Re:More information on Google's new web language, Dash
by Ezku on Saturday September 10, 2011 @04:17AM
(#2981140)
Not to detract from your point of vastly different things, but you picked a bad example. You add a method to the prototype:
File::close = ->
Et voilà, all Files are closeable.
Re:More information on Google's new web language, Dash
by phoboslab on Saturday September 10, 2011 @09:07AM
(#2981508)
Nice, I didn't know that CoffeeScript has a shorthand for .prototype.
So, to revise my point: with "proper" classes (i.e. Java or C++) this wouldn't be possible, or at least more complicated and not the way to do things. Classes are not the ultimate solution and it's a good thing that Go tries a different approach to OOP.
That said, what Go achieves with its syntax is remarkable, imho.
Consider this: How do you add another function (e.g. "close()") to your file class in CoffeeScript? By extending the existing class into a "MyFile" class? But then you have to make sure all your "File" instances are actually instances of "MyFile", so you can call your newly defined function on them.
In Go you just define the new function.