Domain: friday.com
Stories and comments across the archive that link to friday.com.
Comments · 7
-
A lot of C Programmers are missing Objective-C
Disclaimer: I'm an Objective C Programmer by day
The LLVM compiler suite is tremendously powerful with Apple's billions advancing many select features, but key to it's success from a users prospective the core use of reference counted object graphs (of type 'id') and reflection (RTTI - via 'isa' and 'Class'). Obviously this means the entire language is dynamically typed at runtime, but with express qualification in 99% of the code you'll use there's absolutely no performance hit despite the ubiquity of the core object.
I worry that many C programmers will remember RTTI was once considered an unportable disaster in C++ because of the the many differing implementations owing to a spec that left the implementation up to each compiler... Don't let this kind of talk scare you! Although objective, objc is contained to a well defined spec, single inheritance and nary a template in sight.
I consider my programming work to be relatively easy. 50% of my ease comes from the object system above. The other 50% from the fast messaging system used in place of raw ADTs: In the objc world a nil object doesn't fault when messaged (in a C world dereferencing a NULL pointer, common if a struct fetching function fails and then passes NULL on failure) leads to all manner of crashes, or as seen recently, kernel exploits. The messaging system can even push around primitive values, not just nasty objects.
If you program in C, you may have missed Automatic Reference Counting, if you have, low and behold, it's amazing: at *compile time* the compiler adds lifetime qualifiers to the IR that automatically inserts retain and release messages (retain is +1 on alloc, -1 on dealloc - release occurs at 0). In other words the lifetime of an object in objective-c is now exactly the period of acquisition to last use. Yes, last use. ARC's use of a new 'weak' reference means that dangling pointers are a thing of the past: a __weak object is automatically nil'ed after last use: in all local instances of that object (did I say nil objects don't fault on message?).
Admittedly most of what I've mentioned is thanks to the advances in LLVM's Clang compiler, in particular it's static analyser, therefore much objc analysis also benefits C (LLVM's IR is quite specular ).
I could go on: methods can be heap objects with cblocks, objc encourages abstract programming with delegates, you can method swizzle at runtime, extend existing classes and link to C/C++ code.
-
Re:... and?
That's not fair, object orientation isn't strictly a language feature, it's also a generic pattern. Gobject is a C library but is object-oriented. Most object-oriented scripting languages are implemented in an underlying object-oriented C. Method(object, arg1,
...) and object->Method(arg1, ...) are equivalent, particularly if object is an opaque type not in the header.We could even cite the crazier case of Objective C or Objective J[avascript], where every method call becomes a call to a runtime of msgSend(object, methodNumber, args...).
This seems like a total hackaround to force a language into a box it wasn't meant to fit in, though in the case of Objective-C, objc_msgSend() is implemented in a few dozen lines of ASM and can be compiled to a direct dispatch for the non-dynamic case.
-
Re:Bizarre choice
WTF, what is wrong with Slashdot!!!!! has it become so popular that we can't understand how searching in a map works vs a vtable indirection!!!!!!
All of the implementation addresses are cached when run for the first time, and it's usually inlined; after the first invocation a message usually is only a cycle or two slower than a vtable indirection, given the normal caveats. objc_msgSend is extremely optimized, it's the single most called function on the platform so it gets a lot of attention from optimizers.
-
Re:Dinosour language
all the calls to methods as well as accesses to class properties are interpreted
.
It's also not quite true. Objective-c message passing is quite fast, only 4x the cost of a virtual table call in C++. If you are really interested in what happens behind the scene, see obj-c fast-path
Now, namespaces are still a honking good idea.
-
Re:The GPL is a Virus
People have been saying the GPL is a virus for a real long time now. I tend to agree.
-
Re:FPS?
Actually, even the lowley GMA950 video chip has some sort of hardware assist for decoding video, so it's not entirely a CPU task.
http://www.friday.com/bbum/2006/02/28/intel-mac-mi nis-video-card/ -
Re:New revision
The video card in the new Mini is weak.
Actually, it's a substantial step up from the PPC version. See Ken Dyke's comments in this thread.
-jcr