
CoffeeScript One Liners - ricardobeat
http://ricardo.cc/2011/06/02/10-CoffeeScript-One-Liners-to-Impress-Your-Friends.html
======
Argorak
Nice collection of examples.

But: I am still struggling with that talk about 'expressiveness' that seems to
take hold of every programming piece. To take his first example: To anyone who
has an advanced programming vocabulary, his notion of "expressiveness" thing
can be reversed. If I read code like this:

    
    
        i * 2 for i in [1..10]
    

I immediately think: "Well, this is a `map`, why doesn't he spell it out?". So
my personal "expressive" version is the following:

    
    
        [1..10].map (i) -> i*2
    

In my opinion, it is also clearer, because it can be read from left to right.

I do understand that this might not be the case for other people, but that
doesn't make the one option 'more expressive' then the other.

Actually, in the long examples, I find the suffix version extremely odd:

    
    
        console.log "Happy Birthday #{if i is 3 then "dear Robert" else "to You"}" for i in [1..4]
    

I have to read the whole line before I actually find out that this is an
iteration. (Besides the fact that putting a conditional into a string
interpolation just to make it a oneliner seems a bit odd)

~~~
edanm
"I do understand that this might not be the case for other people, but that
doesn't make the one option 'more expressive' then the other."

Look, I like the comprehensions better. I also think if you polled a large
group of programmers and asked them what the code does, more of them will
understand the comprehension than the map. Does that mean it's more
expressive? I don't know, know one here agrees on a definition for
expressiveness. But that's at least one positive (IMO) of comprehensions.

Also, stacking multiple comprehensions together is much easier (cartesian
multiple style). E.g.: (i,j) for i in list_1 for j in list_2.

This is much easier to write and understand with comprehensions.

* Note - I know comprehensions from Python, let me know if the cartesian multiple example doesn't work in CoffeeScript.

~~~
jessedhillon
> _more of them will understand the comprehension than the map_

What? Not if you poll programmers who had to go through SICP or take a real CS
curriculum.

------
Isofarro
A function walks into a function, turns to one of the members and asks "can I
stash my privates in here?"

------
acangiano
I published a Ruby version here:
[http://programmingzen.com/2011/06/02/10-ruby-one-liners-
to-i...](http://programmingzen.com/2011/06/02/10-ruby-one-liners-to-impress-
your-friends/)

------
btipling
>" this is only acceptable for application start-up routines"

You gonna come spank me if I do it synchronously and it works for me? I hate
when people are so forceful with their opinions.

~~~
ricardobeat
It's not just an opinion, blocking your event loop will halt _the world_ in
nodejs.

Now give me your address, please.

