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. Just because you can doesn't mean you should.

Just because you can doesn't mean you should.

Scheduled Pinned Locked Moved The Lounge
questioncryptographylearning
37 Posts 18 Posters 2 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
    rjmoses
    wrote on last edited by
    #1

    Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

    R P C L H 10 Replies Last reply
    0
    • R rjmoses

      Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #2

      I hate that kind of stuff. I always add the redundant parenthesis because I want to be explicit about what is going on and I find it helps in deciphering the statement. I do NOT want to rely on the precedence order.

      "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

      G 1 Reply Last reply
      0
      • R rjmoses

        Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

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

        Yup, I'm pro-parenthesis too. Real important in Regular Expressions as well.

        H K 2 Replies Last reply
        0
        • R rjmoses

          Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

          C Offline
          C Offline
          Cp Coder
          wrote on last edited by
          #4

          I once had a colleague who believed in obfuscating his C code to the maximum. He did not add comments to his code or any documentation of any kind. I believe he thought if he was the only one to understand his code, it provided a kind of job security. :mad: All went well for him until I was promoted into a position where he reported to me. One of my first actions was to fire him.

          Greg UtasG J P U J 5 Replies Last reply
          0
          • C Cp Coder

            I once had a colleague who believed in obfuscating his C code to the maximum. He did not add comments to his code or any documentation of any kind. I believe he thought if he was the only one to understand his code, it provided a kind of job security. :mad: All went well for him until I was promoted into a position where he reported to me. One of my first actions was to fire him.

            Greg UtasG Offline
            Greg UtasG Offline
            Greg Utas
            wrote on last edited by
            #5

            Cruel, but fair.

            <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
            <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

            1 Reply Last reply
            0
            • C Cp Coder

              I once had a colleague who believed in obfuscating his C code to the maximum. He did not add comments to his code or any documentation of any kind. I believe he thought if he was the only one to understand his code, it provided a kind of job security. :mad: All went well for him until I was promoted into a position where he reported to me. One of my first actions was to fire him.

              J Offline
              J Offline
              Jon McKee
              wrote on last edited by
              #6

              In the name of the code-base, the style guidelines, and the future maintainers, we say - comment :-D (And just name things well.)

              1 Reply Last reply
              0
              • R rjmoses

                Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

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

                Hmmmm, Looks like Sebastiano Vigna[^] wrote that code back in 1998 shortly after leaving Milano. Best Wishes, -David Delaune

                R 1 Reply Last reply
                0
                • R rjmoses

                  Tripping through some older but still used C code, I found this section: action a; if ((a = hash_table[r]) && !cmdcmp(commands[--a].name, p) || (a = short_hash_table[r]) && !cmdcmp(commands[--a].short_name, p)) r = a; else r = -1; Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Of course, the programmer saved a couple of characters by excluding four(?) unnecessary parens. Upon further investigation, I found many instances of this type of statement structure. Apparently that was the preferred coding style. So, I'm guessing the programmer probably saved 100 characters. But it takes a lot of time to examine each statement and hopefully understand what is going on.

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

                  I agree with you that the code is just a pain.

                  Quote:

                  Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers!

                  I would. It better. If it's not, it's not C spec and the documentation better have that in big red flashing letters.

                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                  P 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Yup, I'm pro-parenthesis too. Real important in Regular Expressions as well.

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

                    caveat with parenthesis in regular expressions. Unfortunately, with some engines () creates an unavoidable capture (no way to turn it off unlike in PCRE or .net regex) So if you're using like, Microsoft Visual Studio search and replace w/ regex (which i have to from time to time) it pays not to use extra parens. You're not maintaining that regex "code" anyway and the parens just make it so you have to keep advancing $1, $2, to $3 for each group and you only get 9 of them so it's maybe not the best idea to use extras. I bring this up because 50% of the time i'm not tokenizing i'm using regex in something like a search box and the above applies.

                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                    P 1 Reply Last reply
                    0
                    • C Cp Coder

                      I once had a colleague who believed in obfuscating his C code to the maximum. He did not add comments to his code or any documentation of any kind. I believe he thought if he was the only one to understand his code, it provided a kind of job security. :mad: All went well for him until I was promoted into a position where he reported to me. One of my first actions was to fire him.

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

                      Any employee who thinks he has "job security" should be summarily fired.

                      Greg UtasG J 2 Replies Last reply
                      0
                      • H honey the codewitch

                        caveat with parenthesis in regular expressions. Unfortunately, with some engines () creates an unavoidable capture (no way to turn it off unlike in PCRE or .net regex) So if you're using like, Microsoft Visual Studio search and replace w/ regex (which i have to from time to time) it pays not to use extra parens. You're not maintaining that regex "code" anyway and the parens just make it so you have to keep advancing $1, $2, to $3 for each group and you only get 9 of them so it's maybe not the best idea to use extras. I bring this up because 50% of the time i'm not tokenizing i'm using regex in something like a search box and the above applies.

                        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

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

                        Well, sure, but with some rather complex ones which are hard-coded in a program. The OR operator in particular causes me trouble, so I use parentheses, e.g. ((foo)|(bar)) And often with the Explicit Capture option. .net's engine is so feature-rich. I was working with SPLUNK over the summer and was stunned by the lack of flexibility in that engine (PCRE?).

                        H 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          Well, sure, but with some rather complex ones which are hard-coded in a program. The OR operator in particular causes me trouble, so I use parentheses, e.g. ((foo)|(bar)) And often with the Explicit Capture option. .net's engine is so feature-rich. I was working with SPLUNK over the summer and was stunned by the lack of flexibility in that engine (PCRE?).

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

                          I've never heard of splunk but i'm actually far more comfortable with the non-backtracking subset of regex - everything that can be boiled down to () | or * That's because i mostly use them with tokenizing. But honestly i've found if you need backtracking, regex might not be the best tool anyway, because it quickly becomes cumbersome with complex expressions. In one of my fancier tokenizers i gave you ways to break up the regex into reusable bits if you liked to keep them manageable. I may or may not do that again but i never really used it. Some people hate regex tho.

                          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                          1 Reply Last reply
                          0
                          • H honey the codewitch

                            I agree with you that the code is just a pain.

                            Quote:

                            Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers!

                            I would. It better. If it's not, it's not C spec and the documentation better have that in big red flashing letters.

                            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

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

                            Oh, ever hear of Caché? (The "database".) Its not-quite-SQL language doesn't honor order-of-operations! (But it's faaaasssst!)

                            H 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              Oh, ever hear of Caché? (The "database".) Its not-quite-SQL language doesn't honor order-of-operations! (But it's faaaasssst!)

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

                              that seems kind of pointless. How can I tell what it's doing? oh never mind. it's just silly. i don't even want to know. :laugh:

                              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                              1 Reply Last reply
                              0
                              • L Lost User

                                Hmmmm, Looks like Sebastiano Vigna[^] wrote that code back in 1998 shortly after leaving Milano. Best Wishes, -David Delaune

                                R Offline
                                R Offline
                                rjmoses
                                wrote on last edited by
                                #15

                                Tell me more.

                                L 1 Reply Last reply
                                0
                                • R rjmoses

                                  Tell me more.

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

                                  more

                                  R 1 Reply Last reply
                                  0
                                  • L Lost User

                                    more

                                    R Offline
                                    R Offline
                                    rjmoses
                                    wrote on last edited by
                                    #17

                                    Good one! I deserved that. How did you come up with S. Vigna?

                                    L 1 Reply Last reply
                                    0
                                    • R rjmoses

                                      Good one! I deserved that. How did you come up with S. Vigna?

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

                                      Well, I searched for the code snippit and found it in the NE editor source code[^] dated 1998. Best Wishes, -David Delaune

                                      R 2 Replies Last reply
                                      0
                                      • P PIEBALDconsult

                                        Any employee who thinks he has "job security" should be summarily fired.

                                        Greg UtasG Offline
                                        Greg UtasG Offline
                                        Greg Utas
                                        wrote on last edited by
                                        #19

                                        Graveyards are filled with people who were indispensable.

                                        <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                        <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          Well, I searched for the code snippit and found it in the NE editor source code[^] dated 1998. Best Wishes, -David Delaune

                                          R Offline
                                          R Offline
                                          rjmoses
                                          wrote on last edited by
                                          #20

                                          Very good! I like ne and it is an excellent editor! My hat is off to Sebastian. I was using it back in the late 1990's and adapted to run on AIX when I was doing work out of Chicago in Australia and London over a 9600BPS links. I had cause to want to run it recently for a project and resurrected it. I love it's ease of use and functionality, but the code is difficult to follow. I would love to meet Sebastian--he must be one brilliant son of a gun!

                                          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