This week I'm trying to learn objective C. It's quite a nice language, with reference counted garbage collection (albeit manual reference counting), and fairly loose typing (compared to C++ or Java that is).
The syntax is rather strange though. I think that's the most offputting thing about the language. To call a method on an object, it looks something like:
[myobject method]
But then if there's a parameter to go into the method, it has a colon in it:
[myobject doSomethingWith:anotherobj]
It's also got some named parameters stuff, so you can have:
[foo insertObject:bar atIndex:5]
Note that the first parameter is bar, but it's almost not a named parameter. This is interesting because I use this kind of call style in Perl a lot, where I'd do:
$self->method($param, %options);
Which seems to be pretty much the same thing, except Objective-C has it built into the language, and comes with parameter checking.
Anyway, I'll post more as I code up more interesting things.
It's a direct lift from Smalltalk (Score:1)
anArray insert: anObject at: 5
Objectionable C:
[array insertObject: object at: 5]
Quite cute really. Makes it a lot easier to use simple type suggesting variable names 'cos they're not having to do double duty to describe what they're for as well as what they are.
Re:It's a direct lift from Smalltalk (Score:2)
Someone once suggested to me it was nice that Obj-C was nice because it showed you very clearly what parts were method calls, and what parts were just regular C code. I'm not sold on that yet, as I don't really have a problem with that in other languages. But my mind is open on it, and the OS X tools are nice enough that it won't sway me either way.
Re:It's a direct lift from Smalltalk (Score:1)
The method selector tells you what each argument is for, the parameter name tells you what it is. Actually, good Smalltalk style is to only use type suggesting variable names for method argument names. The method body that I lifted the above from, for instance, continues:
| index |is Smalltalk formy $index. Note that there's an assumption in the implementation that thBrad Cox Wiki (Score:2)
http://www.rubygarden.org/ruby?BradCox