Live data from Hacker News

Objective-C isn't what you think it is

news.rapgenius.com

1–10 of 101 posts

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

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

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

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

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

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

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

#5
post #2

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.

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

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

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

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

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

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

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

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

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

Post reply on HN