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. Programming peeve of the Day

Programming peeve of the Day

Scheduled Pinned Locked Moved The Lounge
53 Posts 28 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.
  • B BryanFazekas

    What is the value of the redundant return statement inside the braces? One of my first jobs was processing in a 16K space, and the data was 12K per record. We coded very concisely as we had no room for extraneous code. Today's compilers are far more efficient, but making the processing straightforward and eliminating redundant code is still a good idea.

    Mike HankeyM Offline
    Mike HankeyM Offline
    Mike Hankey
    wrote on last edited by
    #41

    I'm retired but I work a lot with embedded systems that have small memory spaces so every byte counts. The redundant return statements where a joke...to see how screwed up we could make it!

    The less you need, the more you have. JaxCoder.com

    B 1 Reply Last reply
    0
    • Mike HankeyM Mike Hankey

      I'm retired but I work a lot with embedded systems that have small memory spaces so every byte counts. The redundant return statements where a joke...to see how screwed up we could make it!

      The less you need, the more you have. JaxCoder.com

      B Offline
      B Offline
      BryanFazekas
      wrote on last edited by
      #42

      Mike, you're not even close to how screwed up someone could make this! :laugh: I worked with a guy who was intent on cover EVERY possibility. His program executed 700 lines of code when tabbing between fields. If anyone actually clicked something, it go ugly ....

      Mike HankeyM 1 Reply Last reply
      0
      • B BryanFazekas

        Mike, you're not even close to how screwed up someone could make this! :laugh: I worked with a guy who was intent on cover EVERY possibility. His program executed 700 lines of code when tabbing between fields. If anyone actually clicked something, it go ugly ....

        Mike HankeyM Offline
        Mike HankeyM Offline
        Mike Hankey
        wrote on last edited by
        #43

        I've no doubt that it could be more screwed up and I've seen it when I was getting payed to program. I wonder how some people get into the field and even more how they stay.

        The less you need, the more you have. JaxCoder.com

        B 1 Reply Last reply
        0
        • C Chris Maunder

          if (condition)
          {
          return;
          }
          else
          {
          // Do something else
          }

          cheers Chris Maunder

          B Offline
          B Offline
          BernardIE5317
          wrote on last edited by
          #44

          if(the_code_below_can_not_be_executed) return;
          // now do what must be done

          1 Reply Last reply
          0
          • Mike HankeyM Mike Hankey

            I've no doubt that it could be more screwed up and I've seen it when I was getting payed to program. I wonder how some people get into the field and even more how they stay.

            The less you need, the more you have. JaxCoder.com

            B Offline
            B Offline
            BryanFazekas
            wrote on last edited by
            #45

            Yeah, the lack of ability in some cases is amazing, and not in a good way. My boss tells a story of a former employee who made cut-n-paste an art form. Modern art form. This person appears to have never written a line of code -- everything was copied from other programs and web sites, and this person could not understand why the program would not work. In another situation I taught a COBOL programmer with 5 years experience how to program. I am not a COBOL programmer and have never compiled a single line. This is not picking on COBOL -- this guy did not understand program flow. OTOH, he was fantastic at phone support, which is where he should have been.

            N 1 Reply Last reply
            0
            • F Fueled By Decaff

              Hmm, to trying to please people who want a single exit point and clear intent when processing is completed:

              if (condition)
              {
              goto returnStatement;
              }
              // Do something else

              :returnStatement

              return;

              X| :laugh: X|

              C Offline
              C Offline
              Chris Maunder
              wrote on last edited by
              #46

              That's so, so wrong on so many levels...

              cheers Chris Maunder

              1 Reply Last reply
              0
              • C Chris Maunder

                if (condition)
                {
                return;
                }
                else
                {
                // Do something else
                }

                cheers Chris Maunder

                O Offline
                O Offline
                obermd
                wrote on last edited by
                #47

                Looks like a copy/paste error where the code wasn't cleaned up after the paste.

                1 Reply Last reply
                0
                • C Chris Maunder

                  if (condition)
                  {
                  return;
                  }
                  else
                  {
                  // Do something else
                  }

                  cheers Chris Maunder

                  A Offline
                  A Offline
                  agolddog
                  wrote on last edited by
                  #48

                  Of course! It should be:

                  if (!condition) {
                  //Do something else
                  }

                  1 Reply Last reply
                  0
                  • N NotTodayYo

                    Chris Maunder wrote:

                    Your rewrite is how it should be done.

                    Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.

                    M Offline
                    M Offline
                    Mark Starr
                    wrote on last edited by
                    #49

                    Agreed! That’s what GOTO is for. :laugh:

                    Time is the differentiation of eternity devised by man to measure the passage of human events. - Manly P. Hall Mark Just another cog in the wheel

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      if (condition)
                      {
                      return;
                      }
                      else
                      {
                      // Do something else
                      }

                      cheers Chris Maunder

                      J Offline
                      J Offline
                      jmaida
                      wrote on last edited by
                      #50

                      // need to do something if conditions are right otherwise don't if( condition ) { do something } return

                      1 Reply Last reply
                      0
                      • C Chris Maunder

                        if (condition)
                        {
                        return;
                        }
                        else
                        {
                        // Do something else
                        }

                        cheers Chris Maunder

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #51

                        Agreed. I like to avoid (complex) negative conditions; so I might have:

                        if ( negative condition as a positive) {
                        // continue.
                        else {
                        return;
                        }

                        (Don't like your braces tho ... bad Feng Shui)

                        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                        1 Reply Last reply
                        0
                        • B BryanFazekas

                          Yeah, the lack of ability in some cases is amazing, and not in a good way. My boss tells a story of a former employee who made cut-n-paste an art form. Modern art form. This person appears to have never written a line of code -- everything was copied from other programs and web sites, and this person could not understand why the program would not work. In another situation I taught a COBOL programmer with 5 years experience how to program. I am not a COBOL programmer and have never compiled a single line. This is not picking on COBOL -- this guy did not understand program flow. OTOH, he was fantastic at phone support, which is where he should have been.

                          N Offline
                          N Offline
                          NightPen
                          wrote on last edited by
                          #52

                          My first developer job at Microsoft required me to analyze code written by a 'developer who got promoted so is no longer available. I and another dev spent hours analyzing this C language mess. Finally, after hours of analysis, we traced deep enough to get to the root of what the code was doing. Result? It returned the number 1. Yup, that is all the entire 20K lines of code did. The reason it never worked? The array this was used to dereference only had 1 element. Sheesh.

                          1 Reply Last reply
                          0
                          • N NotTodayYo

                            Chris Maunder wrote:

                            Your rewrite is how it should be done.

                            Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.

                            W Offline
                            W Offline
                            willichan
                            wrote on last edited by
                            #53

                            Why does this now come to mind? [https://static.wikia.nocookie.net/company-bumpers/images/7/7d/TCFHE-Australia-1995-Rewind.png\](https://static.wikia.nocookie.net/company-bumpers/images/7/7d/TCFHE-Australia-1995-Rewind.png) Money makes the world go round ... but documentation moves the money.

                            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