Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Bizarre code

Bizarre code

Scheduled Pinned Locked Moved The Lounge
30 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R realJSOP

    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

    B Offline
    B Offline
    Bamaco2
    wrote on last edited by
    #5

    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!

    1 Reply Last reply
    0
    • R realJSOP

      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

      B Offline
      B Offline
      bevpet
      wrote on last edited by
      #6

      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:

      J S 2 Replies Last reply
      0
      • R realJSOP

        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

        J Offline
        J Offline
        JWood
        wrote on last edited by
        #7

        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.

        J R 2 Replies Last reply
        0
        • R realJSOP

          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

          P Offline
          P Offline
          peterchen
          wrote on last edited by
          #8

          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

          1 Reply Last reply
          0
          • R realJSOP

            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

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #9

            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.

            D 1 Reply Last reply
            0
            • B bevpet

              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:

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #10

              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.

              1 Reply Last reply
              0
              • J JWood

                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.

                J Offline
                J Offline
                Jorgen Sigvardsson
                wrote on last edited by
                #11

                Why is it that you react with emotions to code like this? :) -- An eye for an eye will only make the world blind.

                J 1 Reply Last reply
                0
                • J Jorgen Sigvardsson

                  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.

                  D Offline
                  D Offline
                  DavidNohejl
                  wrote on last edited by
                  #12

                  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

                  J 1 Reply Last reply
                  0
                  • D DavidNohejl

                    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

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #13

                    Or 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.

                    1 Reply Last reply
                    0
                    • R Richard Stringer

                      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

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #14

                      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++

                      D M 2 Replies Last reply
                      0
                      • C Christian Graus

                        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++

                        D Offline
                        D Offline
                        Daniel Turini
                        wrote on last edited by
                        #15

                        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!

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          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++

                          M Offline
                          M Offline
                          Member 96
                          wrote on last edited by
                          #16

                          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

                          C 1 Reply Last reply
                          0
                          • R realJSOP

                            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

                            E Offline
                            E Offline
                            El Corazon
                            wrote on last edited by
                            #17

                            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)

                            1 Reply Last reply
                            0
                            • J Jorgen Sigvardsson

                              Why is it that you react with emotions to code like this? :) -- An eye for an eye will only make the world blind.

                              J Offline
                              J Offline
                              JWood
                              wrote on last edited by
                              #18

                              Why do Swedes spit chicken bones? Have I inadvertantly offended you? ;P

                              J 1 Reply Last reply
                              0
                              • J JWood

                                Why do Swedes spit chicken bones? Have I inadvertantly offended you? ;P

                                J Offline
                                J Offline
                                Jorgen Sigvardsson
                                wrote on last edited by
                                #19

                                I'm not the offended one ;P -- An eye for an eye will only make the world blind.

                                1 Reply Last reply
                                0
                                • J JWood

                                  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.

                                  R Offline
                                  R Offline
                                  realJSOP
                                  wrote on last edited by
                                  #20

                                  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

                                  1 Reply Last reply
                                  0
                                  • R Richard Stringer

                                    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

                                    R Offline
                                    R Offline
                                    realJSOP
                                    wrote on last edited by
                                    #21

                                    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

                                    R 1 Reply Last reply
                                    0
                                    • R realJSOP

                                      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

                                      N Offline
                                      N Offline
                                      Nemanja Trifunovic
                                      wrote on last edited by
                                      #22

                                      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.

                                      N 1 Reply Last reply
                                      0
                                      • R realJSOP

                                        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

                                        A Offline
                                        A Offline
                                        Anna Jayne Metcalfe
                                        wrote on last edited by
                                        #23

                                        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.

                                        1 Reply Last reply
                                        0
                                        • R realJSOP

                                          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

                                          R Offline
                                          R Offline
                                          Richard Stringer
                                          wrote on last edited by
                                          #24

                                          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

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups