Click here to Skip to main content
15,902,189 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: goto statement Pin
vl211-Nov-13 8:01
vl211-Nov-13 8:01 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 1:15
Stefan_Lang12-Nov-13 1:15 
GeneralRe: goto statement Pin
vl212-Nov-13 1:30
vl212-Nov-13 1:30 
GeneralRe: goto statement Pin
werinus12-Nov-13 1:34
werinus12-Nov-13 1:34 
GeneralRe: goto statement Pin
vl212-Nov-13 1:45
vl212-Nov-13 1:45 
GeneralRe: goto statement Pin
werinus12-Nov-13 2:36
werinus12-Nov-13 2:36 
GeneralRe: goto statement Pin
jschell12-Nov-13 9:44
jschell12-Nov-13 9:44 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:04
Bill_Hallahan12-Nov-13 13:04 
Look, I disagree with the absolutist position too, but I agree that using goto's is generally bad. I just acknowledge there might be exceptions.

But, having worked on code with gotos, which I did not write, but I had to maintain it, and having worked on object-oriented code, in my experience the code with gotos had both many more bugs and also worse bugs. I've had this same experience in more than one job too, so I see that as a recurring pattern.

And, I've also seen object-oriented code that was faster than the older C code. Efficiency has to do with many other factors than the language used.

If only encapsulation is used in C++, there is no calling penalty and the generated code is essentially C code.

And, 'often' the overhead of calling virtual functions is typically less than using a 'switch' statements, so if the setting that is being tested is in a loop, doing the switch statement outside of the loop and choosing an object with a virtual function based on the switch results can be much faster.

In C, you can do that same thing with function pointers, but it's more complicated, and people don't typically write code that way in C. In C++. it's very simple to do that, plus, there are other benefits.

Here's another issue about performance unrelated to the language used:

I once unrolled a loop for a floating point routine and the code got significantly faster. I did the same thing for a routine that did the same calculations, but was for a different processor. That routine used integer arithmetic. When I unrolled the loop, the routine got much slower! The integer routine required shifting the products down after every multiplication. These extra shift instructions made the code grow to over 4Kbytes, and 4Kbytes is the size of the instruction cache. The code was cache-thrashing.

I've seen the pattern of people imagining their code was faster than some other implementation, when a profiler later showed that the other implementation was actually faster. Modern systems do multiple levels of caching for both instructions and data, do branch prediction, and even do instruction reordering based on both the instruction types and register pressure. Predicting how fast code will run is more complicated today than it ever was. Without using a profiler, it's usually just guesswork.

Finally, languages are tools. Use the right tool for the job. If you think object-oriented languages are slow and buggy, then you definitely don't understand them.

Also, performance is not always the most important attribute of code. If the code takes 10 microseconds instead of 5 microseconds, and the requirement is that the code runs in 1 millisecond, then I would rather the simpler, easier to maintain, implementation, and that is typically (as in almost always) the code written in C++. C is more portable than C++, so C has that going for it, although if one restricts the features they use in C++, it's probably as portable as C.

But, when you suggest that object-oriented languages are inherently more buggy than C, well, that flies in the face of both research and experience. Well-written C++ hides the data, and that definitely tends to make code less buggy, not more.
GeneralRe: goto statement Pin
jschell13-Nov-13 9:30
jschell13-Nov-13 9:30 
GeneralRe: goto statement Pin
Bill_Hallahan13-Nov-13 17:23
Bill_Hallahan13-Nov-13 17:23 
GeneralRe: goto statement Pin
jschell14-Nov-13 7:50
jschell14-Nov-13 7:50 
GeneralRe: goto statement Pin
Bill_Hallahan14-Nov-13 14:02
Bill_Hallahan14-Nov-13 14:02 
GeneralRe: goto statement Pin
jschell12-Nov-13 9:46
jschell12-Nov-13 9:46 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:25
Bill_Hallahan12-Nov-13 13:25 
GeneralRe: goto statement Pin
jschell13-Nov-13 9:49
jschell13-Nov-13 9:49 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 20:50
Stefan_Lang12-Nov-13 20:50 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 12:32
Bill_Hallahan12-Nov-13 12:32 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 21:34
Stefan_Lang12-Nov-13 21:34 
GeneralRe: goto statement Pin
Bill_Hallahan13-Nov-13 7:16
Bill_Hallahan13-Nov-13 7:16 
GeneralRe: goto statement Pin
_Maxxx_10-Nov-13 14:35
professional_Maxxx_10-Nov-13 14:35 
GeneralRe: goto statement Pin
Tarek Elqusi10-Nov-13 18:46
professionalTarek Elqusi10-Nov-13 18:46 
GeneralRe: goto statement Pin
Mark_Wallace10-Nov-13 20:47
Mark_Wallace10-Nov-13 20:47 
GeneralRe: goto statement Pin
Mark H210-Nov-13 21:56
Mark H210-Nov-13 21:56 
GeneralRe: goto statement Pin
Stefan_Lang10-Nov-13 23:24
Stefan_Lang10-Nov-13 23:24 
GeneralRe: goto statement Pin
vl211-Nov-13 7:49
vl211-Nov-13 7:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.