
Objective-C isn't what you think it is - khanlou
http://news.rapgenius.com/Rap-genius-engineering-team-objective-c-isnt-what-you-think-it-is-if-you-think-like-a-rubyist-annotated
======
soup10
Personally I think it's an awful idea to use meta-programming without an
exceptionally good reason in production code. Like excessive use of function
pointers in C. Just because you can doesn't mean you should. Programming in
this style causes more code complexity and will accelerate the rate at a which
a codebase becomes a mess, not to mention it's really slow.

~~~
ebbv
This has always been my view.

New developers (less than 10 years professional experience) seem to become
fascinated by "cool" language features that let them do unintuitive things and
then approach problem solving with a mindset of "What cool tricks can I do to
solve this?"

Instead, the experienced developer will always approach a problem with "What
is the simplest way to solve this problem?"

~~~
bennyg
Sometimes the simplest way is to use a "cool" language feature.

For instance: say you have an app with 30 different ViewControllers, and you
need them to respond to the same notification. Sure, you could go back and
refactor every one to subclass from another class that inherits from
UIViewController - but then you need to make that for UITableViewControllers
and UICollectionViewControllers, and potentially any other new view
controllers that come along if your codebase ends up lasting for years.

Or, you could make one class category that method swizzles the viewDidAppear
method to add the notification handling in immediately. Every class that
inherits from UIViewController will now respond to that notification.

~~~
babesh
[http://stackoverflow.com/questions/5272451/overriding-
method...](http://stackoverflow.com/questions/5272451/overriding-methods-
using-categories-in-objective-c)

~~~
bennyg
[http://nshipster.com/method-swizzling/](http://nshipster.com/method-
swizzling/)

~~~
seanmcdirmid
Isn't that just monkey patching?

