Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: NVDave
Fascinating. Scary fascinating.

The way you critique C, I take it that the Objective C used by Apple is no better?

16 posted on 07/20/2009 6:29:10 AM PDT by conservatism_IS_compassion (The conceit of journalistic objectivity is profoundly subversive of democratic principle.)
[ Post Reply | Private Reply | To 15 | View Replies ]


To: conservatism_IS_compassion

Objective-C IS better — than C++. Which is not a terribly high bar to exceed.

C++ is a language that cannot make up its mind what it is: a floor wax, dessert topping, engine cleaner or dietary supplement. You have OOP and programming by template in the same language, and mixing the two paradigms at the same time can result in seriously brain-twisting results. It is a very complicated language and yet in all the complexity, the language designers could not see fit to handle the #1 issue of languages like C++ — garbage collection and dynamic memory allocation. Why? Well, when we read their reasons, they sound a lot more like excuses.

Objective-C picks only one paradigm - OOP, and then does it well relative to C++: you can do only single inheritance (which is a positive, IMO), you can ask any object at any time “Hey, how did you get here?” and the language pushes late binding, which IMO is something that any OOPL should prefer. In Objective-C 2.0, there is a reasonably decent automatic garbage collection system - prior to that was a fairly mickey-mouse reference counting system.

The message system is simple and clean in Objective-C, they try to model the ideas on SmallTalk, which is a better OOPL than most of the “OOP” languages out there (by a long shot, really). If I had to pick one virtue of Objective-C over C++, it is that Objective-C is simpler; it doesn’t try to solve every programming problem in the world, it tries to solve a small set of issues ONE way, and then do it reasonably well.

So is it better? Yes - than C++. But then, in my opinion, C is better than C++. Does Objective-C solve the problems of C, ie, null-terminated strings, the confluence between arrays and pointers, the ability of programmers to botch pointer math, etc? No. Objective-C (as used by NeXT and then Apple) uses their own string class to avoid using C-style strings, but that’s not a solution in Obj-C any more than the zillions of string classes are a solution in C++. The problem with null-terminated strings originates in C and the C run-time library, and the only way to *eliminate* this problem from Obj-C or C++ is to break compatibility with C and say “this language will NOT SUPPORT C-strings and you WILL NOT call C libraries” to prevent programmers from shooting themselves in the foot with this particular loaded gun.

C/C++ resulted in one more thing that has seriously compromised system reliability: the assumption of C-based run time libraries as being the defacto run time library, regardless of the actual implementation language that calls them. This enshrines the issues like null-terminated strings and lousy exception handling in stone. In ye good ol’ days on a system like VAX/VMS, the run-time libraries had excellent support and were language-independent. Strings, (for example) had a “descriptor” that said “the string is currently X long, can become M maximum long, and is of type A,B,C where the various types were ‘static string,’ ‘dynamic string,’ etc. C-style strings could be modeled on these language-independent string handling routines, albeit with a bunch of fiddling that C programmers really didn’t like because the compiler didn’t do it for them. The libraries would return errors and throw exceptions based on VMS’ very good error/exception handling mechanism, which was also language-independent.

Today, we see that the run-time libraries on most Unix-derived systems are standardized versions of the C RTL - with all of C’s problems like null-terminated strings and the atrocious error handling methods of C. It is a huge step backwards for the industry, IMO.

I certainly have to admit that hacking in C (and a bit in C++) made me a nice living and allowed me to retire from the industry early - so in some ways I’m looking a gift horse in the mouth. But as an American, concerned about American security and overall system reliability as people’s lives are increasingly dependent upon system reliability, I have to be honest and say “things don’t look good” and the reason why they don’t, the “let’s scrape all this down to bedrock and identify where we went wrong at the foundation” type of reason is C and C++.


17 posted on 07/20/2009 8:28:49 AM PDT by NVDave
[ Post Reply | Private Reply | To 16 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson