Linus Torvalds and C++

Started by
149 comments, last by Anon Mike 16 years, 4 months ago
Quote:Original post by ukdeveloper
As for Torvalds' views, I hardly think his views of C++ are valid given the appalling nature of some of the C code that got posted earlier in the thread. Anyone using goto ought to be pointed to and laughed at, then damned to Hell. If you're using that, then you've most likely got some kind of design flaw. That's advice I picked up from GDNet itself, by the way, and because of that I have never once used it in any serious projects.

If something was completely useless they would have removed it from the language, it's not so much as goto is a horrible disease that plagues whatever touches it, as much as it's goto is very easily misused. If you think there's unnecessary goto's in some of his code, refactor it to get rid of the goto, test it, then submit it as a patch.

I agree with the best programmer is the one who gets things done, I generally use the best offerings for whatever task I have at hand, and the ones that are finished are usually much better than ones that don't work.
Advertisement
Quote:Original post by ukdeveloper
His views on Boost and the STL don't hold any water with me; my understanding is that the whole point is that those make things easier as they're tried and tested by a group of the brightest users of the language and it's all standardised, whereas in C you'd have to reinvent the wheel and end up with some horrible hacked mess due to the general primitive nature of most of the C language. You could store your home-rolled code for later, but you'd likely have to adapt it sometimes and evolve it for different situations. I've never used Boost but I've seen it to have some nice features, and the STL is just plain convenience right there.

Actually, things like that get aggregated into libraries in C too. For example, Glib contains data structures such as linked lists, dynamic arrays and hash tables as well as covering many of the same areas that boost such as threading and command line processing. Seriously, one lesson from this thread should at least be "don't bash a language unless you know it well enough to make meaningful statements". You obviously don't know C well enough to be bashing it.
Quote:Original post by Talroth
Quote:Original post by owl
Quote:Original post by Spoonbender
He might be a successful programmer, but not necessarily a competent one.


Are you stating as a fact that Linus Trovalds carried out all his sucessful projects based on incompetence?

Amazing.


You sir, need to watch more Inspector Gadget!


Inspector Gadget is the personification of C++
Quote:Original post by eedok
If something was completely useless they would have removed it from the language,

Legacy code support. If it wasn't for this, then goto would have been removed a long time ago. They just didn't want to break backwards compatibility.

Quote:
it's not so much as goto is a horrible disease that plagues whatever touches it, as much as it's goto is very easily misused.

Oh, give me a break. In 99% of all cases, using goto is a sign of incompetence. Just because Torvald does it will suddendly make it less evil ? I don't think so. Especially if it is so blatantly abused as in his code - see below:

Quote:
If you think there's unnecessary goto's in some of his code, refactor it to get rid of the goto, test it, then submit it as a patch.

The first instance of goto in the piece of code I linked to earlier:
void release_task(struct task_struct * p) 136 { 137         struct task_struct *leader; 138         int zap_leader; 139 repeat: 140         atomic_dec(&p->user->processes);     [... blabla ...] 173         p = leader; 174         if (unlikely(zap_leader)) 175                 goto repeat; 176 }

If *that* is not one of the most blatant abuses of goto I have ever seen, then I don't know what is. Now that's going to be really hard to remove... There's 10 other gotos that follow, only in this single source file.

Quote:
I agree with the best programmer is the one who gets things done, I generally use the best offerings for whatever task I have at hand, and the ones that are finished are usually much better than ones that don't work.

Yeah, and the ones that are completely unmaintainable. Or the ones that you have to restart from scratch, just because your customer wants a tiny little modification, and rewriting the whole thing suddendly is less expensive than having someone shift through the chaos source.

I find it funny how many people, when talking to newbies, always preach about good coding practices, evil gotos, and how great features such as reflection, native lambda functions, and all the other stuff C++ doesn't have can be. But suddendly all that is relativated and forgotten, just because some well known guy with a superiority complex spits out code that would be classified as an abomination, was it written by anybody else.

Bah.
Actually, I should really publically submit a patch removing the gotos from that source file. I'd label the patch "corrected programmer incompetence - removed gotos", and submit it to the kernel dev mailing list...

Of course, it would never be accepted into the source tree. But it would be funny to see their reaction :) I would probably be bashed into the earth by an army of Linus supporters within seconds [wink]
Quote:Original post by Yann L
Quote:Original post by eedok
If something was completely useless they would have removed it from the language,

Legacy code support. If it wasn't for this, then goto would have been removed a long time ago. They just didn't want to break backwards compatibility.

Quote:
it's not so much as goto is a horrible disease that plagues whatever touches it, as much as it's goto is very easily misused.