~~~
bennyg
[http://en.wikipedia.org/wiki/Monkey_patch](http://en.wikipedia.org/wiki/Monkey_patch)

By that link's definition, then yeah, it's basically monkey patching.

~~~
my3681
I think a lot could be said here for maintainability. As others have
mentioned, it really goes a long way to take the time and refactor the class
to inherit the extra/common functionality if you are working on a team or
working on a project that you know will live a very long time. Swizzling will
certainly work, but at what cost to readability, debugging and reuse? That's
normally the question I ask before swizzling or doing fancy, dynamic things.

Sometimes the quickest or even the most elegant solution isn't necessarily the
"best" one. Best being a subjective term, I would say it depends on what you
need from your code over time and with whom.

------
coldcode
With all the many languages I've used in my life, ObjC is actually my favorite
to work with, especially with the modern runtime and features. I first used it
in the 90's with NeXT WebObjects and was pleased to see it become popular
again.

~~~
nbevans
Sounds like you've not tried a functional language yet in your life :p

~~~
nsmartt
Be careful with this kind of thing. You're inadvertently making the FP
community look bad. A more constructive and less pushy approach would have
been to recommend an enjoyable FP language and explain why you think it suits
the parent.

~~~
RandallBrown
I think the tongue out smiley face means they were playfully joking.

------
pornel
They're similar enough that MacRuby [http://macruby.org/](http://macruby.org/)
is actually built on top of the Objective-C runtime (I'm surprised that the
article doesn't mention that).

~~~
MrGando
Yes, ruby has a strong smalltalk foundation (messages & runtime). Thus it
makes sense to compare the roots of both langs in the way they interact with
messages & the runtime.

------
Touche
> Objective-C isn't what you think it is

A language without namespaces, that's used almost exclusively for iOS apps and
nothing else. Nope, that's exactly what I think it is.

~~~
nnq
Yep. And the fact that Apple did _absolutely nothing_ to evolve the language
into something better shows that they just don't give a fuck about tools and
most importantly _about their developers!_ Maybe it's better than C++ or other
alternative, maybe XCode is quite good, but this just show that _since the
days of NeXT (the 80s!), they just don 't give a fuck!_

...hate to say it, but nowadays the only big company that seems to care about
developers and actually gives them cool tools and languages is _Microsoft!_ C#
with all its extensions, F# and the cool research they do in the languages
area shows one thing: _they care about us!_

~~~
austinz
This really isn't true.

[http://en.wikipedia.org/wiki/Objective_c#Objective-
C_2.0](http://en.wikipedia.org/wiki/Objective_c#Objective-C_2.0)
[http://en.wikipedia.org/wiki/Objective_c#Automatic_Reference...](http://en.wikipedia.org/wiki/Objective_c#Automatic_Reference_Counting)
[http://en.wikipedia.org/wiki/Objective_c#Blocks](http://en.wikipedia.org/wiki/Objective_c#Blocks)

Objective-C also suffers from C interop considerations that make it more
difficult to extend and evolve the language than something like C# or Java.

(None of this is to denigrate the wonderful work MS has done when it comes to
language innovation.)

------
RyanZAG
Please use this stuff sparingly though, especially things like
resolveClassMethod: as it makes for some incredibly difficult to follow code
that can segfault with some very strange error messages. Your future team
members thank you.

~~~
tempodox
Even without the segfaults, you would have to document stuff like that
excessively to preserve long-term benefit. But who reads documentation?

------
localhost3000
i enjoyed this b/c i recently made the jump from ruby to obj-C and, though
scary at first, i now feel incredibly comfortable working in obj-C and think i
even prefer it. so, that's cool.

i do see at the bottom that this post is one of those "inbound marketing for
job candidates" things. that's cool, too... but, i gotta say, as soon as i
read the sign off, "If you want to work somewhere where..." i thought to
myself, "not in a million f'ing years - that company is run by jerks!"...now,
maybe the founders are actually good people but their public personae is just
so off-putting that it totally undermines an otherwise well-done marketing
blog post. i'm curious if that's just me or if they generally have trouble
recruiting.

~~~
babesh
Isn't Rap Genius basically an online Talmud meant for anything?

~~~
sehr
Not yet.

------
allochthon
When I first started toying around with Objective-C and got past the syntactic
differences with Ruby, I was struck by how similar Ruby and Objective-C are,
and concluded that they were clearly inspired by a common source (Smalltalk)
or by one another or both. Although this kind of thing is no doubt mentioned
in the Wikipedia articles, it was interesting to observe the commonalities
firsthand and in context.

------
delinka
On "concise syntax" \- this works well when your vocabulary is large. But when
you have to search for an English word that's sorta-like what you want to do,
and then contort the definition to fit the algorithm, readability suffers. For
example, JavaScript's Array.join() and SQL's JOIN are radically different
concepts and the definitions are not interchangeable, only tangentially
related in the respect that all the information being 'join'ed ends up in one
[maybe larger] pile.

With respect to the article, concision looks like an artifact of standard
practices by the languages users rather than any part of the language
specification. One can be just as concise in ObjC (or C or Java), but the
tradeoff is still readability.

------
MrGando
AFAIK Objective-C does indeed have dynamic features. It's also static & weak.
So I already have a problem with the first line of the article:

> Ruby and Objective-C look like opposites: one is dynamic, the other's
> static;

EDIT: Just read that the author basically denies those claims in the next
paragraph.

~~~
pikachu_is_cool
Nice.

~~~
boon
Like this comment, right? :)

~~~
pikachu_is_cool
Ha. Didn't expect you to read through my post history. I guess that makes me a
hypocrite.

------
dave1010uk
I've never really thought about it before but PHP has some very similar
metaprogramming features.

For starters, the incredibly dangerous runkit extension (like importing
Objective-C's runtime).

There's also the Reflection API, which provides introspection and is quite
widely used.

PHP also has magic methods, such as __call(), which give the ability to handle
calling a method that doesn't exist.

As others have mentioned about Objective-C, these are all nice tools to know
about and understand, however using them is often a code smell and can lead to
unmaintainable code.

PHP doesn't have anything like categories, which is a shame because they look
really useful in cases (as long as you don't mind violating the SRP a little).
PHP has traits, which are more similar to mixins in ruby than categories in
Objective-C.

Oh, PHP also has eval().

------
sdegutis
These features are extremely difficult to use when C types are involved.
@encode() mitigates this to some extent, but there are some C types that you
can't fully express using @encode(), and it can't properly handle all types
(namely out-pointers).

------
dahart
Yes. Using objc_msgSend and NSSelectorFromString, you can call functions,
dynamically _by name_ in Objective C.

Yes, it's dangerous. Clever, and not quite as easy as your favorite dynamic
scripting language, but Obj-C supports it.

My favorite personal use case so far is an Objective-C state machine, where
state names are strings, and state callback functions can be added to the code
& called without declaration. It's not really saving much technically, but it
eases just a tiny bit of mental & manual friction to be able to modify the
code without having to update header files.

~~~
prutschman
You can even do it in POSIX C with dlsym.

~~~
swift
Heh, true, though it requires that the function you want to call be in a
dynamic library.

~~~
prutschman
I thought so too, but the man pages suggest that may not be a requirement.

Under Mac OS X, it looks like dlsym(RTLD_DEFAULT, "symbol") will look for the
symbol anywhere.

Under Linux it looks like dlopen(NULL, flags) will open a handle to the main
program which can be passed to dyslm's first argument.

------
cmollis
I like ObjC. It's true that what people generally use it for are the Cocoa
features, but it could be a really good server language too (particularly with
additions of blocks, GCD, and ARC). There are a lot of nice functional
features that would make server development fun. It's pretty clear why Apple
doesn't push it this way, but I think it could be a good server platform.

------
tambourine_man

      Dynamic method resolution isn’t the only superpower of *sick* mutable languages like Ruby and Objective-C
    

I think he means _slick_ , or the author has a funny sense of humor.

~~~
dhugiaskmak
No, he means sick.

[http://www.urbandictionary.com/define.php?term=sick](http://www.urbandictionary.com/define.php?term=sick)

(First definition.)

~~~
tambourine_man
Thanks, never heard it that way.

------
pjmlp
Pity that he mixes languages with implementations, by stating Ruby doesn't
have a compiler.

------
tbarbugli
I think objective-c is an horrible piece of shit, I dont think I am that far
from what it is.

------
jwheeler79
rapgenius are a bunch of douches, and i cant take them seriously no matter
what.

------
jokoon
I don't like ruby very much, but I prefer it to objective C. So I don't like
objc at all.

------
callesgg
I thought it was a pice of shit.

