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. From the Museum of Ugly Code

From the Museum of Ugly Code

Scheduled Pinned Locked Moved The Lounge
question
39 Posts 17 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 Offline
    R Offline
    raddevus
    wrote on last edited by
    #1

    When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

    for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
    // do something with the files in the folder.
    }

    First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

    while (!sourceSubFolders.atEnd()){
    // do something with files in the folder
    sourceSubFolders.moveNext();
    }

    EDIT This one is for all you people. You know who you are! :rolleyes:

    do {
    // do something with files in the folder
    sourceSubFolders.moveNext();
    }
    while (!sourceSubFolders.atEnd());

    1 D B S R 13 Replies Last reply
    0
    • R raddevus

      When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

      for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
      // do something with the files in the folder.
      }

      First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

      while (!sourceSubFolders.atEnd()){
      // do something with files in the folder
      sourceSubFolders.moveNext();
      }

      EDIT This one is for all you people. You know who you are! :rolleyes:

      do {
      // do something with files in the folder
      sourceSubFolders.moveNext();
      }
      while (!sourceSubFolders.atEnd());

      1 Offline
      1 Offline
      11917640 Member
      wrote on last edited by
      #2

      while (!sourceSubFolders.atEnd()){
      // do something with files in the folder and don't use "continue"
      sourceSubFolders.moveNext();
      }

      D 1 Reply Last reply
      0
      • R raddevus

        When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

        for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
        // do something with the files in the folder.
        }

        First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

        while (!sourceSubFolders.atEnd()){
        // do something with files in the folder
        sourceSubFolders.moveNext();
        }

        EDIT This one is for all you people. You know who you are! :rolleyes:

        do {
        // do something with files in the folder
        sourceSubFolders.moveNext();
        }
        while (!sourceSubFolders.atEnd());

        D Offline
        D Offline
        den2k88
        wrote on last edited by
        #3

        It is the smart(ass) approach. I am working on code that makes things like these pale.

        GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

        R 1 Reply Last reply
        0
        • D den2k88

          It is the smart(ass) approach. I am working on code that makes things like these pale.

          GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

          R Offline
          R Offline
          raddevus
          wrote on last edited by
          #4

          den2k88 wrote:

          I am working on code that makes things like these pale.

          I know. It's not that bad. It's just interesting when you see that empty statement in the for loop.

          C 1 Reply Last reply
          0
          • R raddevus

            When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

            for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
            // do something with the files in the folder.
            }

            First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

            while (!sourceSubFolders.atEnd()){
            // do something with files in the folder
            sourceSubFolders.moveNext();
            }

            EDIT This one is for all you people. You know who you are! :rolleyes:

            do {
            // do something with files in the folder
            sourceSubFolders.moveNext();
            }
            while (!sourceSubFolders.atEnd());

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

            The original dev likely thought they were doing cool and advanced stuff with the for statement. This kind of code works, but is the reason that I chose my signature line. ;)

            Just because the code works, it doesn't mean that it is good code.

            T 1 Reply Last reply
            0
            • R raddevus

              den2k88 wrote:

              I am working on code that makes things like these pale.

              I know. It's not that bad. It's just interesting when you see that empty statement in the for loop.

              C Offline
              C Offline
              charlieg
              wrote on last edited by
              #6

              I second the smart ass approach assessment. Someone is showing off his understanding of default loop behavior, coding bugs at a high rate of speed. I love this: "if (bVariable = someothervar) { do something }" despise assignments in conditionals and that was a simple example.

              Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

              R T D 3 Replies Last reply
              0
              • R raddevus

                When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

                for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
                // do something with the files in the folder.
                }

                First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

                while (!sourceSubFolders.atEnd()){
                // do something with files in the folder
                sourceSubFolders.moveNext();
                }

                EDIT This one is for all you people. You know who you are! :rolleyes:

                do {
                // do something with files in the folder
                sourceSubFolders.moveNext();
                }
                while (!sourceSubFolders.atEnd());

                S Offline
                S Offline
                Stryder_1
                wrote on last edited by
                #7

                In personal code, I begin my object variable names with obj. This allows all the objects I instantiate to be easily located with autocomplete. Plus when I am scanning through my code, its easily recognized as a variable I created. I usually do not do this in shared code as this is one of those things will annoy some developers.

                R T 2 Replies Last reply
                0
                • C charlieg

                  I second the smart ass approach assessment. Someone is showing off his understanding of default loop behavior, coding bugs at a high rate of speed. I love this: "if (bVariable = someothervar) { do something }" despise assignments in conditionals and that was a simple example.

                  Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #8

                  charlieg wrote:

                  if (bVariable = someothervar)

                  That's a very ugly one. I had to try it in JS. It works, always runs. C# at least gives you an error "cannot implicitly convert 'int' to 'bool'

                  B 1 Reply Last reply
                  0
                  • S Stryder_1

                    In personal code, I begin my object variable names with obj. This allows all the objects I instantiate to be easily located with autocomplete. Plus when I am scanning through my code, its easily recognized as a variable I created. I usually do not do this in shared code as this is one of those things will annoy some developers.

                    R Offline
                    R Offline
                    raddevus
                    wrote on last edited by
                    #9

                    Stryder_1 wrote:

                    when I am scanning through my code, its easily recognized as a variable I created

                    Yeah, I used Hungarian notation in the early days of C++ and no intellisense, etc. It's just that I'm not sure the obj prefix helped in this case (example I provided) because almost everything in that code was an object.

                    1 Reply Last reply
                    0
                    • R raddevus

                      When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

                      for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
                      // do something with the files in the folder.
                      }

                      First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

                      while (!sourceSubFolders.atEnd()){
                      // do something with files in the folder
                      sourceSubFolders.moveNext();
                      }

                      EDIT This one is for all you people. You know who you are! :rolleyes:

                      do {
                      // do something with files in the folder
                      sourceSubFolders.moveNext();
                      }
                      while (!sourceSubFolders.atEnd());

                      R Offline
                      R Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      Is that from a language that hasn't discovered the foreach construct yet? :wtf:


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      1 Reply Last reply
                      0
                      • R raddevus

                        When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

                        for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
                        // do something with the files in the folder.
                        }

                        First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

                        while (!sourceSubFolders.atEnd()){
                        // do something with files in the folder
                        sourceSubFolders.moveNext();
                        }

                        EDIT This one is for all you people. You know who you are! :rolleyes:

                        do {
                        // do something with files in the folder
                        sourceSubFolders.moveNext();
                        }
                        while (!sourceSubFolders.atEnd());

                        T Offline
                        T Offline
                        TheGreatAndPowerfulOz
                        wrote on last edited by
                        #11

                        Yeah, I hate Hungarian notation, mostly because everyone, and I do mean everyone, missed the point. Hungarian notation was supposed to indicated the kind of thing it was, not it's type. That is it should say Customers, not objCustList nor objCustDict. Really, you don't need to tell me it's an int or number: nCount or iCount and you don't need to tell me it's an object or a list. :rolleyes: :rolleyes: :rolleyes: Named properly I can tell what a variable is. As for the looping, personally don't see the problem with either approach. Whatever floats your boat. It's equivalent code. I like the _for_ approach because I can immediately see what the loop dynamics are. The problem there is when, for some logical reason, you don't want to "_moveNext()_," in that case a _while_ statement may serve better.

                        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                        C 1 Reply Last reply
                        0
                        • B BillW33

                          The original dev likely thought they were doing cool and advanced stuff with the for statement. This kind of code works, but is the reason that I chose my signature line. ;)

                          Just because the code works, it doesn't mean that it is good code.

                          T Offline
                          T Offline
                          TheGreatAndPowerfulOz
                          wrote on last edited by
                          #12

                          To borrow from a common aphorism: One man's garbage code is another mans treasure. and here's another: Good code is in the eye of the beholder.

                          #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                          1 Reply Last reply
                          0
                          • S Stryder_1

                            In personal code, I begin my object variable names with obj. This allows all the objects I instantiate to be easily located with autocomplete. Plus when I am scanning through my code, its easily recognized as a variable I created. I usually do not do this in shared code as this is one of those things will annoy some developers.

                            T Offline
                            T Offline
                            TheGreatAndPowerfulOz
                            wrote on last edited by
                            #13

                            Why not prefix all your variable, function and class names with _stryder__? That way everyone would know! ;P :laugh:

                            #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                            1 Reply Last reply
                            0
                            • C charlieg

                              I second the smart ass approach assessment. Someone is showing off his understanding of default loop behavior, coding bugs at a high rate of speed. I love this: "if (bVariable = someothervar) { do something }" despise assignments in conditionals and that was a simple example.

                              Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                              T Offline
                              T Offline
                              TheGreatAndPowerfulOz
                              wrote on last edited by
                              #14

                              charlieg wrote:

                              "if (bVariable = someothervar)

                              I know it's kool and all and allows for compact code, but really this has been the source of so many EFFING bugs, this construct should be disallowed in any language. Curse the inventor of "C" for adding it the language.

                              #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                              1 Reply Last reply
                              0
                              • C charlieg

                                I second the smart ass approach assessment. Someone is showing off his understanding of default loop behavior, coding bugs at a high rate of speed. I love this: "if (bVariable = someothervar) { do something }" despise assignments in conditionals and that was a simple example.

                                Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                                D Offline
                                D Offline
                                den2k88
                                wrote on last edited by
                                #15

                                charlieg wrote:

                                despise assignments in conditionals and that was a simple example.

                                Yes yes yes. Also scoped variables are cool but... they still end up on the stack. There is really no need to use them, apart from making the code more difficult to read and to maintain. And: kids, always initialize your variables. If you are absolutely, positively sure that the variable in question will never be read before being written on and that the data written on it are always meaningful then at least state it in a comment.

                                GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

                                T 1 Reply Last reply
                                0
                                • D den2k88

                                  charlieg wrote:

                                  despise assignments in conditionals and that was a simple example.

                                  Yes yes yes. Also scoped variables are cool but... they still end up on the stack. There is really no need to use them, apart from making the code more difficult to read and to maintain. And: kids, always initialize your variables. If you are absolutely, positively sure that the variable in question will never be read before being written on and that the data written on it are always meaningful then at least state it in a comment.

                                  GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

                                  T Offline
                                  T Offline
                                  TheGreatAndPowerfulOz
                                  wrote on last edited by
                                  #16

                                  den2k88 wrote:

                                  scoped variables ... apart from making the code more difficult to read and to maintain.

                                  I actually find using scoped variables makes code easier to read and maintain. :-D YMMV. And it has fixed and avoided many a bug for me.

                                  den2k88 wrote:

                                  always initialize your variables

                                  Indeed. Yes!

                                  den2k88 wrote:

                                  absolutely, positively sure

                                  That works until it doesn't. See first rule: initialize!

                                  #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                  D 1 Reply Last reply
                                  0
                                  • T TheGreatAndPowerfulOz

                                    Yeah, I hate Hungarian notation, mostly because everyone, and I do mean everyone, missed the point. Hungarian notation was supposed to indicated the kind of thing it was, not it's type. That is it should say Customers, not objCustList nor objCustDict. Really, you don't need to tell me it's an int or number: nCount or iCount and you don't need to tell me it's an object or a list. :rolleyes: :rolleyes: :rolleyes: Named properly I can tell what a variable is. As for the looping, personally don't see the problem with either approach. Whatever floats your boat. It's equivalent code. I like the _for_ approach because I can immediately see what the loop dynamics are. The problem there is when, for some logical reason, you don't want to "_moveNext()_," in that case a _while_ statement may serve better.

                                    #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                    C Offline
                                    C Offline
                                    charlieg
                                    wrote on last edited by
                                    #17

                                    The only hungarian notation I really like is sticking a little "p" in front of a variable to indicate it's a pointer. Just makes it easier to understand what I am doing. Microsoft loves to go wonkers with it (UINT32, and yes I know that's a type), and I have seen some code (due to coding standards) look like pStrConst_Variablename.

                                    Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                                    R 1 Reply Last reply
                                    0
                                    • C charlieg

                                      The only hungarian notation I really like is sticking a little "p" in front of a variable to indicate it's a pointer. Just makes it easier to understand what I am doing. Microsoft loves to go wonkers with it (UINT32, and yes I know that's a type), and I have seen some code (due to coding standards) look like pStrConst_Variablename.

                                      Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                                      R Offline
                                      R Offline
                                      raddevus
                                      wrote on last edited by
                                      #18

                                      Personally my favorite is :

                                      LPSTR lpszName // lp = long pointer s = string z = zero (null).
                                      // It's a long pointer to a null terminated string, of course.

                                      :rolleyes: Thos were the good old days* when there were no Internet to look that stuff up. All you had was The Petzold and windows.h. :) *Not really all that great for learning to program. :)

                                      1 Reply Last reply
                                      0
                                      • T TheGreatAndPowerfulOz

                                        den2k88 wrote:

                                        scoped variables ... apart from making the code more difficult to read and to maintain.

                                        I actually find using scoped variables makes code easier to read and maintain. :-D YMMV. And it has fixed and avoided many a bug for me.

                                        den2k88 wrote:

                                        always initialize your variables

                                        Indeed. Yes!

                                        den2k88 wrote:

                                        absolutely, positively sure

                                        That works until it doesn't. See first rule: initialize!

                                        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                        D Offline
                                        D Offline
                                        den2k88
                                        wrote on last edited by
                                        #19

                                        TheGreatAndPowerfulOz wrote:

                                        I actually find using scoped variables makes code easier to read and maintain. :-D YMMV. And it has fixed and avoided many a bug for me.

                                        If the code is well written, I concur. When they are used in 300-500 lines jack-of-all-trades functions with dozens of scopes inside and badly named variables on the other hand...

                                        TheGreatAndPowerfulOz wrote:

                                        That works until it doesn't. See first rule: initialize!

                                        My experience exactly :D

                                        GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

                                        B 1 Reply Last reply
                                        0
                                        • R raddevus

                                          When you see this, it only takes a few extra seconds to think about what the dev intends. But... X|

                                          for (;!objSourceSubFolders.atEnd(); objSourceSubFolders.moveNext()) {
                                          // do something with the files in the folder.
                                          }

                                          First of all, not sure why you need to use Hungarian notation to signal that this is an obj. But, more importantly, does the dev not know of the existence of the while loop? Or did he think this was an innovative approach? :sigh: Look how much simpler this is to read.

                                          while (!sourceSubFolders.atEnd()){
                                          // do something with files in the folder
                                          sourceSubFolders.moveNext();
                                          }

                                          EDIT This one is for all you people. You know who you are! :rolleyes:

                                          do {
                                          // do something with files in the folder
                                          sourceSubFolders.moveNext();
                                          }
                                          while (!sourceSubFolders.atEnd());

                                          M Offline
                                          M Offline
                                          Member 9167057
                                          wrote on last edited by
                                          #20

                                          First time I saw something like thins in a C++ code base, I thought "That's clever!" It was only the second thought that I remembered how much I bloody hate maintaining such "clever" solutions. We coders tend to be attracted to logical puzzles. It takes willpower to steer away from something clever in favor of something simple. Either that or enough experience to know how much of a PITA clever code can be.

                                          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