[Gambas-user] Suggestions 4 new keywords

Fabián Flores Vadell fabianfloresvadell at ...626...
Wed Sep 15 04:42:27 CEST 2010


Hi Benoît. Below I expose some suggestions for new and alternative keywords.

PUBLIC and PRIVATE keywords defines the scope for attributes and
methods, but this words come from (or evokes) modular/structured
programming. Because PUBLIC methods and attributes (and properties)
define the interface for a class, I think that a good and alternative
syntax could be based in new keyword like INTERFACE, IMPLEMENTATION,
METHOD, ATTRIBUTE, PROPERTY, VALIDATE, etc.

Example:

PUBLIC Name AS String
PUBLIC LastName AS String

PRIVATE iAge AS Byte

PROPERTY Age AS Byte

PRIVATE FUNCTION Age_Read() AS Byte
  RETURN iAge
END

PRIVATE SUB Age_Write(Value AS Byte)
  IF Value >= MinAge THEN
    iAge = Value
  ELSE
     Error.Raise("Age have to equal or greater than: " & MinAge)
  ENDIF
END

PUBLIC SUB DoSomething()
  . . .
END

PUBLIC FUNCTION DoSomethingElse() AS String
  . . .
END

PRIVATE SUB DoSomething1()
  . . .
END

PRIVATE FUNCTION DoSomethingElse1() AS String
  . . .
END

-----------------

Become:


INTERFACE

  'Attribute keyword is optional
  ATTRIBUTE Name, LastName AS String

  'Defines an attribute that is part of interface class and is
accessed by dot notation (AnObject.Age, AnObject.Age=34)
  PROPERTY Age AS Byte
    'Validate when property is written (WHEN WRITE is optional because
is the default)
    'When Write: just in case, so When Read could exist too.
    VALIDATE WHEN WRITE Age >= MinAge
      'Unsucessfull is a long word, may be there's other better
      UNSUCESSFULL Error.Raise("Age have to equal or greater than: " & MinAge)

  'METHOD keyword is optional
  METHOD DoSomething()
    . . .
  END

  METHOD DoSomethingElse() AS String
    . . .
  END


IMPLEMENTATION

  CONST MinAge AS Byte = 28

  . . .

  'Same name is used in INTERFACE: this would possible because the
scope is different
  METHOD DoSomething()
    . . .
  END

  METHOD DoSomethingElse() AS String
    . . .
  END

------------
Advantages

* More expressive code (smells a bit declarative)
* Is needed to write less code (50% in this example)
* keywords are closer to OOP
* More easy to teach

Disadvantages

* This code not seems BASIC neither Gambas (that is why this syntax
should be alternative)
* Is difficult to implement?


What do you think?




More information about the User mailing list