Re: cocoa-dev digest, Vol 2 #4268 - 14 msgs
Re: cocoa-dev digest, Vol 2 #4268 - 14 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #4268 - 14 msgs
- From: Glen Low <email@hidden>
- Date: Sat, 29 May 2004 19:26:48 +0800
On 29/05/2004, at 5:15 PM, email@hidden wrote:
From: Jim Witte <email@hidden>
Subject: Re: Cocoa Rules - ObjC "evalgelism"
Date: Sat, 29 May 2004 03:25:48 -0500
To: Tim Hart <email@hidden>
I'm more productive in Objective-C than in C, C++, Java or C#. My code
is easier to maintain, and more elegant. ObjC is definitely a great
language, and probably overlooked way too often.
That raises an interesting question: since ObjC is basically only
used on the Mac (as it was basically only used on the Next before OSX),
and since Windows-compatible Cocoa libraries look like a real pipe
dream, is there a need for "Objective-C evalgelism"?
I haven't played with the language much yet, but I can see that it
looks cleaner and more powerful than C++ (the OO part that is - I still
hate the C-language part - I did stuff in Scheme, so C code looks like
of primitive.. not to start a language war here.) C++ or Java are
arguably the dominant OO languages out there, and is also arguably not
a very good OO language - simple, constrained C++ might be good, but
the full language is just way to obstruce and allows you to make way to
many mistakes.
I'm in the mood for a couple of flames. Taking care of two screaming
kids over the weekend does that to you.
All mature languages have their issues. You can do some really
boneheaded things with Objective-C and Cocoa, for example, it's not
always clear what increments a reference count and what doesn't, so
your code can crash at strange times when the runtime decides to purge
its autorelease pool. And you might tie yourself up in knots
implementing copyWithZone: in a subclass. And you might accidentally
call through to the "non-designated" initializer etc. Or unprotected
pointers with the dangers of pointers but none of the benefits.
This guy says it better than me:
http://rentzsch.com/papers/loveHateObjC
As for object-orientation, it really depends on what you mean by that.
Yes, Objective-C is more dynamic, but its heritage is based on
Smalltalk-style object orientation. C++ is based on Simula-style object
orientation. See:
http://www.research.att.com/~bs/bs_faq.html
IMHO C++ has lost some edge in object orientation to Java and C# (since
these languages have better RTTI/Reflection, runtime loading support,
libraries etc.) , but has more than made it up with generic
programming, which approaches the flexibility of ObjC dynamic typing
but with compile-time checking. The Standard C++ libraries lets you
write collection-based code at a fraction of the size of comparable
ObjC, Java (pre-1.5) or C# (pre-generics). Now Java 1.5 has quite a
nice generics facility which maintains some backward compatibility.
Obj-C would seem to have a good chance of replacing C++ as the OO
language-of-choice (Java would be harder, because it's newer, and is
closer to Obj-C anyway). But Apple pushing it only on Macs isn't going
to do it. Now, can WebObjects stuff be written for Windows in Obj-C,
or have they gone completely Java with WO?
This is the curious thing -- IIRC ObjC is at least as old as C++, e.g.
I have Brad Cox's "OOP An Evolutionary Approach" from 1986 where he
talks about ObjC. Perhaps AT&T's clout with C made C++ as the logical
successor and not ObjC. Perhaps it was M$ and the whole emphasis on
MFC. Perhaps it was the whole standardization process. But equally
obviously, C++ has evolved a lot from c. 1980 while ObjC has remained
fairly static, and in some people's mind that makes C++ a better
language.
Now as for cross-platform Cocoa, there's always GnuStep, but they're
playing catch-up with Apple just like Mono is with Microsoft .NET.
(<my rant on operator overload. See "The Dark Side of Java">)
And why the $#@% didn't the C99 bunch introduce *user-defined*
operator-overloading, instead of just overloading the one's already
there. A Vector class comes to mind immediately - you have two
multiply operations - one goes on *, where does the other one go?
Where does unary normalize go? Rotation of one vector around another?
I've seen a vector class that overloads << to be a damn math operation!
I haven't looked at the C99 specs, but perhaps the reason why C doesn't
have operator overloads is because they don't have classes like C++.
With any technique, you have to use it sensibly; an operator overload
only makes sense if the meaning of the operator intuitively corresponds
to its syntax. I can say complex * complex, since that makes sense, but
what does it mean intuitively for rectangle * rectangle? This is no
more dangerous than naming an arbitrary method in ObjC "initMe" when it
does nothing of the sort.
Now operator overloading for binary operators only makes good sense as
binary free functions, not member functions, for various reasons.
Unfortuately both Java and C# don't have free functions -- oops! -- so
while Java threw it out entirely, in C# you can define A * B in either
class A or class B, which frankly is quite confusing. The fundamental
issue there is that both Java and C# are too religious about "all
functions must be in an object", some functions really relate to two
objects or more and not one, then there's the confusion about which
object it really belongs to. At least in C++ and ObjC to a lesser
extent, you can have a free function that has two or more objects as
parameters.
BTW, isn't operator<< a math operation, shift left?
Sheesh, no wonder op-overloading was thrown out by Java. Except
they
threw out the baby with the bathwater, making the use of a
complex-number class in Java a mind-bending exercise in prefix
notation. If only they'd allowed user-defined operators (or
equivalently, procedures whose names just happen to come BETWEEN the
arguments) it would have been fine. But no, they have to make things
SIMPLE! That means they don't take the best parts of Obj-C and refine
parts of C++ - they through out the worst parts of C++, and end up with
something that is a lot harder to use in certain applications..)
Ah Java. There's of course an operator overload happening for string
concatenation, so they're not entirely "pure" either. And you can't
special-case more classes because then you can't write a library
without invoking the special case, and muddying up the compiler. How
would Java bless some classes as able to use operator overloads and not
other classes?
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.