Re: C++ more efficient than C?
On 8 Apr., 19:20, Kelsey Bjarnason <kbjarna...@gmail.com> wrote:
On Sun, 06 Apr 2008 12:59:26 +0300, Juha Nieminen wrote:
bc1...@googlemail.com wrote:
Assuming two programmers of equal skill, on the whole the one writing
in C will write far nicer code than the one in C++ (nicer in terms of
ease of readibility, maintainability, and lack of bugs). And he will
write it quicker.
Here we have a perfect example of the C-hacker syndrome.
I bet you are a big fan of Linus Torvalds. (Heck, you may even *be*
Linus Torvalds. Exactly the same type of trolling.)
I happen to like both C and C++, but there _are_ cases where C++ makes
things a little less clear than they could be. As a trivial example:
int x = 3, y;
y = func(x);
Quick: what's the value of x?
In C the answer's easy: the value is 3. In C++, there is absolutely no
way to know, at the point of calling, what will happen to the variable.
This makes the same code, in C, somewhat easier to read, as the
indicators of whether the value will be modified or not are right there,
in your face - or not.
Right. But this is only true in such trivial cases as the above where
you allow such an absurd name. Replace the name with some reasonable
one, such as square or fibonacci, and no one will be in doubt. I have
heard others complain like you, but never found statements such as the
above to be a real problem.
A much larger problem has been in absurd declaration such as the
above. Are you quite sure that it should read int x = 3; int y; (as
you imply) and not int x = (3,y); ? ;-)
In C++, there's no indication whatsoever, meaning
you have to hunt for the called function, check its interface, realize
that yes, it modifies the value and add this to the growing list of
pointless things to remember which shouldn't need remembering.
If you need to look at the code, you should know what func does
anyway!
/Peter