[Gambas-user] Suggestions 4 new keywords

Benoît Minisini gambas at ...1...
Fri Sep 17 04:01:21 CEST 2010


> > 
> > I mean that declaring a public variable with PUBLIC or with ATTRIBUTE is
> > always declaring a public variable, with another keyword.
> 
> But keyword have a meaning. Words are the starting point for reasoning
> about something.
> 
> For example, the keyword PUBLIC refers to the scope of a variable, so
> evokes a concept that come from structured programming. Instead,
> INTERFACE is an important concept that when you use PUBLIC remains
> hided. But also, INTERFACE refers to the encapsulation, so evokes a
> concept that was highly emphasized by OOP.
> 
> Similarily, FUNCTION, SUB and PROCEDURE evokes to the structured
> programming. Instead, METHOD evokes to the OOP.
> 
> So, words are very important because allow linking the syntax with the
> concepts, and this matters to allow good reasoning (specially at the
> moment than is necesary teach an OOP language).
> 

I agree with the word "method," but "public" and "private" comes from the OOP 
world too. And "interface" has not the same meaning in all OOP languages, so 
it is not necessarily a good idea to use it. Morever, "Interface" is already a 
reserved keyword, because I'd like to implement the "interface" mechanism of 
Java, but I didn't find a good way to make it yet.

> >> That is not an impediment to an alternative syntax. In fact, Gambas
> >> have alternative syntax for many things:
> >> 
> >> - Loops
> >> - String functions (VB component)
> > 
> > The two cases are just exceptions
> 
> There are more than two: PROCEDURE and SUB for example.

Put them with "Loops" (DO, WHILE, REPEAT, FOR, FOR EACH and GOTO).

> 
> > Otherwise, I try to limit the number of keywords as much as possible.
> 
> That can be important. But, is more important that provide keywords
> closer to OOP?
> 
> So if you has admited exceptions before. Why you can't do now?

Because these exceptions comes from the syntax of other BASICs. I want the 
inheritance of AMSTRAD-BASIC, GFA-BASIC, and Visual BASIC (The BASICs I used 
mainly!).

> 
> > It is what I meant: a special syntax to define something not so frequent.
> > You take the case where your "property" is actually just a bit more than
> > a variable. This is actually rarely the case. Reading is often just
> > returning the contents of a variable, but writing is usually more
> > complex. I don't know how to cover all possible cases with less keywords
> > than the current syntax.
> 
> The problem is that if I define, for example:
> 
> PUBLIC Age AS Byte
> 
> PUBLIC SUB setAge(Value AS Byte)
>   IF Value >= MinAge AND Value <= MaxAge THEN Age = Value
> END
> 
> The user can avoid the validation, just using the dot notation.
> 
> This is because the PUBLIC keyword refers to the scope, but if you
> think about that as part of an interface, you can do mandatory the
> validation (execution of setAge) for the dot notation too. So, there's
> no need to force to programmer to write an private attribute, setter
> and getter or property and _Write _Read methods.

So you want a new special syntax just because you don't want to write:

PRIVATE $iAge AS Byte

PROPERTY Age AS Byte

PRIVATE Age_Read() AS Byte
  RETURN $iAge
END

PRIVATE Age_Write(Value AS Byte)
  IF Value >= MinAge AND Value <= MaxAge THEN Age = Value
END

Moreover, that syntax shows clearly that using a property is calling a 
function. What is really done is not hidden by the syntax. That is important 
for me too.

> 
> Do it so, can be confusing because scope concept isn't equal to
> interface concept.
> 
> May be that can be more clear, so:
> 
> PUBLIC '(a.k.a. Interface)
>   Age AS Byte
> 
>   SUB setAge(Value AS Byte)
>     IF Value >= MinAge AND Value <= MaxAge THEN Age = Value
>   END
> 
> So it is clear that both the attribute and the method are part of the
> interface and the method will be executed when the attribute gets a
> value.
> 
> But if you want less keywords, you can do:
> 
> PUBLIC '(a.k.a. Interface)
>   Age AS Byte
> 
>   setAge(Value AS Byte)
>     IF Value >= MinAge AND Value <= MaxAge THEN Age = Value
>   END
> 
> Because, I think than, a method (procedure or function) is defined by
> its signature, not by the prefix keywords FUNCTION, PROCEDURE or SUB.
> 
> May be, you want to do optionals these keywords.

I don't want when the job of the compiler to become too complex. The speed of 
the compiler is a *very* important thing to me, and I spent days to make the 
Gambas 3 compiler twice faster than Gambas 2 compiler.

> >> > Note that I am not agree with the common separation between
> >> > "interface" and "implementation". In the real life, they are not
> >> > separated. A good interface usually leads directly to the
> >> > implementation. Or the interface surface from a good implementation.
> >> > :-)
> > 
> > When I mean "real life", I mean "real programming life". :-)
> 
> Anyway, I don't understand what you mean.
> 

Mmm. It's even hard to explain in french. It's just something I noticed after 
years of writing programs.

> >> (read below of "or much better")
> >> 
> >> http://old.nabble.com/Ideas4Gambas-to28782834.html
> > 
> > Sorry, I didn't know you were the father. :-)
> 
> lol. Luckily, I'm a real father.
> 
> Finally, I think that you can do Gambas become more easy yet (easy to
> code, easy to reasoning, easy to teach), and the syntax can be a
> important part in that. So, you know how to do it the best way,
> because you're the expert not me.
> 
> Regards

I won't change the syntax of Gambas just before releasing a new version, so 
there is enough time to talk about that before the next one!

Regards,

-- 
Benoît Minisini




More information about the User mailing list