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. Clever Code
  4. if(x=5)

if(x=5)

Scheduled Pinned Locked Moved Clever Code
helpc++comarchitecture
33 Posts 14 Posters 79 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.
  • J jhwurmbach

    [coding standards]

    Kevin McFarlane wrote:

    It should concentrate on more important things

    Like which ways brackets should be placed! :mad: Hating coding style guides and the people that are content in contriving them


    "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

    Z Offline
    Z Offline
    Zac Howland
    wrote on last edited by
    #24

    jhwurmbach wrote:

    Like which ways brackets should be placed!

    Everyone knows they should always be placed on the same line! All your code should look like this:

    if (isTrue()) { for (int i = 0; i < SomeNumber; i++) { int q = i; DosomethingWithQ(q); } PrintSomething(); }
    

    ;P

    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

    J 1 Reply Last reply
    0
    • Z Zac Howland

      Kevin McFarlane wrote:

      Guidelines I've come across usually split into recommended and mandatory. Then the things which people disagree over are put in recommendations. But really guidelines, e.g., for C++, should concentrate on the kind of stuff in Scott Meyers's Effective C++ books.

      I don't disagree with that one bit. Its just been my experience that it hasn't worked out that way (and it should be noted that in the first case, I was the only one who was even vaguely familiar with Meyer's books ... much less Robbins, Sutter, etc). I've even had objections arise when I tried to make a case for always forcing code to compile on the highest warning level with 0 errors/0 warnings before being checked in to version control (which is something I always thought should be a given).

      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      K Offline
      K Offline
      Kevin McFarlane
      wrote on last edited by
      #25

      Zac Howland wrote:

      Its just been my experience that it hasn't worked out that way (and it should be noted that in the first case, I was the only one who was even vaguely familiar with Meyer's books

      According to Francis Glassborow of the Association of C and C++ Users (ACCU), most programmers don't read books on programming, so I'm not surprised. He told me this in an email after he'd wriiteen that he'd lent a colleague Effective C++ and it had been returned unopened.

      Kevin

      Z 1 Reply Last reply
      0
      • Z Zac Howland

        Henize wrote:

        In C# if statments can only evaluate booleans so if(x=5) would not give it a boolean and cause a compiler error.

        Which it "borrowed" from Java ...

        Henize wrote:

        C# is the way of the future.

        Just like you don't use a hammer when you need a screwdriver, you don't use C# (or Java or VB) when you need C++.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

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

        Check out the Microsoft research project called Singularity. Its an operating system written in C#. Around %99 of it(including the kernel) is written in C#.

        Zac Howland wrote:

        Which it "borrowed" from Java ...

        Yes, Java was a good start and had the right idea. C# can do more. .NET allows any language to be compiled to the .NET platform.

        static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y; :omg:

        Z 1 Reply Last reply
        0
        • L Lost User

          In C# if statments can only evaluate booleans so if(x=5) would not give it a boolean and cause a compiler error. C# is the way of the future.

          static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y; :omg:

          W Offline
          W Offline
          WillemM
          wrote on last edited by
          #27

          Henize wrote:

          static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y;

          Talking about errorprone statements ;P btw, I have never thought of that, not even after I had this error happen five times in a 500k lines application. Good tip, will keep that in mind and ask the quality manager to add it to the code convention.

          WM.
          Yaaarrrr What about weapons of mass-construction?

          1 Reply Last reply
          0
          • Z Zac Howland

            jhwurmbach wrote:

            Like which ways brackets should be placed!

            Everyone knows they should always be placed on the same line! All your code should look like this:

            if (isTrue()) { for (int i = 0; i < SomeNumber; i++) { int q = i; DosomethingWithQ(q); } PrintSomething(); }
            

            ;P

            If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #28

            Zac Howland wrote:

            [brackets] Everyone knows they should always be placed on the same line!

            You her a multitude of voices from all directions shouting: "For that you will burn on the stake, heretic!" ;P Thats what is fundamental about coding styles: When you have three programmers together, there are at least four stlyes assembled.


            "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

            Z 1 Reply Last reply
            0
            • K Kevin McFarlane

              Zac Howland wrote:

              Its just been my experience that it hasn't worked out that way (and it should be noted that in the first case, I was the only one who was even vaguely familiar with Meyer's books

              According to Francis Glassborow of the Association of C and C++ Users (ACCU), most programmers don't read books on programming, so I'm not surprised. He told me this in an email after he'd wriiteen that he'd lent a colleague Effective C++ and it had been returned unopened.

              Kevin

              Z Offline
              Z Offline
              Zac Howland
              wrote on last edited by
              #29

              Which explains why there are so many horrible programmers running around getting paid to do their worst ...

              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

              1 Reply Last reply
              0
              • L Lost User

                Check out the Microsoft research project called Singularity. Its an operating system written in C#. Around %99 of it(including the kernel) is written in C#.

                Zac Howland wrote:

                Which it "borrowed" from Java ...

                Yes, Java was a good start and had the right idea. C# can do more. .NET allows any language to be compiled to the .NET platform.

                static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y; :omg:

                Z Offline
                Z Offline
                Zac Howland
                wrote on last edited by
                #30

                Henize wrote:

                Check out the Microsoft research project called Singularity. Its an operating system written in C#. Around %99 of it(including the kernel) is written in C#.

                Sun tried to do this with Java a few years ago. It failed and for good reason.

                Henize wrote:

                Yes, Java was a good start and had the right idea. C# can do more. .NET allows any language to be compiled to the .NET platform.

                Don't get me wrong, there are some nifty features in the .Net framework. That said, managed languages are very limited in their scope of applications. Garbage collection, no matter how efficient the algorithm is, will always be slower than optimizing your memory usage based on how you are using it. I haven't done a whole lot with C#, but I do a lot in Java. C++ is like having a whole general purpose toolbox while Java/C# is like having a nice screwdriver set.

                If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                L 1 Reply Last reply
                0
                • J jhwurmbach

                  Zac Howland wrote:

                  [brackets] Everyone knows they should always be placed on the same line!

                  You her a multitude of voices from all directions shouting: "For that you will burn on the stake, heretic!" ;P Thats what is fundamental about coding styles: When you have three programmers together, there are at least four stlyes assembled.


                  "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                  Z Offline
                  Z Offline
                  Zac Howland
                  wrote on last edited by
                  #31

                  :laugh:;Phehe ... sorry, just couldn't resist

                  If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                  1 Reply Last reply
                  0
                  • Z Zac Howland

                    Henize wrote:

                    Check out the Microsoft research project called Singularity. Its an operating system written in C#. Around %99 of it(including the kernel) is written in C#.

                    Sun tried to do this with Java a few years ago. It failed and for good reason.

                    Henize wrote:

                    Yes, Java was a good start and had the right idea. C# can do more. .NET allows any language to be compiled to the .NET platform.

                    Don't get me wrong, there are some nifty features in the .Net framework. That said, managed languages are very limited in their scope of applications. Garbage collection, no matter how efficient the algorithm is, will always be slower than optimizing your memory usage based on how you are using it. I haven't done a whole lot with C#, but I do a lot in Java. C++ is like having a whole general purpose toolbox while Java/C# is like having a nice screwdriver set.

                    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

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

                    The Singularity project is going quite well. It is very interesting, check it out.

                    static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y; :omg:

                    Z 1 Reply Last reply
                    0
                    • L Lost User

                      The Singularity project is going quite well. It is very interesting, check it out.

                      static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<>=1)>0); return y; :omg:

                      Z Offline
                      Z Offline
                      Zac Howland
                      wrote on last edited by
                      #33

                      Henize wrote:

                      The Singularity project is going quite well. It is very interesting, check it out.

                      When they produce an OS that is both stable and efficient enough to compete with a native OS, then I'll look more into it. As it stands right now, it is just another in a line of attempts to use "lazy languages" to do things they weren't designed for. I've seen this fail twice in the past (with both Sun and Microsoft).

                      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                      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