TechHui

Hawaiʻi's Technology Community

Looking at some iPhone Objective C code today I couldn't help but be struck by how awkward it is compared to the Java code we write for Android, the Groovy and Ruby we use for web apps and the C# code we sling for Silverlight and WPF. Of course a good developer can write beautiful code in any language and a bad developer can write bad code in any language, but the fact remains - Objective C is old and ugly. Lines like "NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];" look ridiculous, and Apple must know this. They need a sexy new language for their sexy OS.

I'm willing to bet Apple is working on a new language with all the niceties we've come to expect from modern languages such as clean terse syntax and language-level support for common design patterns. Of course, they could just pick one of the many existing modern languages suited to this domain, but that wouldn't be Apple's way. They will create something new, and I bet we will hear about it this year.

Views: 240

Replies to This Discussion

"NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];" looks gorgeous to me. Very much a clean, terse syntax. Send a message to the NSNumber object to allocate memory to an instance of it, to be called 'value', and tell the instance to initialize itself with floating point value 1.0.

Now, what would a sexy line doing the same thing look like to you?
MacRuby is in development. It stalled out for awhile, not sure if it is back on track:

http://www.macruby.org/
I should mention that when NeXT took over Apple, Java was all the rage, and they came up with an Objective C syntax meant to imitate Java. They wanted to have the latest sexy programming language's hot look. It was a total dud with developers, since it was not as elegant as Objective C syntax, and so I believe it was dropped fairly quickly.
Lee Altenberg said:
"NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];" looks gorgeous to me. Very much a clean, terse syntax. Send a message to the NSNumber object to allocate memory to an instance of it, to be called 'value', and tell the instance to initialize itself with floating point value 1.0.
Now, what would a sexy line doing the same thing look like to you?

Hi Lee - Lets look at instantiating a float object with Objective C and a few newer languages:

Objective C:
NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];

Java:
Float value = 1.0f;

C#:
Single value = 1.0F;

Ruby:
value = 1.0

No objective person can look at these examples and say with a straight face that the Objective C version is terser or clearer than Java, C# or Ruby. To do so would require religious affinity for the language. I realize Objective C people are partial to message passing over method invocation, but there is no reason a new language can't accommodate the same thing (message passing, message routing, etc.) with clean, perspicuous and terse syntax. The Objective C syntax above is verbose, and I'm being very generous with my choice of adjectives. :-)

Katharine Osborne said:
MacRuby is in development. It stalled out for awhile, not sure if it is back on track:
http://www.macruby.org/

Hi Katharine - The MacRuby project is great, and I hope they continue to evolve it for use in development of Cocoa desktop applications, but I think something a little lower level will be required for use on mobile devices. Google Go, for example, might be closer to the sweet spot between C and Ruby.
Dan, If they invented a new language wouldn't that be NIH? ;)

Maybe it'll be something radical like announcing they're buying Google and moving all development to Go ;) hahaha
Absolutely, but which would be easier to pitch to Steve:

"Mr. Jobs, we want to abandon Objective C and move everything to Google Go. The fact is, Objective C is old and everyone else has nicer languages."

-- or --

"Mr. Jobs, we've invented a revolutionary appletastic language called Core (get it - Apple Core.) It has no flow control structures and all the keywords are in Japanese. Its so hip that it makes programmers over 40 go blind. We want to transition iOS and OS X developers to Core so they can be even sexier! Yeah baby!"

Brian said:
Dan, If they invented a new language wouldn't that be NIH? ;)
I've been doing some Obj-C recently. I like the syntax a lot. The ugly part are the NSWhatever classes. What's really cool is that you can mix C into the picture.
So, you are objecting to all the extra characters in the Objective-C code. All those characters are essentially degrees of freedom. It would appear that there are useless degrees of freedom in the Obj-C code. So the question is, are they truly useless? What about "alloc"? What do you get for those 5 characters? The answer is in the alternatives that could go there. The NSNumber class object has many other methods that could go there:
+ new
+ alloc
+ allocWithZone:
+ copyWithZone:
+ mutableCopyWithZone:
+ class
+ superclass
+ isSubclassOfClass:
+ instancesRespondToSelector:
+ conformsToProtocol:
+ instanceMethodForSelector:
+ instanceMethodSignatureForSelector:
+ description
+ cancelPreviousPerformRequestsWithTarget:
+ cancelPreviousPerformRequestsWithTarget:selector:object:
+ resolveClassMethod:
+ resolveInstanceMethod:
+ classFallbacksForKeyedArchiver
+ classForKeyedUnarchiver
+ setVersion:
+ version
+ numberWithBool:
+ numberWithChar:
+ numberWithDouble:
+ numberWithFloat:
+ numberWithInt:
+ numberWithInteger:
+ numberWithLong:
+ numberWithLongLong:
+ numberWithShort:
+ numberWithUnsignedChar:
+ numberWithUnsignedInt:
+ numberWithUnsignedInteger:
+ numberWithUnsignedLong:
+ numberWithUnsignedLongLong:
+ numberWithUnsignedShort:

So, the cost of having this diversity of class methods is that you have to put "alloc" in your initialization. Since it is so frequently used a method, the most efficient encoding would be to have a specialized shorthand for that method; this is what the other languages do. So then the question becomes, how do they achieve the functionalities that Obj-C implements by having this repertoire of other class methods?
Lee Altenberg: So, you are objecting to all the extra characters in the Objective-C code. All those characters are essentially degrees of freedom. It would appear that there are useless degrees of freedom in the Obj-C code. So the question is, are they truly useless? What about "alloc"? What do you get for those 5 characters? The answer is in the alternatives that could go there. The NSNumber class object has many other methods that could go there:...(clip)

All the languages I listed have static (class) methods, including those that can be used as an alternative to the constructor. The equivalent of NSNumber* value = [[NSNumber alloc] initWithFloat:1.0]; using a static method in Java is Float value = Float.valueOf(1.0f); The example I used for Java and C# utilizes boxing to accomplish the same thing (C#): Short value = 1.0F;

Objective C doesn't have anything special in terms of class methods. It does have the ability to route messages in a flexible manner, but so do many other languages. It has the ability to do low level memory manipulation with pointers, but so does C#:

   unsafe static void SquarePtrParam (int* p) {
      *p *= *p;
}
unsafe public static void Main() {
int i = 5;

// unsafe method: uses address-of operator (&)
SquarePtrParam (&i);
Console.WriteLine (i);
}

I maintain that you don't get anything for that extra typing. Its just old clunky syntax. You still have "NS" (NextStep) in front of all your classes because Objective C didn't have a concept of name spaces. That is very, very old school. Its a minor point, but when you have 100 things like this they start to impact code clarity and productivity. Apple can do better than a 30 year old language that awkwardly added some Smalltalk capabilities to C. I know they can!
Apple Core.. I like it! Go trademark it quick ;)

RSS

Sponsors

web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service