Live data from Hacker News

Objective-C isn't what you think it is

news.rapgenius.com

81–90 of 101 posts

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

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

Wow, major hate on the metaprogramming in this post today. Note to self: I'm not working for any of you. K? k.

Anyway. The need for metaprogramming is like a lesser version of the need object-oriented programming. You never strictly need OOP. And you can totally go overboard with the Abstract Factory Factory, and make your code insanely obnoxious to follow.

But it can help, and it can specifically help in the situations when it simplifies more than it complicates -- in the situations where it's so simple you barely notice it. (Describing object attributes for your favorite ORM is a case that comes to mind.) If you're set in your ways and you've already made up your mind to eschew it always, then sooner or later you're going to end up with something more complicated than it should be instead of simpler, and it's just an empty piety. :P

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

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

Wow, major hate on the metaprogramming in this post today. Note to self: I'm not working for any of you. K? k. Anyway. The need for metaprogramming is like a lesser version of the need object-oriented programming. You never strictly need OOP. And you can totally go overboard with the Abstract Factory Factory, and make your code insanely obnoxious to follow. But it can help, and it can specifically help in the situati…

One thing that confuses me is the need for some people to read emotion into nearly everything. This is especially prevalent within the group of people people who tend to prefer Ruby, JavaScript, and languages like those.

When I read soup10's comment, or some of the other comments here expressing a similar take on the matter, I don't see "hatred" involved.

In fact, I see a clear lack of emotion. In place of emotion is a pragmatic and analytical point of view, where the benefits are weighed against the drawbacks, and a conclusion is drawn.

Emotion doesn't really play a role at all in such analysis. It strikes me as odd to see it suggested that emotion is involved, when it pretty obviously isn't.

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

#83
post #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

Does APL count?

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

#84
post #46

Earlier quoted context omitted.

Isn't that just monkey patching?

http://en.wikipedia.org/wiki/Monkey_patch By that link's definition, then yeah, it's basically monkey patching.

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.

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

#85
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().

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

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

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

#87
post #49
post #9

Earlier quoted context omitted.

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

Well. Objective-C isn't that simple to begin with, but when you are used to it, it really provides elegant and very simple solutions to medium complex stuff like key-value observing and coding. Meditated together they are called bindings, where your ui is key value coded, and your model is key value observed. Yes, Objective-C (and Cocoa) are very strong on design patterns, which gives you a whole lot of leverage. It…

Hmm, what's your definition for "hot-dirty-sexy" in the context of programming languages?

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

#88
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've never heard anyone describe function pointers as meta-programming before.

Functions are data, just like other kinds of data. I use them in C whenever what I want to parameterize is behavior, and not, say, an integer or a string.

I believe that if you explicitly avoid function pointers, and instead use a less appropriate construct, that would become a mess, instead. If you replace the function pointer with an enum, you've tightly coupled the type definition of the parameter with all users. You've added a switch statement on the enum, rather than a function pointer call. It would be both messier and probably slower than the function pointer.

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

#89
post #29

Earlier quoted context omitted.

Whichever kind you do, it just has to be optimized for reading the code, not be a leaky abstraction, and stay out of the way of debugging. Static meta programming can be bad in all these ways as well.

I've found that static metaprogramming produces an odd middle-ground. The intermediate code can be wonderfully legible and this lets you quickly find bugs... but when it comes time to fix the bug you have to go into the original generating code and then you find an absolute horror. In this case I'm referring to C# T4.

OTOH, bugs in auto-generated code are much less common.

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

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

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

And what would you call my mindset, which can be summarized as "what cool features I can use to express the problem and it's solution in a simplest way"?

Remember, copy pasting is also very simple solution to many common problems.

Post reply on HN