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. Semicolon at the end of a comment line.

Semicolon at the end of a comment line.

Scheduled Pinned Locked Moved The Lounge
31 Posts 16 Posters 3 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.
  • H honey the codewitch

    For some reason - maybe it's my editor? - but lately I've been dropping a lot of { open braces after if (K&R style for me in C/C++) and it rains absolute mayhem down on my source code. My editor lights up like a $5 {expletive, use your imagination}, and of course nothing compiles. It's also just the sort of thing your brain will fill in for you automatically if it's not there while scanning code. Thanks brain!

    To err is human. Fortune favors the monsters.

    E Offline
    E Offline
    englebart
    wrote on last edited by
    #13

    I always use braces, even when not required. It future proofs for later maintenance. There was a great article supporting the always use braces approach, but I can’t remember the exact format used. The article had extensive test cases around merging changes from multiple branches and showed how braces protected correct merging. I have tried googling it, but with no luck. I guess I could just Chat GPT to provide the answer now? And if I do not like the answer then I will ask Chat GPT to write a white paper proving that my preferred brace style is superior and force my team to adopt it.

    H 1 Reply Last reply
    0
    • E englebart

      I always use braces, even when not required. It future proofs for later maintenance. There was a great article supporting the always use braces approach, but I can’t remember the exact format used. The article had extensive test cases around merging changes from multiple branches and showed how braces protected correct merging. I have tried googling it, but with no luck. I guess I could just Chat GPT to provide the answer now? And if I do not like the answer then I will ask Chat GPT to write a white paper proving that my preferred brace style is superior and force my team to adopt it.

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #14

      I *was* using braces. I'm talking about typing:

      if(foo!=nullptr)
      printf("foo valid\n");
      }

      Like that.

      To err is human. Fortune favors the monsters.

      E J 2 Replies Last reply
      0
      • H honey the codewitch

        I *was* using braces. I'm talking about typing:

        if(foo!=nullptr)
        printf("foo valid\n");
        }

        Like that.

        To err is human. Fortune favors the monsters.

        E Offline
        E Offline
        englebart
        wrote on last edited by
        #15

        At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”

        W H 2 Replies Last reply
        0
        • E englebart

          At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”

          W Offline
          W Offline
          Wizard of Sleeves
          wrote on last edited by
          #16

          This is why I *always* use braces after an if is there is only one line of code ...

          if(expression == true) {
          doSomething();
          }

          Then later when reviewing my code, I decide to tidy it up because it looks nicer ...

          if(expression == true) doSomething();

          Third time around I add one line of code and spend the rest of the day trying to figure out why nothing works.

          Nothing succeeds like a budgie without teeth. To err is human, to arr is pirate.

          1 Reply Last reply
          0
          • E englebart

            At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #17

            Yeah, that's not a fun bug. Fortunately for me, the number of times that has happened to me I can count on one hand.

            To err is human. Fortune favors the monsters.

            1 Reply Last reply
            0
            • H honey the codewitch

              I *was* using braces. I'm talking about typing:

              if(foo!=nullptr)
              printf("foo valid\n");
              }

              Like that.

              To err is human. Fortune favors the monsters.

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

              That closing curly kicks my OCD right where it hurts.

              1 Reply Last reply
              0
              • R Ron Anders

                Too late, already pressed F5, Someday I or someone will get a mild chuckle.

                W Offline
                W Offline
                WPerkins
                wrote on last edited by
                #19

                I found myself (in the old days) putting periods at the end of COBOL comments... but that was OK.

                1 Reply Last reply
                0
                • S Single Step Debugger

                  Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.

                  Advertise here – minimum three posts per day are guaranteed.

                  P Offline
                  P Offline
                  Peter Adam
                  wrote on last edited by
                  #20

                  That is a perfectly valid SAS code[^]. I still don't believe in it when I see it.

                  1 Reply Last reply
                  0
                  • S Single Step Debugger

                    Edit: got it (the fishy part) :) Here, let me clear the picture:

                    if(obj->nVar > 0);
                    {
                    //unreachable code
                    //more unreachable code
                    //even more unreachable code
                    }

                    It was verry confusing because it was CLI manageable section and without a special pragma you cannot debug this code.

                    Advertise here – minimum three posts per day are guaranteed.

                    J Offline
                    J Offline
                    James Curran
                    wrote on last edited by
                    #21

                    um... Not only would that ode be reachable, it would be executed every time.

                    Truth, James

                    S 1 Reply Last reply
                    0
                    • J James Curran

                      um... Not only would that ode be reachable, it would be executed every time.

                      Truth, James

                      S Offline
                      S Offline
                      Single Step Debugger
                      wrote on last edited by
                      #22

                      Yes, exactly - bad wording on my side.

                      Advertise here – minimum three posts per day are guaranteed.

                      1 Reply Last reply
                      0
                      • S Single Step Debugger

                        Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.

                        Advertise here – minimum three posts per day are guaranteed.

                        D Offline
                        D Offline
                        dandy72
                        wrote on last edited by
                        #23

                        Single Step Debugger wrote:

                        Better than a semicolon at the end of an "if" statement.

                        That's a fun one. Back in my college days, a fellow student (much older than the rest of us, I think he decided to go back to college in his 40s) had the habit of leaving his system logged in, with his editor running...so whenever he took a break to (typically) go pick something up at the cafeteria, we'd do things like adding a bunch of spaces after a for loop and then a semi-colon (so it's off-screen and not visible), so his code read:

                        for ( int i = 0; i < someLimit; i++ ) ; <-- not visible without scrolling horizontally
                        {
                        // this only ran once no matter what
                        }

                        We did it many times, but he never learned to lock his workstation...fool me once... Poor guy. He was already struggling, and we made him waste a lot of his time on things like this... Gaetan, wherever you are, I hope you still had a successful and rewarding career... :rose:

                        S 1 Reply Last reply
                        0
                        • D dandy72

                          Single Step Debugger wrote:

                          Better than a semicolon at the end of an "if" statement.

                          That's a fun one. Back in my college days, a fellow student (much older than the rest of us, I think he decided to go back to college in his 40s) had the habit of leaving his system logged in, with his editor running...so whenever he took a break to (typically) go pick something up at the cafeteria, we'd do things like adding a bunch of spaces after a for loop and then a semi-colon (so it's off-screen and not visible), so his code read:

                          for ( int i = 0; i < someLimit; i++ ) ; <-- not visible without scrolling horizontally
                          {
                          // this only ran once no matter what
                          }

                          We did it many times, but he never learned to lock his workstation...fool me once... Poor guy. He was already struggling, and we made him waste a lot of his time on things like this... Gaetan, wherever you are, I hope you still had a successful and rewarding career... :rose:

                          S Offline
                          S Offline
                          Single Step Debugger
                          wrote on last edited by
                          #24

                          That's so evil! I like it! :-D

                          Advertise here – minimum three posts per day are guaranteed.

                          D 1 Reply Last reply
                          0
                          • S Single Step Debugger

                            Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.

                            Advertise here – minimum three posts per day are guaranteed.

                            T Offline
                            T Offline
                            trønderen
                            wrote on last edited by
                            #25

                            Didn't your compiler warn you about a 'possibly unintended empty statement' or something like that? (Or have you disabled that error message?)

                            S 1 Reply Last reply
                            0
                            • S Single Step Debugger

                              Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.

                              Advertise here – minimum three posts per day are guaranteed.

                              A Offline
                              A Offline
                              Alister Morton
                              wrote on last edited by
                              #26

                              BTDTGTTS

                              1 Reply Last reply
                              0
                              • S Single Step Debugger

                                That's so evil! I like it! :-D

                                Advertise here – minimum three posts per day are guaranteed.

                                D Offline
                                D Offline
                                dandy72
                                wrote on last edited by
                                #27

                                All students had some storage on a Novell network... I forget the details - either all storage was accessible by all by default, or we could create shares accessible to anyone or whoever we wanted to share with. That was back in the DOS days where you didn't have a GUI to multi-select files/folders and delete them in a single operation. You could delete files in bulk at a command prompt using wildcards, but only in a given folder - not recursively - you then had to navigate to a different folder and repeat. I knew people were poking around and taking stuff from each other, and running random EXEs they found (!), so I created a small program with an intriguing filename, such as, I don't know, "decodepwds.exe" that identified the user's home folder, and generated in it a hierarchy of folders with extended-ASCII names until the file system started reporting errors (there was probably a quota policy in place). Since you couldn't recursively delete folders in bulk, you were stuck with these folders with names that were difficult to type in...I *had* heard of people having no choice but to go to the IT admin and asking to get their account reset because they had run out of space, and had no idea how to delete all that crap. The IT guy had no clue where this was coming from, since the origin of said files/folders didn't get logged anywhere - and the owner of the files was the person running the EXE, so they couldn't blame someone else. That's probably the worst I had ever done. :-) Sad thing is, even today, people *would* run a random EXE they found somewhere if the filename was interesting enough.

                                1 Reply Last reply
                                0
                                • T trønderen

                                  Didn't your compiler warn you about a 'possibly unintended empty statement' or something like that? (Or have you disabled that error message?)

                                  S Offline
                                  S Offline
                                  Single Step Debugger
                                  wrote on last edited by
                                  #28

                                  Huge legacy project 5+ million ROC - tons of warnings. :sigh:

                                  Advertise here – minimum three posts per day are guaranteed.

                                  T 1 Reply Last reply
                                  0
                                  • S Single Step Debugger

                                    Huge legacy project 5+ million ROC - tons of warnings. :sigh:

                                    Advertise here – minimum three posts per day are guaranteed.

                                    T Offline
                                    T Offline
                                    trønderen
                                    wrote on last edited by
                                    #29

                                    You make it sound like "Yeah, the compiler gave me a warning, but I didn't read the warning". If that is the case: YAFIYGI

                                    S 1 Reply Last reply
                                    0
                                    • T trønderen

                                      You make it sound like "Yeah, the compiler gave me a warning, but I didn't read the warning". If that is the case: YAFIYGI

                                      S Offline
                                      S Offline
                                      Single Step Debugger
                                      wrote on last edited by
                                      #30

                                      Sounds like You've never worked on a big project. A lot of warnings are generated from the environment, not necessarily a bad code. That's why now we have systems like SonarCloud/SonarSource. Also, as I said it wasn't my code. I happened to be the development manager in charge. If you start hunting urgent production bug with building the project and analyzing low-level warnings, this is bad news for your employers.

                                      Advertise here – minimum three posts per day are guaranteed.

                                      T 1 Reply Last reply
                                      0
                                      • S Single Step Debugger

                                        Sounds like You've never worked on a big project. A lot of warnings are generated from the environment, not necessarily a bad code. That's why now we have systems like SonarCloud/SonarSource. Also, as I said it wasn't my code. I happened to be the development manager in charge. If you start hunting urgent production bug with building the project and analyzing low-level warnings, this is bad news for your employers.

                                        Advertise here – minimum three posts per day are guaranteed.

                                        T Offline
                                        T Offline
                                        trønderen
                                        wrote on last edited by
                                        #31

                                        If you are "the development manager in charge", I am surprised that spending half a day, as you told, chasing this bug was your responsibility. But then again, I know nothing about your company. If this really was your coworkers code, I guess he should have looked at the warning pertaining to his code. If you think that "This is a big system, so neither I as the development manager in charge, nor the developers responsible for a specific module, need to read the warnings - we'll rather complain in network forums about how nasty such bugs are", then I think you got what you deserved. I have been working on big systems, and I have been responsible for the processing of warnings and errors, suppressing those that are considered 'noise', reporting the significant ones to the developer. I would never, ever, have classified 'Unexpected empty statement' as insignificant noise. I am not familiar with SonarCloud/SonarSource (I just checked the Wikipedia article; that is my first encounter with them). If this system is not capable of drawing your attention to unexpected empty statements, but let it drown in 'a lot of warning generated from the environment, not necessarily a bad code', then I would consider other tools. I have been working with Coverity; it looks to me as if SonarSource is in the same business. With Coverity, you can indicate for almost any warning that 'This is noise - don't bother me with it'. But you are explicitly presented with every issue at least once, until you say 'Don't bother me with that issue any more'. You may also tell Coverity: "Never bother me with such silly details as unexpected empty statements - they're probably perfectly fine, good code!" In either case: You asked for it. You got it. Your story does not suggest that SonarSource is a viable alternative to Coverity.

                                        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