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. Other Discussions
  3. The Weird and The Wonderful
  4. To me this is a coding horror, and to you? [modified]

To me this is a coding horror, and to you? [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
84 Posts 26 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.
  • G geoffs

    Thank you... for explaining in better terms what I was feeling when I made the original post.

    G Offline
    G Offline
    geoffs
    wrote on last edited by
    #47

    Amazing - CP is apparently not much different from Usenet. No matter how inoffensive a statement might be, you find someone who will take offense. How in heck can what I have stated in the previous message have caused someone to vote it down? :confused:

    D 1 Reply Last reply
    0
    • G geoffs

      :laugh: Ah, a man after my own heart! It is not perverse to me. In fact, I am quite at home with that syntax and like it. It is perverse because so many of my fellow programmers hate it and my use of it makes them froth at the mouth or sit there with a dumbfounded look because they don't understand what it is doing.

      L Offline
      L Offline
      leonej_dt
      wrote on last edited by
      #48

      geoffs wrote:

      because they don't understand what it is doing

      I hate people who use C to program in Java.

      To those who understand, I extend my hand. To the doubtful I demand: Take me as I am. Not under your command, I know where I stand. I won't change to fit yout plan. Take me as I am.

      1 Reply Last reply
      0
      • G geoffs

        Amazing - CP is apparently not much different from Usenet. No matter how inoffensive a statement might be, you find someone who will take offense. How in heck can what I have stated in the previous message have caused someone to vote it down? :confused:

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #49

        Let me get this right, you're asking about how stupidity can exist on the internet. The only type of question more likely to get a yes answer than 'can there be anyone on the web that stupid/ignorant/obnoxious' is 'can there be anything on the web that gross/perverse/obscene'.

        Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

        D 1 Reply Last reply
        0
        • G geoffs

          First, let me say that the code excerpt below is not an egregious violation (and maybe not a violation at all), but it is a coding horror for my programming style and I am curious as to what the others here think about it. So, in reviewing a coworker's code I come across the following line:

          m\_boolVar = (intVar == 0 ? false : true) ;
          

          Yes, parenthesization and spacing exactly as shown above. Were it my code, it would have been written as:

          m\_boolVar = intVar != 0; // (corrected from == 0 by GDavy -- I typed too fast!
          

          ...or if I was feeling in a bit more perverse mood:

          m\_boolVar = !!intVar;
          

          There were much bigger fish to fry in this code, but there are times when I just can't let things like this go by. These things are like misspelled words that shout out at me from among the surrounding text.

          modified on Tuesday, September 16, 2008 3:02 AM

          D Offline
          D Offline
          David St Hilaire
          wrote on last edited by
          #50

          I see a lot of:

          if (b1)
          b2 = true;
          else
          b2 = false;

          and even some:

          switch (b1)
          {
          case true:
          b2 = true;
          break;
          case false:
          b2 = false;
          break;
          }

          C 1 Reply Last reply
          0
          • M Megidolaon

            Your code is shorter, but the other one is easier to read. Your code is still pretty easy to read but I think readability is more important than conciseness. When you look at someone's or even your own code after a while (to find a bug or whatever), it's best if you can easily read and immediately grasp the function of the code. If everything is as concise as possibly, you often have hard to read code, which takes much longer to comprehend. So, writing easy to read code will save you time later.

            C Offline
            C Offline
            cpkilekofp
            wrote on last edited by
            #51

            Megidolaon wrote:

            Your code is shorter, but the other one is easier to read.

            Easy to read for someone who doesn't understand what booleans are, yes. I don't want someone coding for me who doesn't understand booleans - they probably don't understand much else, either. The third expression the original poster gives is the kind of thing that C programmers do all the time, but I don't think it's really appropriate for an application that has to be maintained by programmers of indeterminate skill. However, the first expression simply exposes the one who wrote it as ignorant.

            1 Reply Last reply
            0
            • R RugbyLeague

              It's just different styles of programming rather than a coding horror.

              C Offline
              C Offline
              cpkilekofp
              wrote on last edited by
              #52

              RugbyLeague wrote:

              It's just different styles of programming rather than a coding horror.

              If you coded "boolean_value == true" in my shop, I'd do my best to get you out of my shop as quickly as possible. Calling this convention a "style" is like calling a bum's rags "fashion."

              D 1 Reply Last reply
              0
              • N Nemanja Trifunovic

                geoffs wrote:

                but it is a coding horror for my programming style and I am curious as to what the others here think about it.

                As you said - it is a horror for your programming style. Different people use different styles, and as long as the code is correct and reasonably readable there is no point in discussing it.

                Programming Blog utf8-cpp

                C Offline
                C Offline
                cpkilekofp
                wrote on last edited by
                #53

                Nemanja Trifunovic wrote:

                As you said - it is a horror for your programming style. Different people use different styles, and as long as the code is correct and reasonably readable there is no point in discussing it.

                Are you serious?? Glad you're not in MY shop.

                1 Reply Last reply
                0
                • R realJSOP

                  I would have scoped it:

                  m_boolVar = (intVar != 0);

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  C Offline
                  C Offline
                  cpkilekofp
                  wrote on last edited by
                  #54

                  John Simmons / outlaw programmer wrote:

                  I would have scoped it: m_boolVar = (intVar != 0);

                  Yeah, I do this, too. This is VERY readable to someone with sufficient competency in C# to be trusted with the maintenance of production code. The scoops highlight the boolean expression and make it a one-glance read; without the scoops, it requires a bit more concentration, which can be exhausting if you have to spend that bit of concentration 300 times while reading a single source file.

                  1 Reply Last reply
                  0
                  • D dighn

                    I think it's too trivial to fuss over.

                    C Offline
                    C Offline
                    cpkilekofp
                    wrote on last edited by
                    #55

                    dighn wrote:

                    I think it's too trivial to fuss over.

                    If someone is wasting their time in writing such foolish expressions, and wasting my time by making me read it, it isn't trivial, not when I have to edit 200-300 lines of code before lunch.

                    1 Reply Last reply
                    0
                    • S Swinefeaster

                      i would go with:

                      m_boolVar = intVar ? true : false;

                      C Offline
                      C Offline
                      cpkilekofp
                      wrote on last edited by
                      #56

                      Swinefeaster wrote:

                      i would go with: m_boolVar = intVar ? true : false;

                      That combines the worst of expression one with the worst of expression three.

                      1 Reply Last reply
                      0
                      • A Andrew Torrance

                        I prefer your coworkers style . In terms of efficiency i doubt if there is any significant difference unless this is getting called repeatedly , and it is much much easier to read and understand than m_boolVar = intVar != 0; as this requires you to think about precedence. Just becasue you understand it does not mean that the maintenance programmer will . But at the end of the day its a style question , and nothing divides programmers more than that .

                        C Offline
                        C Offline
                        cpkilekofp
                        wrote on last edited by
                        #57

                        Andrew Torrance wrote:

                        it is much much easier to read and understand than m_boolVar = intVar != 0; as this requires you to think about precedence.

                        If you have to think about precedence, you need to work on your skill set. I guarantee that if you were a junior I was mentoring, you wouldn't have to think about it by the time I got through with you.

                        1 Reply Last reply
                        0
                        • G geoffs

                          Now that I've gotten this off of my chest, I can admit to myself that it really was more of a style issue rather than a coding horror as modern compilers would probably generate similar, if not same, code for any of the alternatives. I probably should have posted it to Soap Box or Lounge, but it is what it is at this point. Thanks for all of your inputs. Some people agreed, some did not, and yet others were bored by the whole thing (in which case why did they even bother to reply?). Meanwhile, my style is best... :doh: ;)

                          C Offline
                          C Offline
                          cpkilekofp
                          wrote on last edited by
                          #58

                          geoffs wrote:

                          Now that I've gotten this off of my chest, I can admit to myself that it really was more of a style issue rather than a coding horror as modern compilers would probably generate similar, if not same, code for any of the alternatives. I probably should have posted it to Soap Box or Lounge, but it is what it is at this point.

                          Don't let the idiots beat on you. It's not style, it's a clear indicator of someone uncomfortable with the language. Perhaps this is a minor thing, but I despise working with people (a) who are uncomfortable working with their language, (b) and who don't work like heck to GET comfortable.

                          1 Reply Last reply
                          0
                          • L leonej_dt

                            geoffs wrote:

                            m_boolVar = !!intVar;

                            What is so perverse with that?

                            To those who understand, I extend my hand. To the doubtful I demand: Take me as I am. Not under your command, I know where I stand. I won't change to fit yout plan. Take me as I am.

                            C Offline
                            C Offline
                            cpkilekofp
                            wrote on last edited by
                            #59

                            leonej_dt wrote:

                            geoffs wrote: m_boolVar = !!intVar; What is so perverse with that?

                            Dependence on zero values being interpreted as false and non-zero as true is a particular feature of C-style languages. It confabulates boolean and integer types, which was OK in C (which has no native boolean type) but is highly inappropriate for any language that does support boolean.

                            L 1 Reply Last reply
                            0
                            • D David St Hilaire

                              I see a lot of:

                              if (b1)
                              b2 = true;
                              else
                              b2 = false;

                              and even some:

                              switch (b1)
                              {
                              case true:
                              b2 = true;
                              break;
                              case false:
                              b2 = false;
                              break;
                              }

                              C Offline
                              C Offline
                              cpkilekofp
                              wrote on last edited by
                              #60

                              David St. Hilaire wrote:

                              I see a lot of: if (b1) b2 = true;else b2 = false; and even some: switch (b1){case true: b2 = true; break;case false: b2 = false; break;}

                              You have my sympathies.

                              1 Reply Last reply
                              0
                              • C cpkilekofp

                                leonej_dt wrote:

                                geoffs wrote: m_boolVar = !!intVar; What is so perverse with that?

                                Dependence on zero values being interpreted as false and non-zero as true is a particular feature of C-style languages. It confabulates boolean and integer types, which was OK in C (which has no native boolean type) but is highly inappropriate for any language that does support boolean.

                                L Offline
                                L Offline
                                leonej_dt
                                wrote on last edited by
                                #61

                                cpkilekofp wrote:

                                It confabulates boolean and integer types, which (...) is highly inappropriate for any language that does support boolean.

                                What is a boolean when the computer understand data in 8 bit chunks?

                                If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                C 1 Reply Last reply
                                0
                                • L leonej_dt

                                  cpkilekofp wrote:

                                  It confabulates boolean and integer types, which (...) is highly inappropriate for any language that does support boolean.

                                  What is a boolean when the computer understand data in 8 bit chunks?

                                  If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                  C Offline
                                  C Offline
                                  cpkilekofp
                                  wrote on last edited by
                                  #62

                                  leonej_dt wrote:

                                  What is a boolean when the computer understand data in 8 bit chunks?

                                  I know this is marked as a joke....but what IS the joke??

                                  L 1 Reply Last reply
                                  0
                                  • C cpkilekofp

                                    leonej_dt wrote:

                                    What is a boolean when the computer understand data in 8 bit chunks?

                                    I know this is marked as a joke....but what IS the joke??

                                    L Offline
                                    L Offline
                                    leonej_dt
                                    wrote on last edited by
                                    #63

                                    cpkilekofp wrote:

                                    but what IS the joke??

                                    What's the need for such an abstraction as a "boolean"?

                                    If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                    C 1 Reply Last reply
                                    0
                                    • L leonej_dt

                                      cpkilekofp wrote:

                                      but what IS the joke??

                                      What's the need for such an abstraction as a "boolean"?

                                      If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                      C Offline
                                      C Offline
                                      cpkilekofp
                                      wrote on last edited by
                                      #64

                                      leonej_dt wrote:

                                      What's the need for such an abstraction as a "boolean"?

                                      I should think it's obvious. Booleans represent either true or false, yes or no. "Is the door open? yes." Using a boolean type, you're guaranteed that the value of an instance of that type will be one of two choices, true or false. Any other questions?

                                      L 1 Reply Last reply
                                      0
                                      • C cpkilekofp

                                        leonej_dt wrote:

                                        What's the need for such an abstraction as a "boolean"?

                                        I should think it's obvious. Booleans represent either true or false, yes or no. "Is the door open? yes." Using a boolean type, you're guaranteed that the value of an instance of that type will be one of two choices, true or false. Any other questions?

                                        L Offline
                                        L Offline
                                        leonej_dt
                                        wrote on last edited by
                                        #65

                                        And what's the difference between an 8-bit boolean and an 8-bit char whose values are restricted to 0 and 1? I still don't get it.

                                        If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                        C 1 Reply Last reply
                                        0
                                        • L leonej_dt

                                          And what's the difference between an 8-bit boolean and an 8-bit char whose values are restricted to 0 and 1? I still don't get it.

                                          If you can play The Dance of Eternity (Dream Theater), then we shall make a band.

                                          C Offline
                                          C Offline
                                          cpkilekofp
                                          wrote on last edited by
                                          #66

                                          leonej_dt wrote:

                                          And what's the difference between an 8-bit boolean and an 8-bit char whose values are restricted to 0 and 1? I still don't get it.

                                          What does the restriction? Either the language provides facilities for doing it, or the programmer has to provide the facilities. If its in the language, it can be taught in a standard way and understood in a standard way. If the programmer provides it, the programmer has to explain it, and only those with access to the programmer or his documentation will understand it. Why else develop languages in the first place? If everyone in the world had the ability to program effectively in machine language, we'd all be doing that.

                                          L 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