Slashdot Mirror


Objective-C Comes of Age

New submitter IdleThoughts writes "Sometimes it takes a long time to spark a revolution. Long the ugly duckling of programming languages, iOS' Objective-C passed C# in the 'TIOBE Programming Community Index this month and seems on a trajectory to overtake C++ in the next few. It was invented in the early 1980s by Brad Cox and Tom Love, with the idea of creating 'Software Integrated Circuits' and heavily influenced by Smalltalk — yet another legacy from Xerox PARC, along with desktop GUIs, ethernet and laser printers. It was adopted early on by Steve Jobs' NeXTStep, the grand-daddy of all that is now OS X. It had to wait, however, for the mobile device revolution to have its day, being ideally suited to the limited resources on portable devices. It's still being actively developed by Apple and others, sporting the new automatic reference counting and static analysis in the Clang compiler. It turns out it has supported dynamic patching of code in applications all along. What more surprises does this venerable language have up its sleeve?"

14 of 437 comments (clear)

  1. New features by bonch · · Score: 5, Informative

    What more surprises does this venerable language have up its sleeve?

    Clang recently added literal syntax for collections and boxed numbers:

    // Old way.
    NSArray *array = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                                @"bar", @"foo",
                                                @"post", @"first",
                                                nil];
    NSNumber *num = [NSNumber numberWithInteger:42]; // New way.
    NSArray *array = @[ @"one", @"two", @"three" ];
    NSDictionary *dict = @{
                                                  @"foo" : @"bar",
                                                  @"first": @"post"
                                                };
    NSNumber *num = @42;

    Properties will also be synthesized by default, so you won't have to write @synthesize statements anymore, and corresponding ivars will be synthesized with an underscore prefixed name.

    Objective-C is interesting to follow because it's a language that was once considered totally niche and almost completely irrelevant, but the frameworks were beloved by developers, and the language's keepers kept at it long enough for the world to see how useful the language is. It also has historical significance as the tools used for creation of the original WorldWideWeb program as well as the development of Doom and Quake. John Romero wrote about he and Carmack simultaneously editing the same map in DoomEd thanks to distributed objects.

    It's still verbose and Smalltalk-ish, but the language as a whole has improved drastically since the transition to Clang. According to the mailing list, Apple has more engineers allocated to the language than ever before, and a lot of it has to do with the move away from GCC.

    I hear that GCC is working toward being easier to modify, so the competition from Clang has been good for everybody, and it's all open source.

    1. Re:New features by gwking · · Score: 5, Informative

      The readability is a bit clearer in C#, but Apple is already fixing that in Obj-C with changes like auto synthesizing properties and making the declarations of common objects simpler like the initial poster showed (with code examples). But aside from simple things like that, the readability of the code depends a lot more on the programmer than on the language.

      If you haven't used Obj-C, at least not on an Apple platform, then that's why you don't know that Apple provides excellent frameworks very much like MS provides .NET. Check out: https://developer.apple.com/library/mac/navigation/#section=Frameworks Almost anything you want to do, Apple provides the foundational building blocks to help you build the application, and not waste time implementing a queue, list, or talk to a webserver.

    2. Re:New features by gwking · · Score: 5, Insightful

      You don't need Xcode to use Obj-C. Clang and gcc are open source and you can use them on Linux and Windows. You can even use clang in Visual Studio! If you mean that you want to develop OS X or iOS applications then yes, you should at least have one of those around to test on. And please hold any more complaints about Xcode being Mac-only until MS releases Visual Studio that isn't Win-only.

    3. Re:New features by Sarten-X · · Score: 5, Funny

      I'm sure someone just handed you a free PC when you decided to program for Windows or Linux.

      My last Linux dev box was pulled from a dumpster by a friend, and was handed to me. I wiped the Windows XP installation off, installed Debian, and happily started coding, so, um... yes.

      --
      You do not have a moral or legal right to do absolutely anything you want.
    4. Re:New features by Dishevel · · Score: 5, Funny

      Let me guess, a Windows developer killed your dog, slept with your wife, read your Sports Illustrated and ruined your birthday party?

      Worse.
      A Windows developer developed Norton.
      Another Windows developer got drunk one night and had all of his humanity removed and wrote Mcafee.
      Then there was the infamous Windows developer that did Internet Explorer. I heard he started his career of terror by writing THIS program.

      --
      Why is it so hard to only have politicians for a few years, then have them go away?
    5. Re:New features by ColdWetDog · · Score: 5, Funny

      That's nothing!

      I built my last dev box from parts that I picked up off the side of the road as the electronic recycling trucks drove past.

      The case comes from old cardboard boxes stolen from underneath the bridge where the homeless folks congregate.

      It's powered by making extension cords unwound from burnt out vacuum cleaner motors and running them under high voltage power lines.

      I got the software by painstakingly gluing a pile of old AOL CDs back together.

      --
      Faster! Faster! Faster would be better!
  2. Just another extension by aaaaaaargh! · · Score: 5, Insightful

    Look, I understand that people who use their tools daily want to advertise them and it's a goosd thing if you like what you're using, but let's face it: Objective-C is just another unsafe, hopelessly outdated extension of C as C++. It's great to get things done and sucks less than C++, but it's not in any way a modern language nor is it based on a great language design.

    Before people start flaming me, please consider that programming languages are tools and you choose the right tool for the right purpose and platform, and the availability of libraries is often more important than the language itself. There is no doubt that Objective-C has its place and is useful, just don't try to sell it as the latest great new thingy. Even Apple's own old Dylan was a more interesting and innovative as a language than Objective-C.

    My 2 cents. Now let the language flamewars commence.

  3. TIOBE Index by PCM2 · · Score: 5, Insightful

    Seems like every few weeks someone writes another story about the amazing "trends" in the TIOBE Index. As far as I can see, the real trend is: Languages go up in popularity, they go down, they move around, one month it's the First! Time! Ever! that a language has made the list, the next month it's gone again, and C, C++, and Java are always at the top (in varying order). Such variable results suggest that TIOBE's sampling method isn't all that reliable or accurate to begin with, but I think we all have a pretty good idea what languages people are really using and for what.

    --
    Breakfast served all day!
  4. How is it not modern? Obj-C has modern libs... by SuperKendall · · Score: 5, Insightful

    Objective-C is just another unsafe, hopelessly outdated extension of C as C++.

    Why do you claim it is "unsafe"? Almost all work done in Objective-C is very "safe", by any measure - mostly you are never using C arrays or the like. Just because they are there does not make the language inherently "unsafe" if that's not how real people use the language.

    consider that programming languages are tools and you choose the right tool for the right purpose and platform, and the availability of libraries is often more important than the language itself.

    Objective-C currently has some of the most advanced libraries for any platform. It already had great string support and other strong frameworks even before iOS, but with iOS and the Mac taking off the framework support for really advanced animations, database work, networking, etc. as good as or better than any other platform. I came from a Java world and am missing nothing for libraries... not to mention a really good set of open source libraries that offer other abilities in addition to the core frameworks.

    In fact, I would go so far as to say the range and quality of design of the frameworks are THE reason to use Objective-C.

    People like you just look at when Objective-C was developed and think because of its age it cannot be "modern". What you don't realize is that Objective-C was developing over all that time, just in a fairly parallel path to other languages - I like to refer to it as a "Steampunk" language. It is modern but just not quite the same as other things you are used to, coming from an alternate reality.

    You're going to have to come up with real reasons for Objective-C not being "modern", most of which are probably quite out of date by now. Before we can flame you, there need to be specifics which we can skewer...

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  5. ObjC sucks by dbrueck · · Score: 5, Informative

    I dev in ObjC on iOS almost every day, and the language sucks. I think it sucks less than C++, but I'm not sure that says much. The Xcode IDE (which also sucks) and the bolted-on features help, but overall the language hasn't aged as well as plain old C - i.e. while coding in it, you are constantly reminded that it is not a modern programming language. Anytime a language gets in your way, it's a bad thing, and that happens an awful lot with ObjC.

    (And before the flames start: yes, I fully recognize that nobody is forcing me to dev for the iOS platform, it's a choice I've made because I make gobs of money off of it. But that doesn't make ObjC suck any less, it just makes me willing to tolerate the suck and grumble about it on /.)

    1. Re:ObjC sucks by dbrueck · · Score: 5, Informative

      Here's a few off the top of my head. Some of them may be specific to Cocoa, but I'm pretty sure that even those are rooted in ObjC's "features":

      Method signatures are often ridiculously long (see NSBitmapRep's initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel: method)

      Parameter names in method calls are /always/ named. You can't just say obj.someMethod(x,y). It's always [obj someMethodForX:x y:y].

      The above combine to make even the most basic operations tedious. Want to trim leading/trailing whitespace off a string? Enjoy [someString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]

      Immutable arrays, dictionaries, sets, strings. I get it, it can be useful for performance to know something is immutable (maybe, I'm not that convinced). But the common use case is most certainly mutable, so /that/ should be the default, e.g. NSArray should be mutable and then if needed there can exist some NSImmutableArray or something. But no, they did it the other way around.

      Memory management (up until recently) was neither fully manual nor fully automatic and ownership was based on naming conventions

      Being a superset of C, they couldn't provide an object-oriented array class using the normal array syntax, so instead you have tedium like [myArray objectAtIndex:2]

      Ditto for strings. Also, you have to prefix string constants with '@'.

      Similarly, you can't put "plain" objects into arrays, e.g. [myArray addObject:5] won't work, but [myArray addObject:[NSNumber numberWithInt:5]] will.

      And of course you can't just create an array with ['a', 'b', 'c'] but instead have to do [NSArray arrayWithObjects:@"a", @"b", @"c", nil].

      Backwards conventions like [NSDictionary dictionaryWithObjectsAndKeys:@"value0", @"key0", @"value1", @"key1", nil];

      If I'm going to pay the dev cycle price of a compiled language, it should catch stuff like non-existent selectors at compile time instead of blowing up at runtime

      Stack traces from delayed selector calls have zero contextual information

      The single inheritance model and a strict class hierarchy discourages writing reusable code. For example, if I have an app that runs on iPad and iPhone and they share a common screen (from the user's perspective although the layout/design might be significantly different), it's a real task to write a common parent class holds the common code.

      Many violations of don't-repeat-yourself: if you want to have an object with properties like Foo.title, then the code is roughly:

      @interface Foo
      {
          NSString *title;
      }

      @property (nonatomic, retain) NSString *title;
      @end

      @implementation Foo
      @synthesize title
      -(void)dealloc
      {
          [title release];
          [super dealloc];
      }

      Similarly, there's no way to have a truly dynamic object with a clean syntax, e.g. in Python/ruby/js/and a host of others you could have a quick little object you use to pass state around, kind of like a struct that has its members added on the fly, e.g.: x = new Object() ; x.name = 'dave' ; x.age = 3. There is literally no way to do that in ObjC - the best you can do is create mutable dictionary and use its verbose syntax.

      We could have a whole extra thread about the toolchain (Interface Builder is an abomination, Xcode often pegs multiple CPUs when it's just sitting there, if you kill the simulator instead of stopping the app via Xcode then you often have to reboot your host machine before you can run the simulator again) but I digress.

    2. Re:ObjC sucks by maccodemonkey · · Score: 5, Informative

      About half of these have been fixed (and were actually new problems that didn't exist in Objc-1.0). Obj-C 2.0 introduced some of the "don't repeat yourself" issues with things like properties and consistency issues between the new property syntax and the existing syntax, but with the new LLVM you can just declare properties and not have to synthesize. In addition, ARC takes care of the memory management code. New LLVM also has Obj-C constants which take care of things like your dictionary example. You haven't needed a backing ivar, so that NSString *title; line in the interface can go.

      (Your code is also in bad form. You shouldn't do [title release]. It should be self.title=nil. Much cleaner, and you get the same thing without doing a roundabout around the property. You also clear the reference to reduce any chance of accidentally hitting a dealloc'd object.)

      As far as complaining about method names... That seems like a personal taste thing... And honestly, it's considered good form to have long method names these days, because the method names themselves become the comments, and it makes extremely clear exactly what the method does. And autocomplete should keep you from having to type out the entire method. There's been a lot of coding standards material written on why this is a good thing. You may not like it, but it seems like a majority of people actually do, and if you're writing APIs or classes, people aren't going to like short method names very much. Writing long method and variable names that describe exactly what they do was one of the first pieces of advice I got in my programming career, and it's served me very well.

      It's actually one of my biggest pet peeves when a C developer starts writing Obj-C stuff. They use these short, truncated method names for no apparent reason, when a longer name will reduce confusion when the code is shared. (And making your code reusable is one of the tenants of Obj-C for very good efficiency reasons.)

      As far as XCode, yeah, it sucks. We all know it. But every IDE has it's quarks. Eclipse is slow and also somewhat unstable, and Visual Studio has it's own quarks. There has been a lot of pressure on Apple to make XCode better, and indeed each release seems to be more and more stable, with 4.0 being the low point.

      Honestly, from your example code, it certainly looks like you've worked with Obj-C, but it doesn't look like you really had a strong understanding of it. Not that I don't blame you, with Obj-C 2.0 it became a little harder to understand, but Apple is cleaning that up.

  6. Unobjective remarks on objective c by Anonymous Coward · · Score: 5, Insightful

    When I evaluate a language the first thing I do is look at a random block of code and say to myself is this what I really want to be writing?

    When I look at lisp all I see is endless streams of ()()())))) and my brain instantly reboots in a violent seizure.

    jquery would be a decent system if only I could get over the rediculous hackish syntax needed to workaround underlying JS environment.

    ASP and close neighbors were always a turnoff due to the weird escape sequences you needed to plaster absoultely everywhere more recently razor cleaned that up somewhat.

    Objective c has too many perlish @ symbols and a rediculous number of [] [][][ ][][][] [] contraptions all over the place. I know this sounds and is shallow but when I look at code I really need to see the code not have to look under layers of syntatic nonsense existing only for convenience or compatibility/interop purposes.

    Give me a capable clean language not hacks upon hacks.

    Given enough time any language can be made useful... this does not mean I would ever willingly choose to use it. I'm instantly wary of languages with only one killer app (iphone) unless it is heavily domain specific.

  7. Re:Yes but by maccodemonkey · · Score: 5, Insightful

    And just like iOS, it's impossible to do an Android app without using Java. Sure, just like iOS, there are abstraction toolkits, support for C/C++, etc. But you can't do an Android app without Java.

    Yet I didn't see any complaining about Google forcing "Java vendor lock in" in your posts, and complaining about that being unfair.