Hacker News new | past | comments | ask | show | jobs | submit login

Maybe I'm an exception, but I generally find code with LESS syntax to be more readable.

    var makeAdder = function(x) {
        return function(y) {
            return x + y;
        };
    }
vs

    makeAdder = (x) -> (y) -> x + y
Is anyone else like this? Do you think people are hard-wired to prefer one form of syntax to another, or do you think it's a "whichever you have more experience with" kind of thing?



I think I could get used to the second, but I'm not yet. At a glance, it looks like Erlang or Haskell, but that just shows you how little I know about those languages.

It's tough to strike a balance between brevity and familiarity sometimes.


In Haskell you could actually just do

    adder = (+)
because operators are just normal functions which happen to be infix by default. I think this is great--it's consistent, flexible and elegant at the same time. Not treating operators as something special makes the language simpler.


And to me that means absolutely nothing at first glance. It's much harder to read because I have to do all the work of translating it into the first example myself, and I have to do it when I was presumably trying to figure out what the code means. By the time I do I could have just written it that way in the first place.

The difference in style is similar to how the invention of punctuation, spaces, capitalization and paragraphs made writing much easier to read, and shorthand is annoying as all get out. It is certainly possible to misuse punctuation, spacing and paragraph breaks to the point where they make writing harder to read, but most often the writing wouldn't be good without them either.


What about the currying in the previous example? It made a function that had some value of X pre-bound to the addition operation, requiring only 1 operand/argument when called.


Functions are curried by default in Haskell.


You can go one step further and make use of automatic function currying (such as in haskell) and just write:

adder(x,y) -> x + y

If you call adder with one argument, you get the same behaviour as your makeAdder (returned closure), but if you call it with 2 args you get addition.


Haha yeah. I don't think CoffeeScript has support for that yet, but I believe LiveScript does.

*I was mainly trying to point out something that is semantically equivalent but syntactically different.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: