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. One guidelines for C/C++ programmer

One guidelines for C/C++ programmer

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpc++
37 Posts 18 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.
  • N Nemanja Trifunovic

    LOL. I remember someone suggesting defines like this:

    #define please
    #define thanks

    And the code would be much more pleasant to read:

    please do {
    ...
    } while (i < imax);
    thanks

    Programming Blog utf8-cpp

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

    I laughed really hard at this one! :D

    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
    • L leonej_dt

      We should create the union of real men, excuse me, C programmers. We'd fight to protect our jobs, our interests and our bugs!

      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
      CPallini
      wrote on last edited by
      #27

      leonej_dt wrote:

      We should create the union of real men, excuse me, C programmers.

      Definitely. :-D

      leonej_dt wrote:

      We'd fight to protect our jobs,

      That's not needed. Other 'programmers' with their 'masterpieces' ;P keep our jobs safe. :laugh:

      leonej_dt wrote:

      We'd fight to protect our our interests and our bugs!

      Definitely again. :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • A asadullah ansari

        In your project, If you are using if condition like

        enum
        {
        Blue_c,
        Yellow_c,
        Red_c
        };
        int color;

        if( color == yellow_c)
        {
        .....
        ......
        }
        or
        if(color != Red_c)
        {
        ....
        .....
        }

        Now you know by mistake if you forget one = or ! means if(color = yellow_c) or if(color = Red_c) then no error will come and bug fixing cost for your projects So To avoid this cost you should use

        if(yellow_c == color)
        {
        .....
        ......
        }
        or
        if(Red_c != color)
        {
        ....
        .....
        }

        Now if you forgot to put one = ot ! then compilation error will come.. So this should be in coding standard to use like this...

        Truth Can'nt be changed

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

        Yes, this is a decent standard, and has been recommended by some very prestigious programmers (Allen Holub comes to mind).

        1 Reply Last reply
        0
        • B BadKarma

          That's correct, in fact here we encourage people to use the most ugly, unwell formed and disaster bringing code that they may come up to. ;P

          Learn from the mistakes of others, you may not live long enough to make them all yourself.

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

          BadKarma wrote:

          That's correct, in fact here we encourage people to use the most ugly, unwell formed and disaster bringing code that they may come up to.

          I think you should have had some coffee before making this statement, as he is exactly right. Placing the constant first will catch this error, which is one of the common typographic errors in C-style languages.

          1 Reply Last reply
          0
          • C CPallini

            asadullah ansari wrote:

            minimize manpower

            Hence not a real-men company! BTW What is the point on minimizing manpower in software industry? Our work is creative after all, don't you agree? The Software Laborer :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

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

            CPallini wrote:

            BTW What is the point on minimizing manpower in software industry? Our work is creative after all, don't you agree? The Software Laborer

            *SEXIST STATEMENT WARNING* I like to maximize the girl power in my environment...as long as I get to stick around as the token alpha male :laugh: *END SEXIST STATEMENT*

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Oh, a coding standards horror. That only works when comparing an Lvalue and an Rvalue, and if a programmer can remember to do that, then he can remember to use the correct operator in the first place. Newbies will continue to screw it up, and experienced programmers will continue to get it right the first time. One company I worked for did have that in the coding standard, but even the guy who defined the standards admitted that it was pretty useless. If it causes you trouble you could switch to D, which will throw an error if it's not done right (if I recall correctly).

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

              PIEBALDconsult wrote:

              That only works when comparing an Lvalue and an Rvalue, and if a programmer can remember to do that, then he can remember to use the correct operator in the first place. Newbies will continue to screw it up, and experienced programmers will continue to get it right the first time.

              You've obviously never worked a 48-hour day.

              P 1 Reply Last reply
              0
              • J Joe Woodbury

                Yes, because actually looking at your warnings is apparently too difficult.

                Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

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

                Joe Woodbury wrote:

                Yes, because actually looking at your warnings is apparently too difficult.

                I had a manager once, who was quite skilled in C programming, but who would often leave warnings in his code if he thought they were trivial...which left him open to missing new warnings that weren't. He's a lawyer now.

                1 Reply Last reply
                0
                • C cpkilekofp

                  PIEBALDconsult wrote:

                  That only works when comparing an Lvalue and an Rvalue, and if a programmer can remember to do that, then he can remember to use the correct operator in the first place. Newbies will continue to screw it up, and experienced programmers will continue to get it right the first time.

                  You've obviously never worked a 48-hour day.

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

                  No, uh uh. The longest day I ever worked was 28 hours... and I fell asleep.

                  1 Reply Last reply
                  0
                  • C CPallini

                    Real C programmers (i.e. real men) don't use such girly tricks. They bravely make mistakes whenever is needed. ;P

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    C Offline
                    C Offline
                    cliran
                    wrote on last edited by
                    #34

                    :laugh:

                    1 Reply Last reply
                    0
                    • A asadullah ansari

                      In your project, If you are using if condition like

                      enum
                      {
                      Blue_c,
                      Yellow_c,
                      Red_c
                      };
                      int color;

                      if( color == yellow_c)
                      {
                      .....
                      ......
                      }
                      or
                      if(color != Red_c)
                      {
                      ....
                      .....
                      }

                      Now you know by mistake if you forget one = or ! means if(color = yellow_c) or if(color = Red_c) then no error will come and bug fixing cost for your projects So To avoid this cost you should use

                      if(yellow_c == color)
                      {
                      .....
                      ......
                      }
                      or
                      if(Red_c != color)
                      {
                      ....
                      .....
                      }

                      Now if you forgot to put one = ot ! then compilation error will come.. So this should be in coding standard to use like this...

                      Truth Can'nt be changed

                      J Offline
                      J Offline
                      Julian Nicholls
                      wrote on last edited by
                      #35

                      No, I will never do this. I would leave the job interview if I was 'corrected' on this when I wrote code.

                      1 Reply Last reply
                      0
                      • J Johann Gerell

                        ed welch wrote:

                        Actually, writing if (x = 0) ... does not generate any warning at all (at least in VS 2005).

                        Of course it does. But you have to enable warning level 4 (as I pointed out in the "guideline") in the project property pages under C/C++ > General. Then you get this:

                        warning C4706: assignment within conditional expression

                        If you also set that warnings should be treated as errors, you get this:

                        error C2220: warning treated as error - no 'object' file generated
                        warning C4706: assignment within conditional expression

                        and that way you just cannot miss the assignment.

                        -- Time you enjoy wasting is not wasted time - Bertrand Russel

                        A Offline
                        A Offline
                        asadullah ansari
                        wrote on last edited by
                        #36

                        first thing if programmer is dump then he can make any mistake... No one gud programmer will do this sort of mistake... So Guidelines for stupid programmer only... As u know why this guidlines.. if(0 == x) : should use as guidelines if(x == 0) : should not use why first one is appreciated for stupid programmer coz he may write as if(0 = x) then error will come in this case in all compiler and second one will not give any error in max compiler...What hell this goin on...How any programmer do this mistake??? I cannt believe...

                        Truth Can'nt be changed

                        J 1 Reply Last reply
                        0
                        • A asadullah ansari

                          first thing if programmer is dump then he can make any mistake... No one gud programmer will do this sort of mistake... So Guidelines for stupid programmer only... As u know why this guidlines.. if(0 == x) : should use as guidelines if(x == 0) : should not use why first one is appreciated for stupid programmer coz he may write as if(0 = x) then error will come in this case in all compiler and second one will not give any error in max compiler...What hell this goin on...How any programmer do this mistake??? I cannt believe...

                          Truth Can'nt be changed

                          J Offline
                          J Offline
                          Johann Gerell
                          wrote on last edited by
                          #37

                          The problem with if(0 == x) is that we don't naturally read or write that way. It's Yoda-speak[^]: if x is 0 will become if 0, x is. ;P Unnatural actions have a tendency to not stick naturally.

                          Time you enjoy wasting is not wasted time - Bertrand Russel

                          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