Hacker News new | past | comments | ask | show | jobs | submit login
Objective-C is a Piece of Shit (emadibrahim.com)
17 points by eibrahim on Feb 21, 2013 | hide | past | favorite | 33 comments



Two of the three examples are pure C and the other one is needlessly verbose (and also invalid, but that's neither here nor there). Here's a more concise version:

  CIContext *context = [CIContext contextWithOptions: 
      @{ kCIContextUseSoftwareRenderer : @YES }];
  CIImage *ciImage = [[CIImage alloc] initWithCGImage: cgImage];

  CIFilter *hueAdjustFilter = [CIFilter filterWithName:@"CIHueAdjust"];
  [hueAdjustFilter setValuesForKeysWithDictionary: @{ @"something" : @(3.0 * M_PI),
                                                      @"inputImpage" : ciImage }];
  CIFilter *colorControlsFilter = [CIFilter filterWithName:@"CIColorControls"];
  [hueAdjustFilter setValuesForKeysWithDictionary: @{ @"something" : @1.3,
                                                      @"somethingElse" : @0.3,
                                                      @"inputImage" : ciImage }];

  ciImage = [colorControlsFilter valueForKey:@"outputImage"];
  [context createCGImage: ciImage fromExtent: [ciImage extent]];
Unsurprisingly, concise code doing a simple task is about the same length in both languages.


I have to say, concise doesn't necessarily imply "idiomatic" or "expressive". I have to take your word for that example being concise, because that looks like jumble code to me (specially with the weird indentation and long method names that plague the library.)


> I have to take your word for that example being concise, because that looks like jumble code to me

Well, it was off-the-cuff and written in a browser window to match the other guy's code, so it's probably not the prettiest thing I've ever written, but I don't think it's that bad. But I'm going to guess that you don't do a lot of Cocoa programming. If that's the case, I suppose we can headline this story "Person has minor difficulty reading code in language he doesn't know well."

I know I had trouble reading Objective-C before I learned it. It looks a lot different from other things.

> weird indentation

It doesn't look that weird to me, but of course "weird" is a matter of what you're used to. There are some stylistic things that are more or less "enforced" about Objective-C, but indentation isn't one of them. If you prefer something different, you can indent it differently in your code. It doesn't make a bit of difference.

> long method names that plague the library

I understand how you feel, but I'm pretty well convinced that descriptive method names are not necessarily a bad thing. One of the benefits of Objective-C is that once you know the language and your standard framework, it's usually exceptionally easy open up somebody else's codebase (or my own 10 months later…) and follow what's happening. In another language you'll need to jump around to definitions to see what arguments do, while in Objective-C it's always right there. And if you do know the codebase, skimming over the long method names isn't really a problem in practice.

What's next, we're going to complain that somebody's repo is "plagued with unit tests"?


I wasn't criticizing your code, per-se.

I did fair bit of Smalltalk development back in school, so I know exactly where Obj-C/Cocoa naming conventions and 'message' syntax comes from. The problem is this: that naming convention doesn't make any sense in a statically typed language. It made sense in Smalltalk because the parameters sent to a message could be anything. It was a convention to avoid common erros. In Obj-C, on the other hand, it doesn't make any sense. Sure, it might sound like saying "message withBananaParameter: banana andCoconutParameter: coconut" is clearer and 'self documenting', but it's a waste of your time typing it (even when you use autocomplete) and the compiler parsing it. Let alone people reading your code in the future.

The indentation is arguable. I don't know whether that's the standard or not, but I dislike the fact that you are pushing stuff to the right, basically forcing yourself to break the parameter list a lot because you get closer to the "right margin". It looks like that indentation convention was specifically invented to make long parameters list harder to read (ironically, considering long parameter lists are an artifact of Smalltalk-like message/parameter convention.)

I've programmed in a bunch of languages and platforms over the yeas, and only three languages always keep bugging me when reading them: Obj-C (specially Cocoa code), Perl and very complex Javascript. There's something about them that just feels off.


Since Obj-C messaging supports duck typing, I'm not sure I understand the argument you're making against the syntax.


I believe dguaraglia is talking about the types of arguments, which are often included in the method name. So you get things like [guy eatFood:food withHand:hand usingEatingStyle:eatingStyle]. Overall, it lends itself to exceptionally long lines of code, such that Objective-C message sends are often broken into multiple lines with lots of info on the right side of the window. For example, instead of:

  NSWindow *window = [[NSWindow alloc] initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen];
people will often write write:

  NSWindow *window = [[NSWindow alloc] initWithContentRect: desiredRect
                                                 styleMask: windowStyle
                                                   backing: NSBackingStoreBuffered
                                                     defer: YES
                                                    screen: [NSScreen mainScreen]];
The length of the selector requires us to choose how we're going to write this line of code.


I might have talked out of my ass? Wouldn't be the first time, and I apologize if I did.


The first thing you need to learn is the difference between Objective-C and C.

The second thing you need to learn is the difference between a language and an API.


Objective-C is a very verbose language. However, the author seems to be intentionally not using any of the features that Apple has built into LLVM that makes it more concise particularly the "dot syntax" which gives Objective-C the ability to call methods and set properties much like C# or Java does.

Additionally, 90% of the code shown here is old C APIs. You will never hear a Cocoa developer defend those. They're particularly frustrating to work with, but have nothing to do with Objective-C the language.


You couldn't use dot syntax here AFAIK, as these aren't declared properties.


I have to admit, most of these seem like the author has little understanding of Cocoa or Objective-C. The first example is fairly verbose, though that's pretty typical of Cocoa in some cases. The second example is just plain strange considering one could just as easily do "NSDictionary *dict = @{ key: value, ... };" (which is backwards since it's just syntactic sugar for another method of creating an immutable dictionary) and spare themselves the direct use of Core Foundation types. The third example isn't even Obj-C and more or less cements my opinion that the author hasn't got a clue what he or she is talking about.

