"I love my skoda! It has four wheels, and a roof, and a passenger seat!"
"That's a pretty low bar for things to love about a car. Pretty much all other cars also have those features, and they do them better."
"Yeah, well I also ride a bicycle, and my bicycle doesn't have those features."
At least there is Moonscript to save it...
class Animal # yeah! real classes!
hello: (name="nobody") -> # nice default variables
console.log "hi #{name}" # sexy variable expansion!
class Dog extends Animal # logical syntax :)
...
f = ->
x=123 # variables are local by default and need no initialisationOn one hand, it looks nicely terse. On the other hand it looks a bit cryptic.
The thing that stops me from trying it for a project is not the language, but the available environments. Having an additional compliation step adds complexity to the system and the workflow.
One thing I cannot resist to say is that to me "hello $name" is sexier then "hello #{name}" :)
I just run `coffee -wc .` on my source directory and pretend I'm using JavaScript everywhere else.
It's really that simple.
function f($x) { return $x*$x; }
...in your code, you know that you can always call f() to get the square of something. Hallelujah. Functions as they are meant to be.If you think that's nice, I'm about to show you something which will BLOW YOUR MIND :D
>>> def hello(name="anybody", age=10):
... print "hello %(name)s, aged %(age)d" % locals()
...
>>> hello(age=42)
"hello anybody, aged 42"
But wait, there's more!> yeah! real classes!
You think PHP's classes are real? Just wait until shit gets REAL real when you subclass a primitive!
>>> class ExtremeInt(int):
... def __new__(cls, val):
... return super(ExtremeInt, cls).__new__(cls, val)
... def __add__(self, other):
... return (self * other) # Multiplication is EXTREME! addition
...
>>>
>>> x = ExtremeInt(42)
>>> print x + 2
84
Dare I stop there? I dare not!> sexy variable expansion!
You think formatting strings based on local variables is sexy? Sure, we can do that:
>>> name = "bob"
>>> print "hello %(name)s" % locals()
hello bob
But why not format a floating point number to a set number of decimal places based on a dictionary? >>> things_to_template = {"pi": 3.14159}
>>> print "My pi is %(pi).2f" % things_to_template
My pi is 3.14
What about formatting based on an object's attributes? >>> class Animal(): # HOLY SHIT REAL CLASSES!!!!
... def __init__(self, name):
... self.name = name
...
>>> my_ferret = Animal("Mr Awesome")
>>> print "My ferret's name is %(name)s" % my_ferret.__dict__
My ferret's name is Mr Awesome
Is that the end? It's 4am here and I'm barely conscious, but no!> logical syntax [for single inheritance] :)
Ready to have your mind blown FOR A SECOND TIME?!?!?
>>> class Animal: # SUCH CLASS.
... def __init__(self, spec):
... self.spec = spec
...
>>> class Awesome: # SO REAL. WOW.
... def __init__(self, awesomeness):
... self.awesomeness = awesomeness
...
>>> class Ferret(Animal, Awesome): # Logical syntax for MULTIPLE INHERITANCE OMGOMGOMG
... def __init__(self, awesomeness):
... Animal.__init__(self, "Ferret")
... Awesome.__init__(self, awesomeness)
...
>>> mr_awesome = Ferret(9001)
>>> print "Mr Awesome is a %(spec)s and his awesomeness is %(awesomeness)s" % mr_awesome.__dict__
Mr Awesome is a Ferret and his awesomeness is 9001
And that final part?> Variables are local by default
...
...
Actually I can't think of a way to improve on that. It's like saying "I love this language for being turing complete". Sure, that's a good thing. The best thing, perhaps. But you sound kind of weird when you list it as a particular high-point of a language...