The curley bracket!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #31
    Originally posted by sicarie
    Yeah, yours definitely looks cleaner.

    /me ponders going off on discussion about code obfuscation and how it relates to job security....
    Someone beat you to it.

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #32
      Originally posted by Motoma
      That's going in my bookmarks, right next to The Daily WTF.

      Comment

      • tolkienarda
        Contributor
        • Dec 2006
        • 316

        #33
        ok i use the right method of currly braces and comments

        Code:
        if($somthin = 'somthing')
        {
            with indented code here;//short same line comments
           $i++;//easy add and standard counter
        /*
        with big jolly multi line comments here about the following code and about the program in general and maybe even some credits as to who helped me write it or if i am posting the script for people to use i put my name on it
        now the reason i do this with proper indention being important is because python dosen't even use the curly braces just indentation and right now i don't know python but sometime when i am not working and doing classes every night i will lean it, and this summer my friend can teach me some
        */
        }
        the reason i do that is because of the coolest teacher at my high school was sick or figuring out what everyone's code does so she made us comment and indent that way also if we coppied other peoples code she knew we at least understood it cause we had to comment them.

        now if you have looked at my code in the posts you can see i have gotten lazy but this is the methodology i belive in.

        eirc

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #34
          Originally posted by Motoma
          That's a great link

          Comment

          • AricC
            Recognized Expert Top Contributor
            • Oct 2006
            • 1885

            #35
            Originally posted by sicarie
            That's going in my bookmarks, right next to The Daily WTF.
            Great link! A good way to lose your job or get stuck supporting some POS

            Comment

            • tsgomez
              New Member
              • Feb 2007
              • 12

              #36
              Using only i++ can get you in trouble. Due to compiler differences, the i might be incremented at a different time than you intend.

              post and pre...in C++ it's normally thought that you apply the incremention in relation to the index in the order that you see it.

              For instance:
              Code:
              int index = 0;
              test[index] = temp[index++];
              Some compilers will assign the value of temp at index 1 to test index 0. Upon completion, the variable index would still be 0.

              Other compilers, especially olders ones, will assign the value of temp at index 1 to test index 0, BUT, on completion, the value of the variable index would be 1 (due to the index++). In these cases, you would have to re-write the code as follows:

              Code:
              int index = 0;
              test[index] = temp[++index]
              There's an article about this on the Web somewhere, sorry i don't have the link at the moment.


              Using index+=1 is easy, but it's not as clear. From a readability standpoint, using index = index+1 is best.


              Note: I personally use index+=1

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #37
                So effectively, the language should be referred to as C+=1
                :-)

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #38
                  Originally posted by Killer42
                  So effectively, the language should be referred to as C+=1
                  :-)
                  Depends on the implementation of operator++ and the typeof(C);

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #39
                    Originally posted by Killer42
                    So effectively, the language should be referred to as C+=1
                    :-)
                    Actually as C = C + 1;

                    Comment

                    • Tuanisviet
                      New Member
                      • Jan 2007
                      • 37

                      #40
                      I prefer the way of

                      if(...)
                      {
                      //blah blah blah
                      }


                      I'd rather sacrifice a few lines of white space for neatly packaged methods & if statements & the ability to find them easily.


                      speaking of i++ & index++... anyone heard of ii instead of i++?

                      Comment

                      • DeMan
                        Top Contributor
                        • Nov 2006
                        • 1799

                        #41
                        I would imagine that could majorly confuse things (especially given some old naming conventions)

                        Comment

                        • stroken
                          New Member
                          • Mar 2007
                          • 24

                          #42
                          Originally posted by AricC
                          Here is another debate what do you like:

                          intIndex++

                          Or

                          intIndex += 1

                          I prefer the +=

                          Aric
                          You should use the prefix-version, ++intIndex. It is faster.

                          Comment

                          • stroken
                            New Member
                            • Mar 2007
                            • 24

                            #43
                            Originally posted by stroken
                            You should use the prefix-version, ++intIndex. It is faster.
                            Perhaps I should explain why:

                            Postfix ++ (i++) needs to copy the object first, then increment the original, then return the copy. You get the overhead of a copy of the object.

                            Prefix ++ (++i) just needs to increment the object and then return a reference to it. No copy is needed.

                            Comment

                            • AnthonyScaife
                              New Member
                              • Feb 2007
                              • 7

                              #44
                              I prefer:

                              Code:
                              if (databaseGotUpdated)
                              {   updateCount++;
                                  clearDisplay();
                                  renderNewTable();
                              }
                              I like:
                              - The style of indentation
                              - camelHumpStyle names rather than with_under_scor es
                              - ++
                              - Functions in the style verbAdjectiveNo un() in plain English

                              What does everyone else think ? ( "what a pedant !" ? )

                              Comment

                              • AricC
                                Recognized Expert Top Contributor
                                • Oct 2006
                                • 1885

                                #45
                                Originally posted by stroken
                                You should use the prefix-version, ++intIndex. It is faster.
                                With the speeds of PC processing these days I wouldn't think this is a big factor. Do you any have proof?

                                Comment

                                Working...