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. Code Reviews

Code Reviews

Scheduled Pinned Locked Moved The Lounge
questiondiscussion
54 Posts 32 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.
  • 5 5teveH

    I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

    if {condition} then {do something}

    Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    I'm happy with

    if (parameter == null) return;

    and so on, but anything more complex than "return" or "throw" I put in brackets over three lines:

    if (parameter == null)
    {
    ...
    }

    The only time I will omit the brackets is for a very short instruction on the same line as it's test.

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    G 5 S R O 5 Replies Last reply
    0
    • 5 5teveH

      I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

      if {condition} then {do something}

      Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

      K Offline
      K Offline
      Kris Lantz
      wrote on last edited by
      #3

      I'll do a single line if-statement if the code inside the braces is a single line, function call, etc. If I were reviewing another's code, either way would be suitable.

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I'm happy with

        if (parameter == null) return;

        and so on, but anything more complex than "return" or "throw" I put in brackets over three lines:

        if (parameter == null)
        {
        ...
        }

        The only time I will omit the brackets is for a very short instruction on the same line as it's test.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        G Offline
        G Offline
        GenJerDan
        wrote on last edited by
        #4

        I do brackets because, sooner or later, I'll be adding something else in there.

        We won't sit down. We won't shut up. We won't go quietly away. YouTube, and My Mu[sic], Films and Windows Programs, etc. and FB

        F S 2 Replies Last reply
        0
        • 5 5teveH

          I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

          if {condition} then {do something}

          Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

          C Offline
          C Offline
          Chris Copeland
          wrote on last edited by
          #5

          This is why we use a code formatter at our place, to avoid the drama and debates on the code reviews! Everyone's code looks equally terrible.

          [ MQ | Tor.NET | Mimick ]

          T 5 B 3 Replies Last reply
          0
          • G GenJerDan

            I do brackets because, sooner or later, I'll be adding something else in there.

            We won't sit down. We won't shut up. We won't go quietly away. YouTube, and My Mu[sic], Films and Windows Programs, etc. and FB

            F Offline
            F Offline
            Forogar
            wrote on last edited by
            #6

            I agree. I always do brackets even for one-liners because, in the words of Forrest Gump, "That's one less thing to worry about".

            - I would love to change the world, but they won’t give me the source code.

            Sander RosselS 1 Reply Last reply
            0
            • C Chris Copeland

              This is why we use a code formatter at our place, to avoid the drama and debates on the code reviews! Everyone's code looks equally terrible.

              [ MQ | Tor.NET | Mimick ]

              T Offline
              T Offline
              theoldfool
              wrote on last edited by
              #7

              :thumbsup:

              If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.

              1 Reply Last reply
              0
              • 5 5teveH

                I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

                if {condition} then {do something}

                Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

                C Offline
                C Offline
                CHill60
                wrote on last edited by
                #8

                Quote:

                I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards.

                Personally, I would have spent the 2 minutes changing the code (actually I wouldn't have done it that way but that's a different argument) .. .. AND a further 2 minutes updating the standards (or at least 2 minutes making life h3ll for the owner of those standards until they updated them :laugh: )

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  I'm happy with

                  if (parameter == null) return;

                  and so on, but anything more complex than "return" or "throw" I put in brackets over three lines:

                  if (parameter == null)
                  {
                  ...
                  }

                  The only time I will omit the brackets is for a very short instruction on the same line as it's test.

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  5 Offline
                  5 Offline
                  5teveH
                  wrote on last edited by
                  #9

                  Firstly, I'm coding in a very old language. Here's the exact line of code. Hopefully you can translate to a 'proper' language.

                  IF ERROR.MSG = "" THEN ERROR.MSG = "Error ":ERROR.CODE

                  It was a catch-all I inserted, (without being asked), to ensure that an error message would always be returned, even when it was an unknown error code. Yes, it's a single "=" for both conditions and assignments. And I was made to change it to upper-case. FFS! What they wanted, was:

                  IF ERROR.MSG = "" THEN
                  ERROR.MSG = "Error ":ERROR.CODE
                  END

                  But, the point that I was trying to make was: not that my way is right, but: if they want it doing a particular way, it should be documented - particular as the code-base contains a, pretty much, 50:50 split of both syntaxes.

                  L 3 Replies Last reply
                  0
                  • 5 5teveH

                    I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

                    if {condition} then {do something}

                    Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

                    M Offline
                    M Offline
                    MarkTJohnson
                    wrote on last edited by
                    #10

                    Since both formats are used within the code base the person who bounced it was just wrong. Code reviews should be about functionality not form. (I would have done it the 4 line way personally but no way would I have rejected the review on style.)

                    if (condition)
                    {
                    action
                    }

                    But then, I'm old.

                    5 1 Reply Last reply
                    0
                    • M MarkTJohnson

                      Since both formats are used within the code base the person who bounced it was just wrong. Code reviews should be about functionality not form. (I would have done it the 4 line way personally but no way would I have rejected the review on style.)

                      if (condition)
                      {
                      action
                      }

                      But then, I'm old.

                      5 Offline
                      5 Offline
                      5teveH
                      wrote on last edited by
                      #11

                      MarkTJohnson wrote:

                      But then, I'm old.

                      Me too! Which is probably why I get landed with working with archaic languages. :(

                      MarkTJohnson wrote:

                      Since both formats are used within the code base the person who bounced it was just wrong. Code reviews should be about functionality not form.

                      Yep. If this had been about something not working, (or if it was important enough to be documented as a standard), I would have changed it in a jif!

                      S 1 Reply Last reply
                      0
                      • C Chris Copeland

                        This is why we use a code formatter at our place, to avoid the drama and debates on the code reviews! Everyone's code looks equally terrible.

                        [ MQ | Tor.NET | Mimick ]

                        5 Offline
                        5 Offline
                        5teveH
                        wrote on last edited by
                        #12

                        :-D

                        1 Reply Last reply
                        0
                        • 5 5teveH

                          I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

                          if {condition} then {do something}

                          Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #13

                          Absent a team style document, definitely stand your ground. And certainly ignore weenies who try to quote from other teams' style documents. "But Microsoft says.." "We don't work for Microsoft, you weenie!" I'm a whitespace supremicist as most of you know, so I nearly always use as much vertical space as I deem reasonable. There are times, though, when I would use a series of one-liners. Usually if the tests and actions are very similar -- to show how they are similar.

                          if ( TestX ) { DoX() } ;
                          if ( TestY ) { DoY() } ;
                          if ( TestZ ) { DoX() } ;
                          ...

                          I feel that in this situation, this style leads to more readable/understandable code and that copy/paste errors like above may be more easily spotted. Does the language you're using not allow:

                          {do something} if {condition}

                          VAX BASIC V3.9-000

                          Ready

                          10 LET X = 42
                          20 PRINT "yes" IF X = 42
                          runnh

                          yes
                          Ready

                          :laugh:

                          5 1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            I'm happy with

                            if (parameter == null) return;

                            and so on, but anything more complex than "return" or "throw" I put in brackets over three lines:

                            if (parameter == null)
                            {
                            ...
                            }

                            The only time I will omit the brackets is for a very short instruction on the same line as it's test.

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                            S Offline
                            S Offline
                            Stefan_Lang
                            wrote on last edited by
                            #14

                            You do it all wrong! The correct syntax is:

                            if (parameter == null)
                            {
                            return;
                            }
                            else
                            {
                            }

                            Reason: always add an else to an if, even if it's empty, because otherwise a future nested if could accidentally add an else at the wrong nesting level! ;P

                            GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                            OriginalGriffO U 2 Replies Last reply
                            0
                            • S Stefan_Lang

                              You do it all wrong! The correct syntax is:

                              if (parameter == null)
                              {
                              return;
                              }
                              else
                              {
                              }

                              Reason: always add an else to an if, even if it's empty, because otherwise a future nested if could accidentally add an else at the wrong nesting level! ;P

                              GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                              OriginalGriffO Offline
                              OriginalGriffO Offline
                              OriginalGriff
                              wrote on last edited by
                              #15

                              Take thy code to The Weird and The Wonderful[^] where it belongs! :laugh:

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                              S 1 Reply Last reply
                              0
                              • 5 5teveH

                                I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

                                if {condition} then {do something}

                                Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

                                Richard Andrew x64R Offline
                                Richard Andrew x64R Offline
                                Richard Andrew x64
                                wrote on last edited by
                                #16

                                I think you may have won the battle, but lost the larger point of it all. What you accomplished was to make yourself difficult to deal with. I don't think that's what you intended.

                                The difficult we do right away... ...the impossible takes slightly longer.

                                5 1 Reply Last reply
                                0
                                • 5 5teveH

                                  I just had a line of my code bounced for 'incorrect' syntax. It was a simple if/then - e.g.

                                  if {condition} then {do something}

                                  Which I had coded, as above, on a single line. The Code Reviewer said it should be on 3 lines. Both syntaxes are allowed in the language I am coding in, so I checked the Coding Standards document - and there's no mention of a preferred if/then syntax. Also, looking at the code-base, both syntaxes are used throughout. My view is: if they can't be bothered to document something as a standard, I, as a developer, am free to choose the syntax I prefer. I stood my ground, (and won out), not because I didn't want to spend 2 minutes changing the code, but because I value properly documented standards. What do you think guys?

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

                                  It's if (...), not if {...} I'll consider a single line if, if it is simple; and at the top of a method. Otherwise no. e.g. if ( parm1 == null ) { return; } And brackets around code: always. Even one-liners.

                                  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

                                  S 1 Reply Last reply
                                  0
                                  • 5 5teveH

                                    Firstly, I'm coding in a very old language. Here's the exact line of code. Hopefully you can translate to a 'proper' language.

                                    IF ERROR.MSG = "" THEN ERROR.MSG = "Error ":ERROR.CODE

                                    It was a catch-all I inserted, (without being asked), to ensure that an error message would always be returned, even when it was an unknown error code. Yes, it's a single "=" for both conditions and assignments. And I was made to change it to upper-case. FFS! What they wanted, was:

                                    IF ERROR.MSG = "" THEN
                                    ERROR.MSG = "Error ":ERROR.CODE
                                    END

                                    But, the point that I was trying to make was: not that my way is right, but: if they want it doing a particular way, it should be documented - particular as the code-base contains a, pretty much, 50:50 split of both syntaxes.

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

                                    Cobol?

                                    5 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Cobol?

                                      5 Offline
                                      5 Offline
                                      5teveH
                                      wrote on last edited by
                                      #19

                                      Richard MacCutchan wrote:

                                      Cobol?

                                      :) It's slightly easier than that! It's a (fairly significant) variation on Basic, which comes as part of the Universe DBMS. It's derived from Pick DataBasic (another one you won't have heard of!) and is actually very easy to develop with - albeit limited in scope. i.e. It's for dumb terminal applications. I like it though.

                                      L 1 Reply Last reply
                                      0
                                      • P PIEBALDconsult

                                        Absent a team style document, definitely stand your ground. And certainly ignore weenies who try to quote from other teams' style documents. "But Microsoft says.." "We don't work for Microsoft, you weenie!" I'm a whitespace supremicist as most of you know, so I nearly always use as much vertical space as I deem reasonable. There are times, though, when I would use a series of one-liners. Usually if the tests and actions are very similar -- to show how they are similar.

                                        if ( TestX ) { DoX() } ;
                                        if ( TestY ) { DoY() } ;
                                        if ( TestZ ) { DoX() } ;
                                        ...

                                        I feel that in this situation, this style leads to more readable/understandable code and that copy/paste errors like above may be more easily spotted. Does the language you're using not allow:

                                        {do something} if {condition}

                                        VAX BASIC V3.9-000

                                        Ready

                                        10 LET X = 42
                                        20 PRINT "yes" IF X = 42
                                        runnh

                                        yes
                                        Ready

                                        :laugh:

                                        5 Offline
                                        5 Offline
                                        5teveH
                                        wrote on last edited by
                                        #20

                                        I'm with you on everything. Particularly like the VAX BASIC - not a million miles away from what I'm working with.

                                        1 Reply Last reply
                                        0
                                        • Richard Andrew x64R Richard Andrew x64

                                          I think you may have won the battle, but lost the larger point of it all. What you accomplished was to make yourself difficult to deal with. I don't think that's what you intended.

                                          The difficult we do right away... ...the impossible takes slightly longer.

                                          5 Offline
                                          5 Offline
                                          5teveH
                                          wrote on last edited by
                                          #21

                                          I didn't just make myself difficult to deal with. I've been like that for about 40 years! :) Hopefully, anyone who knows me, knows that as well as being challenging and pedantic, I will always accept when I'm wrong; never take myself too seriously; and never get personal. Also, I generally give those above me a hard time, rather than my peers. Yep, my chances of promotion are zero - but that matches my ambition. I am way too old to be worrying about career and more than happy to come in and do the day-to-day grunt work.

                                          Richard Andrew x64R 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