[Gambas-user] Suggestions 4 new keywords

Benoît Minisini gambas at ...1...
Thu Sep 16 17:07:13 CEST 2010


> 
> Hum many sugars are possible in gambas ... but i'm ot the master ...
> wait for Benoit ... i'm just a slave ... a poor slave... :P
> 
> 
> I've query some things too :
> 
> For each type in array  must return only object of type 'Type'
> 
> why not "MyString".Len() ? or MyStringVar.Mid(2,1), or
> myString.Instr("v",3)

That syntactic sugar could be possible. After I did 'Mid$(String,X,Y) = ...'.

> 
> why not declare the var on need ?
> 
> (String)MyString = i + 2
> 
> (String[])aValue = ["titi", "toto"]
> 

Not declaring the type of the variable is a big problem. The type must be 
computed by the compiler, that will become slower. And the compiler will fail 
most of the time, as soon as the data comes from another unknown class, so...

Anyway, not declaring the type of a variable is a bad idea. You see it when 
you start to debug a program. Try with more than 100 lines of javascript and 
you will see.

But there is another opportunity. A very Gambas-specific one.

The interpreter does type computing at run-time, so that it can optimize most 
of the bytecode.

When it enters a function, the interpreter initializes each local variable 
with its datatype.

So we can imagine that when the interpreter does nothing for a local variable, 
the local variable takes its datatype from its first assignment. That way, 
only local variables could be undeclared.

But I don't like it anyway, because if you make a mistake in an identifier 
name, instead of an error, you may get a new local variable automatically 
declared and a new bug hard to detect at first sight between thousands lines 
of code.

Regards,

-- 
Benoît Minisini




More information about the User mailing list