I know I’ve supposed to have written about Unit testing (part 3), it’s in draft and needs amending, but in the mean time I’ve been thinking about compilers and languages. I’ve been reading the dragon book of late, because I’ve needed to implement a coding style verifier and micro optimiser (something which has been talked about in length by developers).
One thing has struck me of late and that is; we do have really fast operational codes in the language, but other than haXe and Adobe Alchemy not much is taking advantage of it. You can of course try and use TDSI from Joa Ebert, but why should we have to optimise something after we’ve written it? This should be either standard from the language or the compiler.
So what is this really about?
This is about wanting to code without thinking about optimising the basics, you don’t hear of C/C++/C#/Java developers talking about trying to squeeze every ounce of power from the language every time they code something. I’m not saying you shouldn’t optimise, what I am saying is that as a platform it always seems like we’re starting with a handicap.
I want the fasting language for the platform and have all the features for the language. I really like method overloading from Java. I know the AVM2 doesn’t support it by default, but that doesn’t stop you from implementing in some way. A perfect example of this is type parameters (generics) of the Vector class, which I really like from Java and HaXe, but why is it not default on all objects. The compiler checks what your implementing and the aligns it to correct compound types.
Now why can’t a language do this for method overloading, by simply changing the method signature to something else at compile time.
1 2 3 4 5 6 7 8 | function method(name:String) : void { } function method(name:String, age:int):void { } method('fred'); method('jim', 24); |
This would be translated to the following:
1 2 3 4 5 6 7 8 | function method_StringVoid(name:String) : void { } function method_StringIntVoid(name:String, age:int):void { } method_StringVoid('fred'); method_StringIntVoid('jim', 24); |
The reason for the curious method signature is to enable something to call the method if it’s not directly know i.e. external swf file etc.
Also why is the fastest int, not used automatically? To use the fastest int, you have to delve into opcodes, which seems extraordinary as you’re actually saying to your developers “we do have this really fast player, but you’re not allowed to use it”. It would be great if a language just used the fastest int and not require the developer to jump into another language (C/C++/haXe).