Re:Why Dart Types Are Optional and Unsound
by extension on Friday January 06, 2012 @02:28AM
(#3432407)
In any sensible OO language (i.e. not C++) all method calls will be virtual, so there is always some sort of dynamic lookup involved.
Re:Why Dart Types Are Optional and Unsound
by AndrewDucker on Friday January 06, 2012 @05:07AM
(#3432710)
In C# you have to specify that a method is virtual if you want people to be able to override it. This makes it clear where you expect people to insert their changes, allows you to design extra safety into those points, and makes the code faster.
No, but you can generate better code if you know exactly what types you're playing with ahead of time.
Say you have a function like this:
That could be compiled to just a straight 'jmp SomeClass::bar', whether you're compiling natively or to a VM.If you don't have static types, the best code you can output is something along the lines of this:
Of course there are tricks that you can use to optimize this second case a bit that involve fancy static analysis, fancy JIT business, etc. but the point is that you will never generate better code than just a single jump to the right code, based on the types you know at compile time in a static language.