The Mac and iPhone SDK are based on the Objective-C programming language, a surprising alliance of C and Smalltalk. Features such as meta-classes, message sending, dynamism, C compatibility, etc., contribute to define the development experience on Apple’s platforms. Here is a little list of things that, in Philippe Mougin’s experience, contribute to make Objective-C a powerful and fun programming language.
Unfortunately, gentoo distro does not have an objective C compiler (that I can find). In my estimation
Objective C is miles ahead of C++ — multiple-inheritance is a solution in search of a problem.
Doesn’t the GCC that comes with Gentoo have at least the option to be compiled with ObjC support? On the Mac the standard ObjC compiler is GCC.
“Adding Objective-C support to GCC
Install GCC with the objc USE flag set. GNUstep itself only uses Objective-C, so this will suffice.
If you are a developer and want Objective-C++ and garbage collection support, add the objc++ and objc-gc USE flags, respectively.”
http://gentoo-wiki.com/HOWTO_GNUstep#Setting_up_your_system
Objective C has no operator overloading, which is really useful for e.g. matrix libraries or other mathematical stuff. Objective C has no templates, thus no typesafe collections. Objective does not have most of the useful features from languages like C# like delegates and events. And multiple inheritance can be really useful, you just have to know what you are doing. And C++ can be quite simple to program if you use it with a decent class library like Qt. There are good reasons to not use C++, but there are certainly better languages than Objective C like C#, Scala or Haskell.
Objective C has no templates, thus no typesafe collections.
Objective C is a very dynamically typed language. Generally, type safety of a collection isn’t a concern.
Objective does not have most of the useful features from languages like C# like delegates and events.
Objective C has dynamic message sending (the ability to call an arbitrary selector on an object at runtime), as well as C function pointers.
A common idiom in Cocoa is to provide delegate objects to views which implement the event handlers that they want to implement (for example, mouseDown:). These messages are then sent if the delegate implements the method, and not sent if it doesn’t.
Events are handled in multiple ways, but Cocoa has NSNotificationCenter, which is a generic event notification system that anyone can subscribe or send messages to.
Do we have to go back to Objective-C? After all those years of improvement in Java? My Dad used Objective-C for God’s sake. How bloody ancient.
<sarcastic>Yeah, that makes sense, because if something is old, then it is obviously bad.</sarcastic>
…Otay….
Edited 2008-03-14 22:06 UTC
Well.. have you read the article? I don’t know Objective C, but it looks nice. Syntax looks clean, and I don’t think it’s inferior any way to C++. And Java, well… if you compare Java to Ruby, Java looks like an old man’s language, yet Ruby is couple of years older. I’m not judging and I’m far from it – it all depends on what you use the language to, different languages are good for different tasks. Ruby can do iterators nicer, Java can run on anything and has powerful libraries, C++ is damn fast and flexible. The choice is yours.
My dad used punch cards. Compared to those, this is cutting edge stuff.
Your dad is a wise man:) Respect wisdom, newer things are not always the best. One word that describe Obj-C above java and C++, elegant.
Edited 2008-03-15 00:51 UTC
May I laugh? Java is a lot of things but certainly not ‘modern’ or ‘easy’. Java once started out as being developer friendly (compared with C/C++), but these days are long gone. Sun lost that focus completely and added more and more cruft. Instead Java went the “we have [insert current hype feature of current hype langague], too!” road. In order not to break backward compatibilty (which they broke anyway!), Sun bolted things like generics, autoboxing, etc. on top. In the beginning, you didn’t had to bother much about what the compiler or the runtime system does with your code. These days are definitively gone.
I can’t comment on ObjC; but as a Java developer, I can assure you that Java is definitively not a good choice nowadays. Look at languages like Scala or at runtime systems like OSGi to see what Java is desperately missing.
Java is on its way to become the COBOL of the early 21st century.
I will start by saying that I have not used objc much beyond just looking at some examples and reading some docs but, from what I’ve seen, the syntax itself seems like a very nasty and freakish hybrid of C and god knows what (anyone who knows Cadence’s skill, like that). From the feature list it sounds like a modern language but unlike other modern languages (Python, Ruby, Java, etc) the syntax seems anything but elegant and intuitive.
Any serious objc guys who also know Ruby/Python well care to compare/contrast objc on this front? I could be wrong but my first reaction was Oh GOD! NO! NO!
Well I’m not a God but I do know the other language: Smalltalk!
Smalltalk has a very simple syntax, but as it’s very different from everything else, it takes some times to get used to it..
That said, I remember that when I was at school, I disliked a lot Smalltalk’s ‘weird’ syntax, but after the more I use monster-languages like C++ or Perl, the more Smalltalk’s simple syntax seems atractive
True. The syntax is a bit off-putting to me too, but you might want to consider the following:
* Objective-C was the first Object Oriented version of C and is still widely used.
* Despite being about as powerful as C++, it’s *a lot* easier to learn since it only adds a handful of features.
Back in the old C++ version 1.0 days, I cringed at the Objective-C syntax. But as I watched C++ evolve from a nice simple language to C++ version 2.0, which had some warts but was generally okay, to the PL/1-wannabe called ISO C++ (which only recently has a full implementation and has behaviours that still surprise it’s creator), I’m struck by how favourably Objective-C stacks up with C++. This is despite being virtually unchanged since the early days.
I sort of wonder whether Java, JavaScript, and C# would have even been invented if Objective-C won the hearts and minds of the Object Oriented C devotees. If this happened, I speculate that, SmallTalk might have been the language of the Web (definitely has fewer warts than Javascript), Small-Talk would have taken Java’s place, and Objective C over a Small-Talk VM might have taken C#’s place.
Edited 2008-03-14 22:54 UTC
NeXT brought Obj-C to the masses in 1988. Here it is, 20 years later (well, 19 to be pedantic as we got 2.0 last year) and we’re just now getting garbage collection. There have been 3rd party GC systems for C forever (Boehm instantly comes to mind), but Obj-C 2.0 will make it wide spread, at least in the Mac community. And it’s been almost 20 years for that to happen.
Three things brought Java to prominence: GC, the JVM (and its portability), and its syntax (being shared with C and C++).
Obj-C had until last year, none of those attributes.
And, to be frank, thank heavens for that. Not to slight Obj-C, but the real gift that Java brought us is the JVM and all of the research necessary to make it perform. If Obj-C had taken off, we’d still be bound to the CPU and portability by source code rather than what we have today. JIT technology would be a niche and not mainstream.
If any system has brought the idea of “software components” to maturity, it’s Java. It is painless to use Java libraries today, on any platform. It is painless to build most of them. The JVM provides all of that. Beyond the rare conflict of running a later version binary on an older JVM (Java 5 on a 1.4 JVM for example), Java has more software reuse than any other system on the planet.
I can’t see how Obj-C could have brought upon us the age of software that we have now. And mind, I don’t mean just Java. But you can see the principles developed and improved upon by systems like .NET, as well as the number of languages targeting the JVM and the CLR. Not to mention projects like Parrot.
If Obj-C had “taken over” and Java floundered, I strongly suspect we wouldn’t have the Brave New World that we have today and it would have, in fact, held us back — without really knowing it.
Actually, SmallTalk (one of Objective-C’s two parents) brought the component model to maturity far earlier than Java.
So if Objective-C had taken off, SmallTalk would have been where Java is today. That much I’m sure of since a huge proportion of early Java programmers were SmallTalk programmers (who had to port their existing SmallTalk apps to the more popular Java) and many core Java design patterns started off in SmallTalk.
Edited 2008-03-14 23:50 UTC
Not really. It brought the Class model, but it basically had only Source Code portability, and even that was iffy across implementations particularly because of its flat namespace.
There was no sharing of binaries at all in the Smalltalk world, especially because of its image dependence.
Granted, many OO idioms migrated over from ST to the Java world, but Smalltalk was well placed within the industry during the rise of Java yet still floundered under its growth.
Obj-C might have brought in a more conventional dev and distribution cycle (individually compiled source files creating distributable artifacts linked in to standalone applications), but I doubt the VM nature of ST would have come over in to Obj-C because of the C underpinnings (and it’s implied pointer and unsafe memory heritage).
So, Obj-C certainly shows what can happen when the ST object model is carried forward, but I think the VM, JIT improvements and binary portability artifacts of Java, and the subsequent rise in libraries and reuse because of that, are the real fruit of the Java success story.
Quite honestly, I, and a considerable number of other developers, don’t really like Java. Fully compiled langauges seem to be taking off again recently after all of the Java and .NET hype over the years.
I mean, the idea is nice, but VM based languages can sometimes be over promoted. Java is almost as difficult to write decent cross-platform code for, package for and distribute for multiple operating systems as any other language, such as C, Obj-C or C++. That is, provided you properly plan the project and understand the languages. Clearly, with Java you can do very simple, elegant cross-platform programming, but the level of system integration you’d be forced to accept without doing platform-specific code is plainly unacceptable for a lot of use cases, particularly if you’re making a product that will be released into the wild.
Of course, if you do C++ coding and decide to use the Windows APIs instead of a cross-platform graphics/UI API, you’ll need to write multiple implementations of the graphics portion of your code, but contrast that with the unmeasurable advantage you gain by having an interface that properly integrates with the operating system.
The thing that makes Java nice is the code is fairly elegant, garbage collection and that it has some nice, dev-friendly APIs. However, Obj-C and the various APIs available for it have proven that you don’t need a mammoth VM for that, and can still properly integrate with C APIs, as typically used during system programming. Other languages such as Vala for Linux are attempting to bring the .NET C# syntax to a fully-compiled language. It’s unlikely you’ll be able to do “safe” programming without a VM, but who needs that
Essentially, with Java, for the fairly small advantages you’re gaining over something like Obj-C, Vala, or even C++, you’re accepting bad OS integration, reduced speed and high memory consumption. Often this is appropriate, and the advantage in speed of development can be quite significant if you don’t really try to make it fully integrate to the system, particularly for in-house business development. And during in-house business development, often it’s not performance critical nor is it subjected to the pressure of external market forces.
Java is good, but I don’t think it’s the be all and end all.. infact, if Java, or indeed VM-based programming had never been invented, I still think that many of the things we learned from it would still exist now, such as ‘software components’ and easy source code portability. But perhaps they would have taken longer to come into existence.
Who the hell do you think influenced the dynamic nature of Java? It was NeXT and former NeXT engineers that were working at Sun during the Openstep Alliance.
Java chose a different syntax to garner a greater immediate following. That syntax doesn’t make it a more grammatically appealing language lingustically speaking.
It always seemed to me that NeXTSTEP developers in Germany seemed to really have no issue with the language syntax.
Perhaps the differences in English<->German sentence structure has much to do with it.
Either way, if you find the German language difficult to learn or grasp on how the put the verb/noun relationship different form English then I definitely can see why you’ll not first grasp the ObjC Syntax.
It is painless to use Java libraries today, on any platform. It is painless to build most of them
It may be painless to use the libraries, but it is painful to look at Java applications running on any platform. They are the most hideous things I’ve ever seen, and although they are platform agnostic, they are also independent of any platform’s real look and feel.
So Objective-C is a little quirky, but so are Ruby, Perl, and C++. And anyone familiar with C or Smalltalk should be able to pick up Obj-C very quickly.
The language is really incidental here (though personally I prefer F-Script). It’s the Cocoa (Touch) framework and its Core libraries that’s the superstar. That’s what gives OS X developers the edge.
Strange though how a language’s syntax, and not its inherent capabilities, has more of an effect on how quickly and widely it’s adopted.