Design Element
Comment on "CocoaHeads: Objective-C 2.0"
by Blain — Sep 16
Ah. C#. That's a different kettle of fish. I'm intending to write an article about c++ vs ObjC, but the C# has a nice twist, in that it's not C-compatible.

Correct me if I'm wrong, but C# frowns on the use of pointers, and makes them mostly inaccessable. Problem is that, to play nicely with C, pointers are vital. C++ muddles through, and here's where the overloading falls apart.

All Obj-C objects are actually pointers to mostly-opaque structs. To get to the value pointed at foo, you use *foo. If foo is an array, you can point to the first element as bar = foo, and then talk about *bar, and the next element is pointed at by bar+1.

So suppose we have an C array of ComplexNumber.
ourNumber = numberArray[0];

No problem. The value of the complex is *ourNumber.

So if we want to add two complex numbers, we'd want
*c = *a + *b;
But we want to use constants as well.
*c = *a + 1;
which is a mess and much worse than brackets, especially when you get *c=*a * *b;!

So let's overload so adding pointers returns a pointer to the sum of the values.
c = a + b;
But now
c = a + 1;
is ambigous; Is that the index of the object after a in the array, or one added to the value of a?

Either we get confused scientists, or we lose backward language compatibility. Again, this is moot with a lang that doesn't allow for pointer math. But it leads to lots of bugs if it's not called a new language.

The thing is that complex numbers are an edge case, and Obj-C is meant more towards doing 80% really well instead of 100% mostly okay.

What would I suggest to the wayward scientist? Simple. If you know C#, use it, and the mono to cocoa bridge.

Or use a language taylored to the physics, and use obj-c to display, but not compute the results. Model, view, controller and all.
Back to "CocoaHeads: Objective-C 2.0"
Design Element

Copyright © Scott Stevenson 2004-2015