“It is a surprising fact that anyone studying GNUstep or the Cocoa Framework will notice they are nearly identical to the NEXTSTEP APIs that were defined ten years ago. A decade is an eternity in the software industry. If the framework (and its programming language–Objective C) came through untouched these past ten years, there must be something special about it. And Objective-C has done more than survive; some famous games including Quake and NuclearStrike were developed using Objective-C.” Read the introduction to Objective-C at LinuxJournal.
“Every object also carries an is an instance variable that identifies the object’s class (what kind of object is it?). This allows objects to be typed dynamically at runtime. isa also allows objects to introspect themselves so they can find out what methods they have”
Indeed, THAT is a good functionality for a language.
I’m currently writing C++ code that needs to ‘represent itself’ in a XML doc, and that’s a pain
> Indeed, THAT is a good functionality for a language.
> I’m currently writing C++ code that needs to ‘represent
> itself’ in a XML doc, and that’s a pain
Granted, C++ doesn’t have reflection, but that has nothing to do with the dinamicity of the language, it could also be implemented in C++. However, Objective-C is slower than C++ at invoking methods, much slower: from 70% up.
Given the recent progress with bytecode compilers,
I don’t see a reason for Objective-C to be slow
anymore.
> Given the recent progress with bytecode compilers,
> I don’t see a reason for Objective-C to be slow
> anymore.
Objective-C programs aren’t bytecode. Objective-C uses a rather advanced runtime to dispatch messages, create objects and keep all the other good stuff going. If you got a GCC install available you might want to look at the objc directory of your GCC directory. There are all the header files needed to programmatically reach the Objective-C runtime from C.
> Granted, C++ doesn’t have reflection, but that has
> nothing to do with the dinamicity of the language, it
> could also be implemented in C++. However, Objective-C is > slower than C++ at invoking methods, much slower: from
> 70% up.
You could also implement a complete object system in x86 assembler so what is your point? The thing with Objective-C is that you don’t have to implement all that yourself. The compiler does it all for you and thus saving you a lot of effort. If you need some function to execute at high speed just have ordinary C functions, they bypass the Objective-C runtime and avoids the message dispatch overhead.
>Given the recent progress with bytecode compilers,
>I don’t see a reason for Objective-C to be slow
>anymore.
ObjC is *not* slow, that is a myth! Method invocation is a
little slower than a member function call, but you have to
measure the difference in order to notice it…
BTW you can do some neat runtime tricks to speed up method
invocation, so you can perfectly write high performance stuff in ObjC ( note that ObjC uses a runtime which is not the same as interpreted bytecode in a virtual machine ).
The problem with reflection and RTTI is that people are not disciplined enough to use them properly. The resulting code is usually worse than bad. It is a cluttered, inefficient, unmaintainable, unextendable mess that is able to describe itself.
This is not a general case against RTTI and reflection. But i´ve seen few good coders who are up to the task of resisting that sweet temptation and that are the ones that usually don´t even ask for it. Everyone can put on the ring, but everyone is a ringbearer 🙂
> You could also implement a complete object system in x86
> assembler so what is your point?
My point is this:
> Granted, C++ doesn’t have reflection, but that has
> nothing to do with the dinamicity of the language,
In other words, the fact C++ doesn’t have reflection has nothing to do with the fact that C++ is a statically typed language or, in even other words, the fact that Objective-C has got reflection has nothing to do with the fact that it’s a dinamically typed language.
In yet other words: you completely missed my point.
> ObjC is *not* slow, that is a myth! Method invocation is a
> little slower than a member function call,
It’s not “a little slower”, it’s MUCH slower at invoking methods: unless special tricks are used for which all the available methods of ALL the installed classes are known and unless a special table with all of these methods is created, and unless the compiler uses this table to dispatch methods, which means that no classes can then be thrown in the system at runtime anymore, the only approach that can be used to invoke methods is an hash table which gets filled when methods are invoked and which has the function of a sort of method’s cache: this system is more than 3 tymes slower than a virtual method invocation in C++.
Any trick to make invocation faster is what it is: a trick.
A while back I did a fair amount of benchmarking of this, so to get some hard numbers (well, lies, damn lies, etc.; this is what I got at the time):
(in clock cycles on my PII 400)
normal c call, loop and benchmark overhead: 8.12
c++ virtual method call: 10.52 (+2.4)
objective-c method call: 21.68 (+13.56)
(objective-c method call with manually cached imp: 9.24 (+1.12))
Objective-C is slower (in fact, nearly 6 times slower, counting from the normal c case) but this is still only an 11 clock cycle difference. There are places where this makes a difference, but most of the time it’s irrelevant. If you need the extra performance, the standard solution is to simply cache the implementation lookup; this is a bit of extra work, and you lose some features, but it’s faster than even c++. IMHO, all the extra features you get are well worth 11 clock cycles.
> Any trick to make invocation faster is what it is: a trick.
Not at all; it’s called an optimization. The GNU objc runtime manages to be dynamic, thread-safe, and fast. It’s all in gcc/libobjc/ if you want to know how.
To claim Objective-C is more flexible than C++ is just marketing speech. While it is more dynamic in its OO part does not mean it is more flexible as a whole. Take for instance the fact that C++ offers generics which Objective-C obviously lacks and even though I would not call C++ more flexible just because of that.
Do some research, buddy.
class DynamicallyTypedObject {
ObjectType type;
};
’nuff said.
So maybe you could enlighten me — I was referring to parametric polymorphism or Milner-style polymorphism or how you call it, that is generic type definitions (generics). I don’t see direct support of this in Objective-C, do you?
C++ does allow you to ask if an object is of a given class.
That is given the pointer bar of unknown type, you can ask: is this object foo of class <ul>bar</ul>
but i must admit I have yet to se any examples where using dynamic typing was “The right thing” to do in an OO language. (Yes I have done it, but it was as a “Quick hack, release now and patch tomorrow” not as a permenent solution.
Martin Tilsted
[Please ignore the previous mail, this is the right one]
C++ does allow you to ask if an object is of a given class.
That is given the pointer foo of unknown(void *) type, you can ask: is this pointer foo a pointer to an object of the class <ul>bar</ul>
but i must admit I have yet to se any examples where using dynamic typing was “The right thing” to do in an OO language. (Yes I have done it, but it was as a “Quick hack, release now and patch tomorrow” not as a permenent solution.
Martin Tilsted
i don’t believe parametric polymorphism exists in objective-c, but then, i also don’t believe it is needed. if you require polymorphism then you can use the type “id”, which can be any object. i’m not sure if it can take the place of an int, a double, or any non-class type.
Actually, Ojbective C has some more problems beyond inherent speed hits. The problem is that current ObjC compilers just aren’t designed to optimize away the abstractions like current C++ compilers are. C++ sees a lot of use, but it was only recently (with GCC 3.1 and Intel C++ 6.0) that most C++ abstraction features were optimizable by the compiler. These days, you can take any piece of nicely abstracted C++, and be reasonably sure that the compiler will compile into tight machine code. Becuase ObjC doesn’t see as much use, it doesn’t have that luxury. Of course, this is no reason to not use ObjC. Even if using it entails an overall %25 percent speed hit, with todays processors that’s not big deal. And if it’ll stop you from using something truely dreadful like Java or C#, then that’s great. In the end, the speed of your app (barring disasters like Java) depends on your algorithms, not so much your language. It only takes GNOME and KDE to prove that just because its written in C or C++ doesn’t mean its fast.
IMHO, all the extra features you get are well worth 11 clock cycles.
Why did you not list normal C++ functions?
Do some research, buddy.
DIY.
Indeed, THAT is a good functionality for a language. I’m currently writing C++ code that needs to ‘represent itself’ in a XML doc, and that’s a pain
Can you not implement reflection in C++ using templates?
i don’t believe parametric polymorphism exists in objective-c, but then, i also don’t believe it is needed. if you require polymorphism then you can use the type “id”, which can be any object. i’m not sure if it can take the place of an int, a double, or any non-class type.
Can you create a list class in Objective-C that handles any type without a ton of messy casts and which has performance as good as or better than C? A vector? A hash map? A deque? A sorting algorithm? I would rather not rewrite this code every time I want to use a new data type in those containers, and I do not wish to sacrifice the performance.
In the end, the speed of your app (barring disasters like Java) depends on your algorithms, not so much your language.
Why use a language like Objective-C? Why would one want to have to reimplement containers and algorithms for new types? Why can one not have a nice, fast algorithm that works on int’s, char’s, float’s, foo’s, and bar’s using C++ templates?
WindowMaker is written in C. while it’s touted as the “GNUstep Window Manager”, it’s simply a NeXT-ish wm written in C. the original window manager written in objective-c is available at http://interfacewm.sourceforge.net.
> Can you not implement reflection in C++ using templates?
That’s right, but to obtain full dynamicity, as well as backward compatibility, i’m currently using ‘interfaces’ (pure abstract classes). So, no templates.
Then, each class of mine derive from pure abstract classes,
and use aggregation to not rewrite functionalities.
Kind of java keyword ‘interface’…
Can you create a list class in Objective-C that handles any type without a ton of messy casts and which has performance as good as or better than C? A vector? A hash map? A deque? A sorting algorithm?
Yes. The typing system is dynamic enough that you can put any objects (declared as id) into any data structure you want. So long as they respond to the messages you want to send them (which you can even check at runtime, if you wish), you can have as many different types of objects in the same data structure as you wish.
In tight loops and such, where performance might be a concern, you can drop down to the runtime and get actual method pointers to use. This removes a degree of abstraction–the same degree that you always lose in C++ when using non-virtual methods, at roughly the same cost (i.e., loss of dynamism)
There’s nothing worse than listening to a bunch of people participating in a urinary olympics about their favorite language. “My language is better than yours! Nyah nyah!”
Please try to take an position of objectivity when evaluating a new technology (or old, as in this case). Take the time to read some information about it, and attempt to put it into a larger context.
Here are some observations on Objective-C and C++:
* Objective-C was designed to rapidly construct entire “applications”. Typically, in a GUI environment, the vast majority of time is spent diddling around with the UI libraries to get things to work correctly.
With this in mind, the language designers made what I feel is a surprisingly pragmatic decision: Implement a dynamic language construct (message dispatching) to get the benefits of a Smalltalk-like approach without the “everything is an object” overhead. Notice that they added this extension to C, a language that can really cruise when performance is of the essence. They got the best of both worlds: a dynamically typed language that’s great for GUI application development, and a high-performance language that everyone was already familiar with.
Compare this to the approach taken by Stroustrup when designing C++. Let’s make up so much new and ambiguous syntax for the language that compiler developers won’t even figure out how to parse it correctly for the first several years. Even now you’d be lucky to find a compiler that *CORRECTLY* implements the entirety of the current C++ spec. Whatever you may think about Objective-C, the *simplicity* of the language makes it EXTREMELY easy to work with.
* Objective-C has a vast number of classes in its standard library, much more than C++. Here the language designers also took a page from the Smalltalk book and provided a comprehensive set of intelligently designed class libraries that did just about everything. (And where they didn’t you could change them!). The C++ development community is only now reaching a semblance of this level of library reuse (e.g., C++ Boost). Some people don’t like this approach, as there’s a lot to learn before really becoming an effective programmer, but that’s the beauty of it. You can enter the job market after having used this library knowing that the past several months of net-based development wasn’t wasted on proprietary implementation quirks, etc.
* Generics aren’t as necessary in Objective-C because it is a “dynamic” language. This is the same reason that you don’t need generics in Smalltalk or Lisp – the language itself is generic.
You are forced to use generics in C++ because C++ has a “broken” type system (compared to the Hindley/Milner variants in use in other advanced programming languages, such as Haskell, ML, or O’Caml). So, be careful to not toot that “C++ Generics Kick Ass” horn before you realize that the implementation of templates in C++ is a workaround for yet another problem in the design of the language. (As cool as templates may be!)
C++ has a tremendous number of problems (if you deny this then you’ve probably only used C/C++). However, all languages have (major) problems, and at least we can thank Bjarne/Stepanov/et.al for being single-minded about performance.
Personally, *I* can’t wait until we have a standard way of designating and using aspects in C++. That will *really* rule.
MY HAMMER IS BETTER THAN YOURS
stanley’s are shit…craftsman BABY!!!
i don’t here carpenters talking that way…
guess what programming languages are TOOLS not religions, not lifestyles…tools
some tools work better for a problem than others…if you’re a good programmer, you’ll become proficient in several different languages so that you can use the right tool for the job…C is good for certain things, Obj-C is good for certain things C++ is good for certain things…you can write a CGI script in Assembly language…does that mean you should?
You can use Java to write an X11 window manager, but should you?
How many carpenters do you see using a hammer to fix every problem? or using a hammer as the only tool to build a house with?
people have gotta stop using C++ as the only language to implement everything with…b/c sometimes its not the best use of time and resources
for GUI code…Obj-C rocks…for server code Java and Perl rock…high-performance code…you gotta go with C and C++ and for ultrahigh performance code nothing beats assembly language
-bytes256
hehe. good observations, i agree completely.
btw, i’d trust an optimizing compiler to do a better job than most people can do in assembly.
for GUI code…Obj-C rocks…for server code Java and Perl rock…high-performance code…you gotta go with C and C++ and for ultrahigh performance code nothing beats assembly language
I’m not sure about the standard GCC compiler, but Apple’s compiler supports Objective C++. That is, you can intermingle C++ code/objects with Objective-C code/objects. The only thing you can’t do is have Objective-C objects morphing into C++ objects. Since you can now integrate C,C++ and Objective C code all together, why not write the engine in C/C++ for speed reasons, where most of the tight loops are, and write the interface code in Objective-C?
Does it support templates and therefore something like the STL lib?
Generics aren’t as necessary in Objective-C because it is a “dynamic” language. This is the same reason that you don’t need generics in Smalltalk or Lisp – the language itself is generic.
Obviously this is stupid. You need generics (templates) when you want to have fast code for tight loops and small operations (e.g. dereference an iterator). C++ was designed with this in mind, which it seems Objective C was not. One person says “11 cycles is not much”. Well, if you spend 11 cycles of method invocation each time you dereference or increment an iterator, for example in a very tight calculation loop, then it becomes much, too much !
There are some 3D engines coded entirely with template-based containers (I’ve seen one in a French game company). Obviously this kind of application wouldn’t be efficient if the container/iterator classes couldn’t benfit from compile-time optimization and even inlining of container/iterator method calls.
for server code Java and Perl rock…
I don’t know exactly what you are talking about, but if you suggest rewriting Apache (for example) in Java or Perl I fear the result would be quite laughable…. If you are talking about CGIs and the like then it seems more reasonable (but still heavily visited sites have problems with PHP’s poor performance, for example).
> MY HAMMER IS BETTER THAN YOURS …
I think this is a poor and overused analogy.
Programming languages to a developer is maybe somewhat more like brand-of-tools to a carpenter/contractor — but even that’s a stretch too.
It takes *way* longer to learn to use a programming language than it does to learn to use a Metabo hammer drill.
That’s right, but to obtain full dynamicity, as well as backward compatibility, i’m currently using ‘interfaces’ (pure abstract classes). So, no templates. Then, each class of mine derive from pure abstract classes, and use aggregation to not rewrite functionalities. Kind of java keyword ‘interface’…
Inheritance is not necessarily the best mechanism for achieving code reuse. I think that people really overuse inheritance. Of course, that does not help you with your problem…
Yes. The typing system is dynamic enough that you can put any objects (declared as id) into any data structure you want. So long as they respond to the messages you want to send them (which you can even check at runtime, if you wish), you can have as many different types of objects in the same data structure as you wish.
That was not what I wanted to know. I wanted to know whether one could implement generic algorithms and containers as efficiently as in C++. One cannot even do this in C. For example, C’s qsort function is inherently slower than C++’s sort function template.
In tight loops and such, where performance might be a concern, you can drop down to the runtime and get actual method pointers to use.
That is still not quite as good as a nice inline comparison functor.
This removes a degree of abstraction–the same degree that you always lose in C++ when using non-virtual methods, at roughly the same cost (i.e., loss of dynamism)
Non-virtual methods are the default because virtual methods are not as frequently needed. why bear the performance cost when it is unnecessary?
Notice that they added this extension to C, a language that can really cruise when performance is of the essence.
C is almost as good as C++ as far as performance is concerned, but it lacks the generic facilities and stronger typing that would really make it shine.
Compare this to the approach taken by Stroustrup when designing C++. Let’s make up so much new and ambiguous syntax for the language that compiler developers won’t even figure out how to parse it correctly for the first several years.
Oh, that’s real objectivity for ya! Or did you mean object-ivity as in “let’s all root for Smalltalk-like objects!”
The approach that Stroustrop took was to add Simula-like features to C, thereby enabling him to write object-oriented code. The real reason for the ambiguities is that C had a large number of problems that the C community had no interest in fixing, so the C++ community began incorporating fixes into C++. The languages continued to grow further apart, but eventually C incorporated most of the fixes and new features (albeit years later). C++ was not standardized until 1998.
Even now you’d be lucky to find a compiler that *CORRECTLY* implements the entirety of the current C++ spec.
Yes, just like C99 and most other recent language standards. Most of the important things have been correctly implemented, and there are more good C++ compilers than Objective-C compilers.
Generics aren’t as necessary in Objective-C because it is a “dynamic” language. This is the same reason that you don’t need generics in Smalltalk or Lisp – the language itself is generic.
Objective-C is not a generic language. There is no way to express templates nor any way to generate class and function definitions from templates. It is dynamic, and to a certain extent it can do the same job. But it is not the same thing. There is not a generic language; C++ merely contains some facilities for writing generic code.
You are forced to use generics in C++ because C++ has a “broken” type system (compared to the Hindley/Milner variants in use in other advanced programming languages, such as Haskell, ML, or O’Caml). So, be careful to not toot that “C++ Generics Kick Ass” horn before you realize that the implementation of templates in C++ is a workaround for yet another problem in the design of the language. (As cool as templates may be!)
Being able to write a sort function that outperforms C’s qsort and yet works for any data type capable of ordering is evidence of a language flaw? Do tell.
C++ has a tremendous number of problems (if you deny this then you’ve probably only used C/C++).
What problems?
Personally, *I* can’t wait until we have a standard way of designating and using aspects in C++. That will *really* rule.
What are aspects?
people have gotta stop using C++ as the only language to implement everything with…b/c sometimes its not the best use of time and resources
More often, though, developers simply do not know how to use the language correctly.
no i wasn’t talking about rewriting apache…yeah that would be funny to see a perl powered apache
i was thinking about mod_perl and JSPs and CGI and such
Please stop focusing on fast sorting of linear datastructures!!! I have NEVER been in a situation where a product failed to deliver due to a too slow sorting routine. Never, ever, period.
What I have experienced are failed deliveries due to overly complex designs, poor maintainability and time consuming bug chasing. Any feature in a language that helps with these issues are for more important than having the ability to have a parameterized sort routine run at double the speed of the competition.
If you really think performance in general method dispatching or gaining a 20% speed increase when sorting vectors is so important to your program maybe you should reconsider your design.
Take C++ and you get Taligent.
Take Objective-C and you get NEXTSTEP and then Cocoa on Mac OS X.
It’s all about differences in dynamicity and flexibility here.
All thes talks about templates and having a great sort function are interesting but they tends to hide the fact that you can’t, with C++, have collections of heterogeneous objects! Which is a trivial thing to do with Objective-C and Smalltalk.
As Alan Kay said: “I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.”
Please stop focusing on fast sorting of linear datastructures!!! I have NEVER been in a situation where a product failed to deliver due to a too slow sorting routine. Never, ever, period.
Well, maybe you haven’t, but some others have. Why do you think the different STL implementations are so carefully-coded ? Why do you think they even bothered include the memory allocator in the template arguments for the container classes, so that one can choose his own allocator ? Yes, you get it, because some people do have strong performance constraints. I was mentioning a video game 3d engine, it’s clear that in this case you desperately need performance ; it’s not a design flaw because performance _is_ part of the design goals ! C++ allows it along with flexibility (and yes, some people _do_ define their own memory allocator, e.g. to better deal with memory fragmentation but also cache line size etc.). Now I also, of course, agree that in some cases you don’t need all that performance ;-))
Another template-based framework often used in performance-critical – even real-time – applications is ACE (Adaptive Communication Environment). See it at http://www.cs.wustl.edu/~schmidt/ACE.html
Take C++ and you get Taligent.
Take Objective-C and you get NEXTSTEP and then Cocoa on Mac OS X.
This is irrelevent. An example does not make for an argument. There are desktops written in C++ (I guess KDE is), others in C (Gnome ?), Objective-C (GnuStep), or even a blend of Pascal, C and C++ (Windows I think). So what’s the point ?
you can’t, with C++, have collections of heterogeneous objects!
Are you kidding ? :-))
You can just inherit your classes from the same base class. Either your objects share some interface properties, and you can do it cleanly because it is part of the design (and you should do it anyway ;-)) ; or they don’t share any common interface property, and then I don’t see the f**ing point of putting them together in the same collection ! (or then it would _really_ be bad design on your side !).
For your record, MFC for instance _do_ allow collections of heterogenous objects, because they use your paradigm of using polymorphism instead of generics. It just stinks, both conceptually and in terms of performance, compared to STL constructs. Nevertheless MFC are in C++ so it shows you’re wrong.
As Alan Kay said: “I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.”
That isn’t an argument either. We are talking about programming language advantages and disadvantages. Terminology issues are not a valid point. And nobody should care about who invented the term “object-oriented” (well, not more than who invented the Internet (Al Gore)) because there are tons of different acceptions according to the underlying tastes and philosophies of people using the term. And the fact that perhaps the term drifted from its original meaning, is no valid point at all. Words and meanings are always changing, or then the language is dead (like ancient Greek).
Yikes. Its 1990 all over again. We just need some Java programmers yelling at both sides for incorporating features that could be misused in the hands of a retarded yak. Seriously though, the two languages are designed for two different things. C++ (according to its creator) is a multi-paradigm language. Its procedural when you need it, object oriented when you need it, generic when you need it. A nice multi-purpose tool. ObjC, instead, is a really good object-oriented language. You use whatever you’re comfortable with, and whatever serves the task at hand best. I blame the article for instigating this whole thread, there was no point taking jabs at C++ just to point out the merits of ObjC.
PS> As for ObjC not needing templates, bull. Its just like Java not needing templates. Generic containers in both languages break type safety by using the equivilent of a void *. Sure errors typing errors are caught at runtime, but its better for typing errors to be caught at compile time, before the product ships (almost infallibly) without enough testing.
PS> Also, I find the comment about C++’s syntax funny. C++ has a much more C-like syntax than ObjC. It uses keywords, rather than funky meta-characters (@ and whatnot). In fact the only non-C-like syntax introduced in C++ is the <> construct for templates.
Anyone whos uses any kind of tool from day to day will be opinionated about those tools. For example, Stanley DOES make a better hammer. It has some nifty shock abosorption technology in it. Very crafty.
I think the most telling thing WRT C++ Templates and Obj-C dynamic typing is how few implement the former, and how many implement the latter.
There are a plethora of languages that have an object systems like Obj-C, with Java the current heir apparent.
Very few languages that *I’m* aware of have taken on and embraced the C++ template technique (which, of course, is NOT an object system, it’s a templating mechanism, however in this discussion, they’ve sort of become synonymous for generic containers).
Now Java is getting generics in 1.5 (and has them now), but that appears to me to be completely syntactic sugar, rather than really adding anything to the language model. However, in Java there IS a runtime cost to casting an object from ClasaA to ClassB, so generics should also have some marginal performance benefit.
But, the motivation for Generic Java isn’t the performance, it’s just the casting with the generic containers.
Now, one might be try and argue that Lisp Macros == C++ templates, but that’s not even close. Lisp Macros are FAR more than what C++ templates provide. Scheme/Dylan define-syntax macros fill a different need than C++ templates.
I think that a good Dylan compiler has enough information to produce a hi performing, “generic” sort routine if the coder was willing to lock that routine down and seal the data structures. That is, the programmer has the option to pay the price of static typing for performance, but does not have to pay that price for the entire application, nor necessarily at the start of developemnt. The programmer can “tune” things like this in later in development. C++ coders have to pay that price immediately.
Anyway, I think that templates are a boon to the C++ programmer, but I also think it’s a shame that they’re needed at all.
As a clarification, I don’t think that Objective-C is *better* than C++ (or vice-versa). I was only pointing out that it was developed with a different goal in mind, and various aspects of the language are tuned to that goal.
I use C++ for very high-performance library development myself, and I would go insane if I had to go back to the pre-template days. All I’m advocating is taking the time to understand the strengths and weaknesses of other programming languages. I think Eric Raymond said it well in reference to LISP:
LISP is worth learning for a different reason – the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot.
I think the same is true of “aspect-oriented” programming (http://aosd.net). I believe aspects are the next evolution of object-oriented programming (templates/genericity being the last) and can significantly improve overall system structure.
Unfortunately for C++ developers, aspects haven’t yet caught on as much as in the Java community – there are already a number of aspect-oriented tools available for Java. However, I’m hoping that we’ll see some of this technology incorporated into C++ in the near future. Like templates, it will be a great tool to have available.
So anyway, besides a diferent sintax, what are the advantages that ObjC has over C++ and vice-versa?
In what type of situation is ObjC better? Can objc lib’s be linked to c++ and vice-versa?
The programmer can “tune” things like this in later in development. C++ coders have to pay that price immediately.
Anyway, I think that templates are a boon to the C++ programmer, but I also think it’s a shame that they’re needed at all.
Bullshit #1. Do you read other statements before typing in your own ? Several people have already explained why and in what cases templates are necessary, **be it in C++ or anyother language**. Templates are not a workaround, they are a feature on their own ! If you don’t mind raw speed, good for you, but some do.
Bullshit #2. Do you read other statements before typing in your own ? Generic containers can also be coded in C++ without templates, using inheritance. It’s simply a less intelligent way of doing the stuff. See MFC. It does it, and people prefer STL.
Bullshit #3. C++ is not the only language to have templates. In fact, ADA 95 has exactly the same. It’s called “generic” if I remember correctly. And, although I personally don’t like Ada at all, I wouldn’t go as far as saying that it is not a language that has been successfully designed with precise goals in mind (reliability, error-proofness and speed). Ada is the leading language is industry applications that need high reliability (I mean real industry, not Web servers or desktop managers…). All its features were weighted carefully towards that goal. And it has templates.
Bullshit #4. The fact that few languages have a feature does not mean the feature is useless, nor that it is a workaround. After all, if you take all computer languages, not many are really object-oriented (I mean, not just some syntactic sugar like in Perl or whatever). That doesn’t mean object-orientation is a workaround for a weakness in object-oriented languages….
Though I see no point in posting here, since there are so
stuborn C++/templates fanatics around here, I wanted to make a posting:
I’m developing in Objective-C/GNUstep and I also programmed on OPENSTEP and MAC OS X (in Objective-C).
If you say there is a need for “templates”, then you’re wrong. I mean templates might be a nice feature for C++, but I don’t miss the functionality in ObjC at all. Because I don’t NEED it. ObjC offers many other features like
dynamic binding (not that late binding crap in C++), dynamic AND static typing etc. Polymorphism is no issue, you can throw in any object in any container WITHOUT casting and worries whether it will work or not. It just works. Polymorphism in C++ is crap, and nobody who has used both languages (C++ and ObjC) in larger projects that use this feature can tell you this.
Why do you need templates anyway? Abstraction?
When anything is an object and treated as such (no differences amongst different types of objects), why do you need templates then?
Yes, I code for living (=earning money). And I do real OOP.
ObjC/OpenStep is very mature. One reason why it didn’t change for 10 years is that there is no need to change anything. It has a clear design and after 10 years you can guess there are not many (known) bugs in the implementations.
If you want C++, then code C++. in the gcc shipped with MacOS X you can also mix C++ and ObjC, and there is a patch
for the FSF gcc (NOT beta, it’s working!) that will finally make it in the official gcc soon.
About the speed issue: that’s crap. 25% overhead. blabla.
That’s just the overhead in method calls. Most executed code is C like anyway.
You have to consider that you have much more functionality in ObjC message passing, ie. you can call REMOTE objects on a different server (Distributed Objects, eg. PDO).
If you want the same speed as in C/C++, then use C function calls or call/cache the selectors (method/function pointers). This is NOT a hack/trick, it’s well documented and was always there EXACTLY to deal with this issue, if you want speed.
ObjC is a real OO language, C++ is NOT. ObjC is a multipurpose programming lanugage with minimal efforts. It’s not specialized in speed (use assembler for that), or to confuse people (use C++ for that).
I don’t like C++ after I realized I can make the same things with no more efforts (but less) in ObjC. BTW, I used to teach C++ at the university.
Java is IMHO also no real OO language, so don’t even try to compare Java, C++ and ObjC.
Sorry, but I’m very biased here.
Comments welcome.
greetings max
I probably will never learn how to post here … f***ing CR
Why some people says that they need a fast language like c++ to code videogames.
Why do you need c++ in videogames?
Code them in C and assembly.
Please do not tell me that you use c++ because you have object orientation and templates.
C++ is a broken language: you spend too much time understanding the sintax than coding.
Templates in my mind are a very broken thing: you lose a lot of memory.
If you have to design it is better to use Eiffel.
If you have to code fast you can use C.
A final note: objective C is not so bad because IT IS C. With some sintax added to aid large scale programming.
So it is fast. Easy to understand and scalable.
Not perfect. But better than c++ in many points.
you want it, you got it:
http://www.jcraft.com/weirdx/
… I also am sorry to understand that now developing=marketing. Some languages like c++ are used more than better ones (Eiffel, OCaml, Ruby, Objective C) only because they are better publicized.
After C++ now it is the turn of Java to be the “best” language. After that C# will be the latest trendy language.
I am sorry for that.
I don’t miss the functionality in ObjC at all. Because I don’t NEED it
Aah, so all we need to do is convince the world that the only applications they need are the ones you write.
All these people here are say
o “I’ve never needed templates”
o “Why would you use C++ in a video game?”
o “25% speed differences don’t matter”
o “If you need to do that, then your design is broken”
Why do you all assume that you are so enlightened about all areas of software development that you can completely understand all the requirements for every piece of software, and immediately know that none of them would benefit from the above features?
Templates are useful because they are fairly full featured implementation of compile-time generics.
You can implement pretty much everything that templates give you with polymorphism instead. But it’s less efficient.
You can avoid generics all together and just write the same code multiple times, in C. But it’s a waste of time.
Templates are a massive gain for projects with very high performance requirements. If you’ve never needed them, then you’re may well be right – C++ isn’t a useful language for you. But don’t assume that just because your projects haven’t needed it, that it’s a non-issue.
Personal bias:
I used to be a C++ developer on a project that had some pretty heavy performance needs. It also had a lot of GUI needs, so a good combination of dynamic/static would have been ideal (ObjC++ probably would have been good), but they don’t really exist in a stable/supported form.
I’m now mostly a Java developer, because raw performance isn’t required, but good tools/vendor support is. Java certainly isn’t te best language around, but it’s good enough, and it has a great marketshare, which is important on a lot of projects.
If you really think performance in general method dispatching or gaining a 20% speed increase when sorting vectors is so important to your program maybe you should reconsider your design.
(Could you people make up your minds? First, I am told that the speed difference is in the algorithms – that having the whole app be slower is not a big problem. Then, when I point out that fast, generic algorithms are C++’s strong suit, suddenly they become unimportant.)
Anyway, the speed increase in sort is not the only reason to use C++; it is merely a convenient example of how hard it would be to achieve this level of performance *with* this level of genericity in C/Objective-C. You can have one or the other but not both. I think that you should reconsider your remarks.
All thes talks about templates and having a great sort function are interesting but they tends to hide the fact that you can’t, with C++, have collections of heterogeneous objects! Which is a trivial thing to do with Objective-C and Smalltalk.
One cannot have collections of objects that have no common superclasses? All one needs is a void pointer and an integer representing the type of the object. The integer is provided by the typeid operator, and once the ID has been found all that remains is to cast it to its real type. Voila!
Now would you mind telling me why it is so important that one be able to have collections of classes that have little to do with each other?
(well, not more than who invented the Internet (Al Gore))
Well, if throwing money at something qualifies as invention, then Bill Gates must make Einstein look like a blithering idiot. 😉
Yikes. Its 1990 all over again. We just need some Java programmers yelling at both sides for incorporating features that could be misused in the hands of a retarded yak.
LOL!!
Anyway, I think that templates are a boon to the C++ programmer, but I also think it’s a shame that they’re needed at all.
Heh, I liked the joke about the yaks better.
Unfortunately for C++ developers, aspects haven’t yet caught on as much as in the Java community
I spent a few minutes looking at the site and some of the links, but all I found was a lot of psychobabble. Could someone tell me what aspects are? And if you tell me that they “crosscut the software system” I may just bash my head against the wall in frustration.
C++ is not the only language to have templates. In fact, ADA 95 has exactly the same.
I never knew that. Well, I guess I learn something new everyday. Now if I could only learn two new things per day…
Though I see no point in posting here, since there are so stuborn C++/templates fanatics around here, I wanted to make a posting:
We refuse to accept stupid arguments. If you would improve your arguments, we would not be so stubborn.
ObjC is a real OO language, C++ is NOT. ObjC is a multipurpose programming lanugage with minimal efforts. It’s not specialized in speed (use assembler for that), or to confuse people (use C++ for that).
You make comments like this, and then you wonder why C++ programmers keep disagreeing with you…
Why some people says that they need a fast language like c++ to code videogames. Why do you need c++ in videogames?
Because C++ allows us to write fast code that is much easier to maintain than C.
Please do not tell me that you use c++ because you have object orientation and templates. C++ is a broken language: you spend too much time understanding the sintax than coding.
The next person that calls C++ a broken language without some qualification is going to get broken into tiny pieces.
Templates in my mind are a very broken thing: you lose a lot of memory.
*whallops Mario with a large trout*
… I also am sorry to understand that now developing=marketing.
I am sorry that people who have no understanding of the situation have decided to pass judgement on the rest of us.
Just use the fucking language you are most productive with! You like Objective C? No problem: USE IT! Like C++? Then USE IT. Like C? Then USE IT! The same goes for every other language that got invented.
It is quite pathetic… this debate. Just like the Mac vs. PC debates we normally have.
thank you rajan r…
that’s one of the most intelligent posts i’ve seen on this thread
Why thank you 🙂
Besides, I just got to wonder how an article (that is edging close to be called a flamebait) about GNUstep and Obj. C programming turned into a C++ vs. Obj C flame war….
i would venture to guess (at the risk of flamebaiting) that it would be a little bit of language envy from both sides
guess what folks…no programming language is perfect every single one is missing that killer feature or has a poor implementation of something you like…get over it…just use what works
stop flaming each other over what stupid programming language is the best
-bytes256
You may see an aspect as a set of ‘issues’ that appear in slightly different form in different part of your software system. If you can identify this aspect, you can find a generic solution for it, instead of having to solve every single issue.
I’m not an expert myself, but I hope I’ve been clear.
For those that are interested:
Aspects provide a way of further separating concerns in a complex architecture. Aspects provide a mechanism for “wrapping” a class or method with other code – an aspect. The problem with only having classes/inheritance/aggregation is that some types of behavior are forced to be spread throughout the system. Aspects provide a way of grouping these behaviors into a concrete representation that doesn’t interfere with the abstractions represented by classes.
Typically, aspects are perfect for representing things like policies, etc., although that will surely change as more people become familiar with them.
Here are some good examples of where aspects really shine:
1) Logging. Selectively attach logging behavior to methods and classes without cluttering the code with logging statements.
2) Design By Contract. Aspects make it trivial to run tests before/after/etc. code in a class is executed, making design by contract really usable.
3) Concurrency policy enforcement. When implementing a complex concurrency policy, code supporting that policy is typically spread throughout all participating classes. Aspects provide a very clean mechanism for implemting a concurrency policy without polluting the implementation of your class. This makes it trivial to modify the policy in one place, or even swap it out completely.
I hope that this makes sense. I have been trying to get people thinking about aspects for the past year or so. Unfortunately, I feel like I’m getting the same type of reaction as when I introduced people to object-oriented programming.
If you’d like to read some articles that are significantly clearer than this post, there was really good coverage of aspect-oriented programming in a recent issue of The Communications of the ACM (10/01), as well as Dr. Dobbs (8/02).
>MY HAMMER IS BETTER THAN YOURS
>stanley’s are shit…craftsman BABY!!!
>i don’t here carpenters talking that way…
Then you’re not around carpenters very much .
Here are one really nice exampel use of templates in c++
Imagine you need to make a class to handle complex numbers as part of a numeric library. You normaly handle a complex numbers as a pair of numbers. One part called the real part, and the other part called the imaginary part.
Now the big question you face are: What type do I use for the real and imaginary part of the complex number. One could use 32 bit int’s. That would be fast, but what if you alse need to handle large numbers? you could use 64 bit, but what if someone want to use floating points insted? The point is that there is no “right” choice so insted one make it a template argument and let the user deside which type they want for each complex number.
No imagine you ship your library to a customer who want to use 256 bit floating points for the real and imaginary part. Now they just write/buy a class to handle 256 bit nunbers and then they could use that class with your complex numbers class thus gaining the ability to handle 256 bit complex numbers.
An other fast example is that the string class in c++ use a templates argument to store a single char.
Now imagine you want to make a startrack simulator. To store a single char you need 64 bit(There are many languages outthere in the galaxy) so to have a usefull string class you just need a type which can store 64bit. This is buildin to c++ (called long long) so now you just do a:
basic_string<long long>MyString;
and you got a string which can handle 64 bit chars. And if you find an other universe and thus need 128 bit chars you just need use
basic_string<long long long>MyBigString
not a lot of work.
But the best thing is that there is no slowdown when using templates, so using basic_string<long long> is just as fast as if you made your own very own special class to handle strings with 64 bit chars.
——— And just an note to the sucess of C++ —-
I think that the real reason to the sucess of c++ is that is it based on C and thus that people can/could keep using their old code/library while learning this new language. It is worth noting that the biggest problems with c++ also come from the fact that it need to support C, including the infamous void pointer.
(And it is posible to make containers in c++ which can store pointers to any type of data simultaniously widtout using inherence, but why one would want that is a question I can’t answer)
Martin Tilsted
OK, I think I understand AOP now. Thanks for the information!
rajan r >> “Besides, I just got to wonder how an article (that is edging close to be called a flamebait) about GNUstep and Obj. C programming turned into a C++ vs. Obj C flame war….”
That’s an easy one — just read the headline and you know why this happend. It’s a pattern – a minority claims superiority and the majority strikes back.
The battle between Objective-C and C++ rages on. And C is still in wide use, for kernel code, simple tasks that don’t require object orientation, teaching, and Gnome, among others. But why are people still using any variation of the language to begin with?
Since C was first released, many evolutions in computer programming have been made. Computers have gotten faster, making scripting languages a feasible choice for many low-power applications. Higher-level programming languages have been invented, some part of the OO school (Java, Python, Smalltalk), and functional languages like Lisp/Scheme and Haskell were created – and for some tasks, CAML is faster than C.
Now, there’s almost no program that is better done in C/C++/Objective-C than some other language. Things on the low end of the power spectrum can use Python or Haskell; things on the super-high-end, depending on the situation, can either use a similar high-level language, Forth, or assembler. All that’s left is the middle – powerful apps, especially games, on home computers. With the advent of new graphics-card languages, it might soon be possible to create a game 95% in the graphics-card-language, and the other 5% in Python, and not lose any performance. And C, in all its forms, will finally be dead. *Good.*
But why are people still using any variation of the language to begin with?
People use the language because they find it useful. C had a very good syntax (unlike Pascal which is absolutely horrible), and C supported low level programming. C++ extended these capabilities to deal with more modern (read: larger) programs and even added some things to deal with performance.
It is unfortunate that all the new must-have languages seem to be written by OOP purists who care little about performance. While I like OOP and use it myself, it is not the be-all and end-all of programming paradigms. The problem is that overuse of the inheritance model tends to tie derived classes and base classes’ behavior too closely together.
It is also unfortunate that many people do not see the usefulness of generic programming. I think that generic programming is a much more useful paradigm because it allows code to be very loosely coupled. For example, the interface of a function template is basically defined by how it takes its parameters, what it returns, and what operations the function definition consists of, as opposed to other paradigms where functions require the objects being operated upon to supporting some predefined message format or to be derived from a certain class.
Regardless of how we feel about each paradigm, no paradigm is perfect for every task. That is why languages like Objective-C and C++ support more than one paradigm.
The only reason C continues to exist is personal preference and the lack of C++ compilers on some platforms.
Now, there’s almost no program that is better done in C/C++/Objective-C than some other language.
I wish people would avoid making such ridiculous comments.
With the advent of new graphics-card languages, it might soon be possible to create a game 95% in the graphics-card-language, and the other 5% in Python, and not lose any performance. And C, in all its forms, will finally be dead. *Good.*
You must be kidding. First, the graphics card languages are C clones. Second, all they do is 3D stuff like shader routines. Expecting to be able to create a game 95% in the graphics card language is kind of like expecting to be able to build a bridge from the US to Cuba using popsticle sticks and chewing gum.
Expecting to be able to create a game 95% in the graphics card language is kind of like expecting to be able to build a bridge from the US to Cuba using popsticle sticks and chewing gum.
See that’s just silly.
It’s obvious you’ll need 5% macaroni.
Aspects arecommonly referred to as “Policy based class design” in C++ and are usually implemented using … TEMPLATES. See Alexandrescus most brilliant “Modern C++ Design”, it shows without mercy why C++ is such a brilliant language. You know something is cool when fulfills the requirements 100%. But you hit something great when all intended things are possible + a whole bunch more.
I am a professional developer and believe me: No other language holds a candle to C++ when it comes to the real thing.
From what I can see of the Quake 1 source, it’s written in pure C and ASM, and since it compiles with MS VC++ 5/6, I believe that should also clarify that it doesn’t used Objective-C (since MS VC++ doesn’t have an Objective-C compiler).
“Please try to take an position of objectivity when evaluating a new technology (or old, as in this case). Take the time to read some information about it, and attempt to put it into a larger context.”
Maybe you should listen to your own words, the rest of your comment was an unobjective piece of crap.
Can’t wait, should be able to have the best of most worlds then!
http://www.gamers.org/dEngine/quake/QuakeEd/source.html
John Carmack’s quake editor, written in objective C.