Thursday, June 2, 2011

When is an enum not an enum? When you use Objective C!

I have been using enums in my Objective C code and they are starting to bite me in the behind. The issue? They are not unique, they really just go up in a big global named item pool. I had two classes (or interfaces as they are misnamed in this stupid language) both had enums and each had a enum value named "Text". Not a big deal in Java as you prefix the enum you want with its name when you use it. No way to do that in Objective C. They don't support namespaces for anything so I guess it should not be a surprise it is not supported for enums either.

I really did not notice this until I needed to include both interface header files in another interface. Then it got annoyed that I redefined "Text". I see others that use enums prefix every freaking enum with the enum name. What is the point of the enum name at this point? What a waste and gives long and stupid looking enums but I guess you want to use the "convenience" of an enum in Objective C that is really the only way to do it otherwise you will be bite over and over. Hate to think what happens if some 3rd party software does not do this.

Please don't give me the "just follow the language standards and shut up" argument. This is crappy compiler design. I will follow the standards to get around something the compile should handle for me but arguing that I am the one at fault is crap.

The more I work with Objective C the more I understand why it has not been ported to other environments. It is not a modern language. You have to use it on the Mac. It was written as a C preprocessor, not as a full language, and it has been tacked on to since then. Learning to get around its lousy limitations is not making my job fun. PC folks steal everything, good or bad, but they have not bothered to steal this language and I totally understand why. It does allow the Mac crowd to feel more unique.

I am also sick of the "iOS is harder to write so we have better developers, anyone can write on the Android and it shows" line of poop. You should not have to fight the compiler to write code ever. Fighting Objective C does not make me a better programmer, it makes me a bitter programmer and a hell of a lot less productive. I am learning to get around the issues and I try to not make the same mistake twice but I still cuss at the stupid thing for making me write too many lines of ugly code.

3 comments:

  1. lol. Nice blog. I completely agree with the points you've made here. Apple really doesn't care about its developers (or customers really), whereas Microsoft is all about their developers.
    Night and day.
    I stopped using enums because of the silliness.

    I threw my lot in two years ago to make mobile games and it's a PITA and odd language. Anyway, funny blog, keep it up.

    ReplyDelete
  2. Glad you are enjoying the blog. I don't get many comments but I do seem to get a lot of traffic so it is nice to hear from people who get a laugh from what I write.

    ReplyDelete
  3. If you want namespaces, use Objective-C++ instead of Objective-C. Then you get C++ style enums.

    ReplyDelete