
_.m: A port of Underscore.js to Objective C - aaronbrethorst
https://github.com/kmalakoff/_.m
======
justinvoss
As someone who knows both Javascript and Objective-C, this is less readable
than either.

Underscore.js may have some useful abstractions, but they'd be better exposed
as Objective-C categories rather than trying to shoehorn everything into
Javascript syntax.

------
Groxx
'Underscore.m' seems a lot nicer to me: <http://underscorem.org/>

I mean, what?

    
    
      N* value = (N*) hash.getOrAdd(l, ^{ return N.I(0); });
    

I'll take a minor increase in verbosity for a massive increase in readability
in the future.

(edited; unwrapping is needed in both libraries)

~~~
aaronbrethorst
Agreed, I hadn't seen this library before.

~~~
Groxx
fwiw, I do like seeing a variety of libraries - they occasionally come to the
same kind behavior through different techniques. It's a fun way to get a
deeper knowledge of the language.

------
mpweiher
For a more Objective-C-ish take on these sorts of functional idioms, have a
look at Higher Order Messaging:

    
    
      myStrings = @[ @"hello"   @"world" ];
      upperCase = [[myStrings collect] upperCaseString];
      
      myInts = @[ @1 @2 @3 ];
      sum = [myInts  reduce] add:@0];
    
      [[self onMainThread] doSomething];
      [[delegate ifResponds] delegateMessage];
    

Blocks also work, but the built-in methods tend to be a tad verbose.

~~~
SeoxyS
Wow, I just found out about Higher-Order Messaging. This is pretty awesome.

Here are some links for more info:

    
    
        - http://cocoadev.com/wiki/HigherOrderMessaging
        - http://macdevcenter.com/pub/a/mac/2004/07/16/hom.html
    

\---

As an aside, I like to use my own [ATFunctionalCollectionExtensions][] for
this purpose, which is a blocks-based implementation of map, reduce, inject,
each, and filter.

[ATFunctionalCollectionExtensions]:
[https://github.com/kballenegger/ATFunctionalCollectionExtens...](https://github.com/kballenegger/ATFunctionalCollectionExtensions)

------
mmariani
First of all, language design is tough business. And for not appreciating
that, with all my heart, I thank Netscape's project managers for rushing JS
designers.

That said, I don't get all the hate towards ObjC. Taking into consideration
its requirements, I think it has been doing great for us.

As for _.m, I appreciate the effort taken by its author, really. However, I
won't be using it because it hurts one of the most pristine features of ObjC,
which is readability. Fix that, and you'll get a lot more love from the
community.

------
pzearfoss
I feel as though most of these functions can be achieved with existing methods
or with other libs like blocksKit.

Apart from the downright foreign (to objective-c) syntax what makes this
different?

~~~
Groxx
It's probably just another attempt to build the same thing. Maybe for
learning, maybe because they didn't know others existed (blockKit is new to
me, fwiw). Maybe as a curiosity.

------
revelation
I don't get it. So this is a poor mans LINQ? Without the necessary performance
considerations and a distressing lack of language support for its primitives?

------
jawngee
What an abortion. Seriously just stop.

Every time I see someone misuse properties like this on Objective-C, I want to
hire them to work at my company just so I can fire them. And then I would call
them a few days later and apologize for being so rash and convince them to
come back and work for me just so I could fire them again once they've settled
into their desk.

Nobody wants your shitty javascript syntax mixed in with Objective-C. Nobody
but you anyways. This isn't smart, regardless of whatever functionality it
provides. You've done all this work to create this awkward, unclear,
confusing, cryptic layer of shit that makes no sense when read. If I have to
read documentation to understand what is going on, you've failed. This is full
of fail.

WTF is A _? N_? N.I what the fuck is that?

underscorem is better for sure, but it still abuses property syntax in a way
that I would reject on any project I saw its use in.

I'm always amazed at how much work people want to put into not having to write
proper Objective-C. It doesn't make any sense.

So slow clap for writing some useless crap. Sorry for the vitriol, but this
shit is just dumb.

~~~
floatingatoll
"How dare people port X to run on Y! This has no place in production code and
you are WASTING OUR TIME doing theoretical experiments!"

Saying "Sorry for the vitriol" doesn't excuse being an ass, it just confirms
that you were being an ass intentionally. How is your verbal assault an
appropriate response to this project?

~~~
jawngee
It is because this is that offensive to anyone who writes objective-c for a
living.

First of all, you are using properties to fake dot syntax for method calls.
This is all kinds of wrong.

Second of all, you are shortening the names of types because you are too lazy
to type the first letter and hit space. This is beyond wrong.

It's not the functionality, it's the implementation. And when writing
libraries for others to use, you must consider how it fits into that
surrounding code. There are a bazillion smart people working at Apple writing
objective-c libraries. Have you seen anything like this? You think maybe there
is a reason for that?

Its just plain lazy, its just plain offensive. Learn objective-c. It's not
that hard. Stop putting in all this work to produce something to fit this idea
you can get around your weird perceptions of it and to shoehorn it into what
you already know.

Like I said in another post, it's sad because there seems to be a lot of work
put into this.

~~~
sticks

      It is because this is that offensive to anyone who writes objective-c for a living.
    

Really? I write objective-c for a living and I'm not finding it offensive at
all. I may not agree with all of it, but rather than getting upset about it
I'm trying to understand where this developer is coming from. They clearly put
effort into making it, so I'll give them the benefit of the doubt that there
must be some gains to be had here.

    
    
        This is all kinds of wrong.
    

Is it correct from the language specification's point of view? Does the
compiler allow it? Does it generate correct bytecode? It seems it might not
align with your code style or even widely accepted "best practices" but it's
probably not all kinds of wrong. That level of rigor might be appropriate for
certain environments (health care, flight control, etc) but not all software
needs to be held to that standard. The reaction in this thread seems awfully
similar to The Great Javascript Semicolon Wars that took place earlier this
year.

    
    
      [Y]ou must consider how it fits into that surrounding code.
    

Perhaps this library is meant to shift the way that new code is written. Maybe
it'll get some of those bazillion smart people working on other libraries to
see a different way to do things.

Relax. Don't get upset. It's not meant as an affront to your style or
sensibilities. Consider this by @fat [1]:

    
    
        Projects with the most radically unique styles often have the highest internal
        standards for code quality and consistency. People put so much thought into the
        written code itself that it actually engenders a new sort of pride. 
    

[1]: Eating a whopper: <http://byfat.xxx/eating-a-whopper>

