Live data from Hacker News

Objective-C isn't what you think it is

news.rapgenius.com

11–20 of 101 posts

Re: Objective-C isn't what you think it is

#11
post #6

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

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.

Re: Objective-C isn't what you think it is

#12
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.

Re: Objective-C isn't what you think it is

#13
post #8

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.

[deleted]

Re: Objective-C isn't what you think it is

#14
post #3

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 n…

You can even do it in POSIX C with dlsym.

Re: Objective-C isn't what you think it is

#16
post #4

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.

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

Re: Objective-C isn't what you think it is

#17
post #8

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.

I think the real problem is dynamic metaprogramming. Things like method_missing and the like can be very hard to reason about. However, static metaprogramming (ie code generation), can dramatically reduce maintenance costs and yield a fantastic regression testing mechanism for free: Just check-in the generated code!

Re: Objective-C isn't what you think it is

#18
post #9
post #8

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.

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?"

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.

Re: Objective-C isn't what you think it is

#19
post #15

> 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.

The namespaces are inherent in the class name. It's actually a very nice solution.

Instead of this Foundation::Array we get NSArray. Way easier to type out, and looks a million times cleaner to me.

Post reply on HN