Bizarre code
-
Yeah I know - I've been doing C++ for over 15 years, and I've never seen it used before - ever. In fact, that's probably more rare than the use of "goto" (evil code if ever there was some). I would say this line of code is pretty bad form. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
I have been avoiding goto in the past, but ever since I have started programming low-level firmware on embedded systems, I have learned the value to make my code leaner, simpler to read, and smaller. Don't get me wrong! I have a C++ project with a total of 781 use of the "for" keyword, but only 88 gotos. (Mostly on error handling situations) Of on my (much bigger) PC project, I have found 2127 "for" loops and 53 "goto" Mostly for "error handling'. (don't confuse "error handling" with "exception handling", in my mind, it's two different things). I often have some code checking 100,000 different things, validating and making sure that all conditions are met before doing something, eventually doing it or displaying a normalized error message and taking some actions. Goto come in handy on those simple "event handler" type of functions, where noting much is done except for validation, presentation of error and invocation of method that actually does the work. (Ok, maybe I prepare a bunch of parameters too) Don't get me going about the goto!
-
The following line of code actually exists in one of our formview classes (maybe more than one of our classes for all I know)...
m_pPropertySheet->~CMyPropertySheet();
I passed an entire can of soda through my nose when I saw this. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
The following line of code actually exists in one of our formview classes (maybe more than one of our classes for all I know)...
m_pPropertySheet->~CMyPropertySheet();
I passed an entire can of soda through my nose when I saw this. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
Yeah I know - I've been doing C++ for over 15 years, and I've never seen it used before - ever. In fact, that's probably more rare than the use of "goto" (evil code if ever there was some). I would say this line of code is pretty bad form. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
I've used it once 'cause I couldn't figure out the syntax for a placement delete (It was a homegrown array class, back when stl was just yatl, using "allocate raw storage, and construct/destruct in place on demand")
Pandoras Gift #44: Hope. The one that keeps you on suffering.
aber.. "Wie gesagt, der Scheiss is' Therapie"
boost your code || Fold With Us! || sighist | doxygen -
Yeah I know - I've been doing C++ for over 15 years, and I've never seen it used before - ever. In fact, that's probably more rare than the use of "goto" (evil code if ever there was some). I would say this line of code is pretty bad form. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Eventhough it's a huge howitzer aimed straight at your foot, it's a valuable tool which makes certain situations less ugly than if you hadn't used it. It's not as rare as you think, as most (if not all?) STL implementations use this trick for pre-allocations. But yeah, it's not the most common C++ construct. -- An eye for an eye will only make the world blind.
-
i'll swap you your m_pPropertySheet->~CMyPropertySheet(); for my :doh::doh: monther-in-law :doh: and day of the week :wtf: bring on your goto's also :wtf: no code is as bad as :omg::wtf: "the mother-in-law" :wtf::omg:
mother-in-law? code? You should've known better than to marry a robot. ;P -- An eye for an eye will only make the world blind.
-
Yeh I hate stuff like that. Some people don't understand there are certain rules of decorum when programming - In a dinner time analogy This is like spitting chicken bones into the centerpiece.
Why is it that you react with emotions to code like this? :) -- An eye for an eye will only make the world blind.
-
Eventhough it's a huge howitzer aimed straight at your foot, it's a valuable tool which makes certain situations less ugly than if you hadn't used it. It's not as rare as you think, as most (if not all?) STL implementations use this trick for pre-allocations. But yeah, it's not the most common C++ construct. -- An eye for an eye will only make the world blind.
Dirty tricks are ok... when they are commented! just my 2 cents David Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
Dirty tricks are ok... when they are commented! just my 2 cents David Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidyOr well programmed. For instance, the technique STL uses for pre-allocating arrays of objects, should not need much explaining. At least not for C++ programmers. But yeah, if there's a real dirty trick involved, proper comments should be made, as well as documented somewhere else outside the code. But the best solution to avoid dirty tricks is to redesign/refactor. Unfortunately, that's not always possible. :| (Been there, done that! I've even binary patched faulty DLLs to which I did not have the source code. :sigh:) -- An eye for an eye will only make the world blind.
-
John Simmons / outlaw programmer wrote: more rare than the use of "goto" (evil code if ever there was some). There are good reasons for leaving the GOTO keyword in any all purpose language. I'll leave "why" as an exercise for the reader but check out "throw" and "catch". Richard In a world of pollution, profanity, adolescence, zits, broccoli, racism, ozone depletion, sexism, stupid guys, and PMS, why the hell do people still tell me to have a nice day? --Unknown
I'm still waiting for an example where goto is actually a 'good' solution, as opposed to a possible one. Christian Graus - Microsoft MVP - C++
-
I'm still waiting for an example where goto is actually a 'good' solution, as opposed to a possible one. Christian Graus - Microsoft MVP - C++
Christian Graus wrote: I'm still waiting for an example where goto is actually a 'good' solution, as opposed to a possible one. Goto is the fastest implementation for a FSA, when you can create the FSA at compile time. The alternative are arrays that keep state information, but you're only emulating gotos, and gotos are much more clear to read than a huge state table - try to debug a wrong state table and you'll understand what I mean. Gotos can be up to 10x faster on machines with branch prediction and speculative execution when compared to arrays. Also, redundant states do not need to be optimized by the FSA generator, as the compiler will take care of it. I see dead pixels Yes, even I am blogging now!
-
I'm still waiting for an example where goto is actually a 'good' solution, as opposed to a possible one. Christian Graus - Microsoft MVP - C++
Really? That's surprising, I thought you were a working programmer not a hobbyist? I'll admit it's rare, but I can't think of any major commercial application of consequence I've worked on that didn't have at least one area with a goto in it (both in c++ and now c#) that was better done any other way. (sure I could have invented a convoluted way to avoid it but why bother? It's a tool there to be used in the right circumstances.)
"In our civilization, and under our republican form of government, intelligence is so highly honored that it is rewarded by exemption from the cares of office." - Ambrose Bierce
-
The following line of code actually exists in one of our formview classes (maybe more than one of our classes for all I know)...
m_pPropertySheet->~CMyPropertySheet();
I passed an entire can of soda through my nose when I saw this. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
John Simmons / outlaw programmer wrote: I passed an entire can of soda through my nose when I saw this. at least you didn't write it.... I spent the week tracking down a bug only to find some of the poorest code I have ever written. Words cannot describe how stupid I felt. I don't drink, don't smoke... all I can figure is I wrote it 8 months ago during a severe migrain or during a 24hour coding nightmare.... I finished fixing it today, but I am not very happy with myself. _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
Why is it that you react with emotions to code like this? :) -- An eye for an eye will only make the world blind.
-
I'm not the offended one ;P -- An eye for an eye will only make the world blind.
-
Yeh I hate stuff like that. Some people don't understand there are certain rules of decorum when programming - In a dinner time analogy This is like spitting chicken bones into the centerpiece.
Hell, *I've* done that! :) ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
John Simmons / outlaw programmer wrote: more rare than the use of "goto" (evil code if ever there was some). There are good reasons for leaving the GOTO keyword in any all purpose language. I'll leave "why" as an exercise for the reader but check out "throw" and "catch". Richard In a world of pollution, profanity, adolescence, zits, broccoli, racism, ozone depletion, sexism, stupid guys, and PMS, why the hell do people still tell me to have a nice day? --Unknown
Nope, I've never used a goto in C++ (although I have removed a few). There's never a "good reason" to use one. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
Yeah I know - I've been doing C++ for over 15 years, and I've never seen it used before - ever. In fact, that's probably more rare than the use of "goto" (evil code if ever there was some). I would say this line of code is pretty bad form. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
1. Explicitelly calling destructor is very common in cases of implementing reference-counting schemas. I have never implemented such a thing myself, but I have seen it many times. Nothing wrong about that. 2. goto is sometimes the cleanest technique to get out of a nested loop. You just got to be sure there are no allocations within these loops, or you may end up with a leak.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-
Yeah I know - I've been doing C++ for over 15 years, and I've never seen it used before - ever. In fact, that's probably more rare than the use of "goto" (evil code if ever there was some). I would say this line of code is pretty bad form. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
The only time I've seen a direct call to a destructor is in template framework code. I've not used a goto since I moved from Basic and Z-80 assembler to Pascal (and thence to C and C++). :) Anna :rose: Riverblade Ltd - Software Consultancy Services Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
Nope, I've never used a goto in C++ (although I have removed a few). There's never a "good reason" to use one. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
There is code that you dimply can't write without it. But I guess outlaws are special. There is absolutly nothing wrong , bad, or incorrect about a goto. Much more mayhem has been invoked in using memory allocation than with the use of goto. Urban legend stuff you know. Richard In a world of pollution, profanity, adolescence, zits, broccoli, racism, ozone depletion, sexism, stupid guys, and PMS, why the hell do people still tell me to have a nice day? --Unknown