Oh, give me a break. In 99% of all cases, using goto is a sign of incompetence. Just because Torvald does it will suddendly make it less evil ? I don't think so. Especially if it is so blatantly abused as in his code - see below:

Quote:
If you think there's unnecessary goto's in some of his code, refactor it to get rid of the goto, test it, then submit it as a patch.

The first instance of goto in the piece of code I linked to earlier:
*** Source Snippet Removed ***
If *that* is not one of the most blatant abuses of goto I have ever seen, then I don't know what is. Now that's going to be really hard to remove... There's 10 other gotos that follow, only in this single source file.

That was the only abuse I could see (could replace it with a do-while loop, which would be about the same). The rest of the goto uses are common practices in kernel code in the name of keeping code size down, decreasing cache footprint, error/stack unwinding, etc.; I'm unfortunately unqualified to judge their worth. However, you'll find the same uses in other kernels' code, such as Solaris (/usr/src/uts in their CVS tree, if you're interested in seeing for yourself.)

And no, it isn't because Torvalds said it, nor because I'm a fan (I most certainly am not, in particular of his brusque approach in presentations), but is the same answer which has come up a few times in discussions about goto before on this site.
Quote:Original post by Yann L
Quote:Original post by eedok
If something was completely useless they would have removed it from the language,

Legacy code support. If it wasn't for this, then goto would have been removed a long time ago. They just didn't want to break backwards compatibility.


Not really. In C, and other languages where SESE is a valid technique, goto can actually be used to make things like error handling and resource cleanup more readable than equivalent non-goto code. It helps if you remember that C and C++ are different languages, and techniques that are valid and indeed idiomatic in one can be reprehensible in the other.
Quote:Original post by SiCrane
Let's put it another way: I consider myself to be an expert C++ programmer. The thing is, I need to be an expert C++ programmer in order to write relatively bug-free code. I've been using the language for something like 15 years, and I still have WTF moments when my code behaves in a manner completely different than I intended. I'm probably only a decent Python, Visual Basic and C# programmer, but I don't need to be any better than that to get my programs to do what I want in those languages.

I too consider myself to be an expert C++ programmer, having also used it for over 15 years now, and completely agree. It is nearly impossible to write a non-trivial bug free C++ program, even as an expert. While you're less likely to make the trivial bugs, the ones you do embed into your applications tend to be ones dues to the complexity of the language. There are just too many gotchas that catch you in dark alleys, beat you up, and take away your money.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Quote:Original post by crusadingknight
That was the only abuse I could see (could replace it with a do-while loop, which would be about the same). The rest of the goto uses are common practices in kernel code in the name of keeping code size down, decreasing cache footprint, error/stack unwinding, etc.;

Ah, the "but but but - it's kernel code" excuse [wink]

Of course this doesn't hold up. As I said before, kernel code is nothing special - it's just code. Sure, you have to be careful about a few specific things, but this is just as valid for device drivers and the like. Any advantage of using gotos over cleaner alternatives would be absolutely minimal in almost all cases (and even counterproductive). We're not working on the 6502 anymore, where every single byte counted. The kernel I'm currently running is about 1.6MB, compressed. I've written entire 3D engines that were smaller than that (in C++ :). And about using gotos for performance - now that would probably be the textbook example of completely futile micro-optimization with exactly zero benefit.

Torvalds is just using gotos for convenience, because it's his (very bad) coding style. Nothing more.
Quote:Original post by Yann L
Quote:Original post by crusadingknight
That was the only abuse I could see (could replace it with a do-while loop, which would be about the same). The rest of the goto uses are common practices in kernel code in the name of keeping code size down, decreasing cache footprint, error/stack unwinding, etc.;

Ah, the "but but but - it's kernel code" excuse [wink]

Of course this doesn't hold up. As I said before, kernel code is nothing special - it's just code. Sure, you have to be careful about a few specific things, but this is just as valid for device drivers and the like. Any advantage of using gotos over cleaner alternatives would be absolutely minimal in almost all cases (and even counterproductive). We're not working on the 6502 anymore, where every single byte counted. The kernel I'm currently running is about 1.6MB, compressed. I've written entire 3D engines that were smaller than that (in C++ :). And about using gotos for performance - now that would probably be the textbook example of completely futile micro-optimization with exactly zero benefit.

Torvalds is just using gotos for convenience, because it's his (very bad) coding style. Nothing more.


Singularity, a MS Research project is an OS written almost entirely in C#, except for an assembly binding layer. There's no C in it at all. So, pretty cool stuff are coming out of managed worlds even in the low level areas. I also agree with you about the gotos. I've never encountered a situation that required a goto for performance reasons that couldn't be refactored into a simpler model with equivelent performance metrics as the "goto" version.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement