Linked by David Adams on Sat 11th Oct 2008 16:48 UTC, submitted by IndigoJo
Thread beginning with comment 333491
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[6]: Before you get rid of C++ ....
by werpu on Mon 13th Oct 2008 19:02
in reply to "RE[5]: Before you get rid of C++ ...."
[q]Well there are two different design principles. Objective-C followed the keep it simple principle while C++ followed the, lets take every feature there is on earth and press it into the language approach.
Objective-C may be simpler then C++, but it is also way more limited then C++. For example it is impossible to write a efficient vector class in Objective-C. In C++ you would to something like:
public class Vector
{
public:
Vector(double x, double y, double z);
Vector operator+(Vector v);
double operator*(Vector v);
...
}
In Objective-C it is just not possible to write light-wight classes. Every method invocation is a hashtable lookup. You can of course use C-structs but in my opinion this is also suboptimal.
Problem with this comparison is, to enable inheritance and polymorphism C++ translates every call into a virtual method table lookup....
Which is exactly the same a lookup map for methods!
Depending on the compiler you might get efficient code, but you cannot rely on it.
RE[7]: Before you get rid of C++ ....
by setec_astronomy on Tue 14th Oct 2008 10:04
in reply to "RE[6]: Before you get rid of C++ ...."
Problem with this comparison is, to enable inheritance and polymorphism C++ translates every call into a virtual method table lookup....
Which is exactly the same a lookup map for methods!
Depending on the compiler you might get efficient code, but you cannot rely on it.
This is incorrect (or at least a little bit misleading, depends on what you mean by "inheritance and polymorphism", emphasis mine). The virtual function table is only created for functions, that are declared virtual. Other, non-virtual class member functions are resolved statically [1], e.g. at compile time, so (apart from the - nowadays compareably small - abstraction penalties) there should be no loss of performance when calling non-virtual class member functions compared to procedural functions. There are situations, where the lookup process and/or the table introduce unacceptable overheads (esp. in numerical sensitive / scientific code, cf. [2] for a very good introduction to this problem set + examples how to avoid it ).
While the virtual function lookup is indeed the "default" way to introduce polymorphism to C++ class hirachies, there are first-class-citizen alternatives
available for situations where other approaches are more appropiate (static polymorphism via template engines, static polymorphism via Barton-and-Nackman type template voodoo, carefully designed class hirachies with helper-classes, etc.)
[1] http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20...
[2] http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01...





Member since:
2006-02-04
Objective-C may be simpler then C++, but it is also way more limited then C++. For example it is impossible to write a efficient vector class in Objective-C. In C++ you would to something like:
public class Vector
{
public:
Vector(double x, double y, double z);
Vector operator+(Vector v);
double operator*(Vector v);
...
}
In Objective-C it is just not possible to write light-wight classes. Every method invocation is a hashtable lookup. You can of course use C-structs but in my opinion this is also suboptimal.
Objective-C also does not offer operator overloading and templates which are quite useful for numeric stuff, just think about matrix multiplication.
In my opinion the scope of Objective-C is much more limited then C++, but for some things it might be the better language.