So, overall, this just comes across as hyperbolic and silly. It's cute and I'm sure the author felt smart by making this an image (why is it an image?), but it's mostly devoid of substance.


Since you decided to use emotional language in your title, I'll fire back: you're an idiot.

Yes, if you deliberately set out to write bad code (CFDictionaryCreate instead of @{}? Come on.) then you can make a language look really bad. This should surprise nobody.

I'm afraid that, while you may have attempted to make ObjC look bad, you simply managed to make yourself look bad.


Two of the examples aren't even Objective-C...


Well, first of all most of that code is straight C. Anybody can create a simple package to make 5 lines 1 line if you only want it to do one thing.

Weak sauce. This is just a marketing attempt.


"Brilliant," thought Ender, "Eibrahim was able to distill Drama without using Sexism or Rails. He might even be able to submit a 'white' paper to a Ruby conference!"


Be positive! Say "C# is much better than Objective-C (with examples)"!


Haha, but this title is much more funny.


Here is a more modern example of objective-c... Though, this seems more a critique of the APIs?

http://i.imgur.com/XVtUuWH.png


Objective C is on the left, C# on the right.


Objective-C now has syntax for dictionary literals. Use it.



OP here... wow... people are calling me an idiot on twitter https://twitter.com/0xSina/status/304657083435991041 and my blog server is crashing... easy people, I am not making fun of your mother, it's just a programming language...

I am all about learning new languages. I love c#, python, ruby and javascript... But objective-c has to be one of the most verbose language out there and is syntacticly fugly...

When I programmed in python after 15 years of .net/c-type languages, I picked it up in 1 day. It was simple and beautiful. The same for ruby... But obj-c, after 2 weeks of using it, I find myself hating it more and more every day...

chill out people...

PS: the image on my blog s from http://xamarin.com/how-it-works


The problem people have with this is not that you're complaining about Obj-C's verbosity -- this is a well-known complaint and something anyone using it will probably agree with. The problem is that you've just displayed a fundamental lack of understanding of 1) the difference between Obj-C and Cocoa (seems the Xamarin folks are just as guilty here, which is odd), 2) the difference between Obj-C and C, and 3) the difference between Cocoa, Core Foundation, and other frameworks. In reality, only one of your examples is Objective-C while the rest are C, and you didn't even handle the Objective-C or C cases as well as you could have, so it does make you look like an idiot. Either way, you learn from it and the 'net will forget you within an hour, so it's not a huge issue.


They are NOT MY EXAMPLES man... It's a screenshot from http://xamarin.com/how-it-works and YES I have TOTAL LACK of understanding of obj-c... My entire experience with it is less than 4 weeks. But so is my experience with python - which I instantly loved.


Chill out, manbrodude. Just learn from your mistake. It's not like you're being crucified, just being called out for perpetuating something stupid and being misinformed. If you're concerned about your appearance, maybe pull the post, but a better thing to spend your time on would be learning how to use Obj-C so you don't write terrible code like the Xamarin folks. Live and learn, as it were.


I am chill :)... Mastering/learning obj-c is on my todo list. Thanks.


You're a complete beginner with the language and borrowed some examples from an obviously biased source to make a claim that you're in no position to be making... and this is supposed to make you look better?

At least own what you said.... You can't make a post like this and then try to roll it back with "ha ha only kidding not my examples anyway".


You used emotional language in your title, and now you're surprised that people are getting emotional? What kind of reaction did you expect?


The post is pretty much just an image. It's slow on the cache and throwing a 500 error.

Here's a mirror of the image that is the body of the post:

http://i.imgur.com/DAgq7To.jpg


If you used literals, the obj-c examples would be way less verbose.


> Internal Server Error

So is your web server.


The title made me LOL so bad


Same lines of code if you NSAttributedString (iOS6) instead of plain Core Text C API for second example.




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

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

Search: