More flexible syntax
Posted: Mon Jun 04, 2012 10:09 am
After toying with many other languages for a while I have come to the conclusion that Purebasic is missing a massive feature that many have in its syntax. Of course that is the ability to have anonymous inner procedures. Not just that though, but some syntax changes which I think would take Purebaic to an entirely new level (and shouldn't be too hard to implement).
Consider the following code:
This is not possible in Purebasic, of course it sees 'Procedure' as a keyword and tells me no. What it should do is create the procedure and return the address of the procedure to var1 (so var1 = @getStuff()). Why is this essential? Too often do I find I need to declare a procedure, and then assign its address to a variable, which is fine in smaller code, but as projects get larger it becomes more difficult to manage. Without it Purebasic lacks an element of scalability.
Scoping is also something I would like to look at. Consider I have a procedure where I have a variable ('a') which is protected. Much like in the Purebasic examples.
This code allows 'a' to be changed by calling only that procedure. Suppose I now have 'a' 'b' and 'c' as my variables all protected in that procedure. I need to edit each one depending entirely on what the values of them are or something like that. I can do it all in a single procedure... but it would be much nicer to have it all separated out so it is easier to read and maintain later into separate functions for each one. Of course I cannot do that, because it is protected.
Now consider this:
The inner procedure (which can only be called from that procedure) has done most of the work for me.
I would very much like to be able to do things like create structures inside a procedure as well (with protected access to that procedure).
I think adding functionality like this would make Purebasic a significantly more flexible language. I also think that it would make those here who want an object-oriented variant of pb much happier, as this would make coding in such a way possible.
Consider the following code:
Code: Select all
var1 = Procedure getStuff();
EndProcedure;
Scoping is also something I would like to look at. Consider I have a procedure where I have a variable ('a') which is protected. Much like in the Purebasic examples.
Code: Select all
Global a
a = 10
Procedure Change()
Protected a
a = 20
EndProcedure
Change()
Debug a ; Will print 10, as the variable has been protected.
Now consider this:
Code: Select all
Procedure Change()
Protected a
Protected b
Protected c
editA();
editB();
editC();
Procedure editA();
if a = blah
a = blah
endif
EndProcedure
EndProcedure
Change()
I would very much like to be able to do things like create structures inside a procedure as well (with protected access to that procedure).
I think adding functionality like this would make Purebasic a significantly more flexible language. I also think that it would make those here who want an object-oriented variant of pb much happier, as this would make coding in such a way possible.