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. Best Programming Advice Ever.

Best Programming Advice Ever.

Scheduled Pinned Locked Moved The Lounge
phpcomtoolsquestion
36 Posts 22 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.
  • Brian C HartB Brian C Hart

    That point is irrelevant. I am talking about seeing this in high performance scientfic codes where a single function can be thousands of lines long. Makes the code fairly hard to understand if all the tmp variables happen to be one letter, trust me.

    Sincerely Yours, Brian Hart

    S Offline
    S Offline
    supercat9
    wrote on last edited by
    #24

    I am talking about seeing this in high performance scientfic codes where a single function can be thousands of lines long. There is nothing wrong, IMHO, with using trivial variable names in cases where the scope of the variable is short and its meaning can be entirely gleaned from context. A classic example:

    For I As Integer = 1 To 40
    Item.Dat(I) = 0
    Next

    Would using any name other than "I" make things clearer? Of how about something like:

    Dim st As String
    st = GetSomeData();
    If Not String.IsNullOrEmpty(st) Then
    DoSomethingWith(st)
    Endif

    Would any name other than "st" be more helpful?

    N Brian C HartB 2 Replies Last reply
    0
    • C clearbrian1

      Just do what apple do. Create a platform...IPOD/IPHONE They only change 3 things every 6 months..(Email forwarding (cmon we all know that took a day to write))..have a big macworld announcement and the starving clients will praise you forever. :) 6 bugs /year...think thats a programmers best average? :)

      G Offline
      G Offline
      goodideadave
      wrote on last edited by
      #25

      clearbrian1 wrote:

      6 bugs /year...think thats a programmers best average?

      Jeez, if I only create six bugs per hour, I'm having a helluva day. :sigh:

      Someone's gotta be the last to know, but why is it always me?

      J 1 Reply Last reply
      0
      • P Philip Laureano

        Clickety[^] :)

        Do you know...LinFu?

        D Offline
        D Offline
        Drozzy
        wrote on last edited by
        #26

        link dead :(

        N 1 Reply Last reply
        0
        • G goodideadave

          clearbrian1 wrote:

          6 bugs /year...think thats a programmers best average?

          Jeez, if I only create six bugs per hour, I'm having a helluva day. :sigh:

          Someone's gotta be the last to know, but why is it always me?

          J Offline
          J Offline
          John M Drescher
          wrote on last edited by
          #27

          goodideadave wrote:

          Jeez, if I only create six bugs per hour, I'm having a helluva day.

          Per hour, you are probably programming too fast. Are you counting failed compiles/syntax type errors? I don't consider that a bug.

          John

          G 1 Reply Last reply
          0
          • J John M Drescher

            goodideadave wrote:

            Jeez, if I only create six bugs per hour, I'm having a helluva day.

            Per hour, you are probably programming too fast. Are you counting failed compiles/syntax type errors? I don't consider that a bug.

            John

            G Offline
            G Offline
            goodideadave
            wrote on last edited by
            #28

            Wow, I have never been accused of coding too fast before, usually it's just the opposite...

            Someone's gotta be the last to know, but why is it always me?

            1 Reply Last reply
            0
            • J Jane Williams

              It did have positive benefits back in the early days of COBOL, punched cards, and things like that. Anything that saved memory was a good thing. You know, like 2-digit years.... hmmm... Yes, I have attempted to maintain programs from that era. Two-letter variable names and labels, many hundreds of gotos, even more hundred alter-gotos. Having done so, let me add something to that original advice. 2) If you use 1 or 2 letter variable names, do not leave your name in the comments at the top of the code to say what you did. 2a) Especially if one of the programmers who will read it, a few decades later, is your own daughter. She DOES know where you live.

              N Offline
              N Offline
              Naruki 0
              wrote on last edited by
              #29
              1. Leave someone else's name in the comments. Preferably your PHB's name.

              Don't let my name fool you. That's my job.

              1 Reply Last reply
              0
              • D destynova

                Dave Parker wrote:

                At the place where I used to work the guy who was there before me made *every* variable a global (this is in VB6) and would start with the name AAA and work his way upwards :-s

                Now that's a master coder.

                N Offline
                N Offline
                Naruki 0
                wrote on last edited by
                #30

                If you accidentally hired him, do not make any sudden moves. ;P

                Don't let my name fool you. That's my job.

                1 Reply Last reply
                0
                • D destynova

                  KungFuCoder wrote:

                  I just settle for calling them tmpStr tmpInt etc so I know.

                  It's better than nothing I suppose, unless you're using a statically typed language, in which case it's completely useless (e.g. "int tmpInt" is redundant and a waste of brain/finger time).

                  N Offline
                  N Offline
                  Naruki 0
                  wrote on last edited by
                  #31

                  In my very short scope example, most likely so, but not for the reason you say. The fact that the compiler will catch a mistake does not make it easier to read and understand. A short scope of 10 lines or less means we don't really need to care what it is. But if you are evaluating 20 different boolean results over the course of a 100+ line function, you might not want to spend a lot of time thinking of 20 meaningful but distinct names. tmpBool would do just fine.

                  Don't let my name fool you. That's my job.

                  1 Reply Last reply
                  0
                  • S supercat9

                    I am talking about seeing this in high performance scientfic codes where a single function can be thousands of lines long. There is nothing wrong, IMHO, with using trivial variable names in cases where the scope of the variable is short and its meaning can be entirely gleaned from context. A classic example:

                    For I As Integer = 1 To 40
                    Item.Dat(I) = 0
                    Next

                    Would using any name other than "I" make things clearer? Of how about something like:

                    Dim st As String
                    st = GetSomeData();
                    If Not String.IsNullOrEmpty(st) Then
                    DoSomethingWith(st)
                    Endif

                    Would any name other than "st" be more helpful?

                    N Offline
                    N Offline
                    Naruki 0
                    wrote on last edited by
                    #32

                    supercat9 wrote:

                    Would any name other than "st" be more helpful?

                    Try 'str'. :-D Because I'd keep thinking "street? What's street got to do with this?"

                    Don't let my name fool you. That's my job.

                    1 Reply Last reply
                    0
                    • D Drozzy

                      link dead :(

                      N Offline
                      N Offline
                      Naruki 0
                      wrote on last edited by
                      #33

                      I guess he linked like the person clicking was a deranged serial killer, and he didn't want him to know where he lived.

                      Don't let my name fool you. That's my job.

                      1 Reply Last reply
                      0
                      • S supercat9

                        I am talking about seeing this in high performance scientfic codes where a single function can be thousands of lines long. There is nothing wrong, IMHO, with using trivial variable names in cases where the scope of the variable is short and its meaning can be entirely gleaned from context. A classic example:

                        For I As Integer = 1 To 40
                        Item.Dat(I) = 0
                        Next

                        Would using any name other than "I" make things clearer? Of how about something like:

                        Dim st As String
                        st = GetSomeData();
                        If Not String.IsNullOrEmpty(st) Then
                        DoSomethingWith(st)
                        Endif

                        Would any name other than "st" be more helpful?

                        Brian C HartB Offline
                        Brian C HartB Offline
                        Brian C Hart
                        wrote on last edited by
                        #34

                        Agreed. Certainly nothing wrong at all with "using trivial variable names in cases where the scope of the variable is short and its meaning can be entirely gleaned from context," as you say, and I quote.

                        Sincerely Yours, Brian Hart

                        1 Reply Last reply
                        0
                        • D destynova

                          Brian Hart wrote:

                          That point is irrelevant. I am talking about seeing this in high performance scientfic codes where a single function can be thousands of lines long. Makes the code fairly hard to understand if all the tmp variables happen to be one letter, trust me.

                          I'll tell you what makes the code fairly hard to understand: having a single function which is thousands of lines long. This is idiotic and completely unnecessary - we've had procedures and functions and other abstractions since before colour TV, and their main use is to prevent thousand line functions from ever existing. IMO, tiny variable names are okay if you have quite short functions, which you really should anyway.

                          T Offline
                          T Offline
                          tsdragon
                          wrote on last edited by
                          #35

                          "I'll tell you what makes the code fairly hard to understand: having a single function which is thousands of lines long." You can say that again!!! If at all possible I try not to have a function that goes over the number of lines that will fit comfortably in one screen of my programming editor.

                          Meddle not in the affairs of dragons, For you are crunchy, and good with mustard.

                          1 Reply Last reply
                          0
                          • P Philip Laureano

                            Clickety[^] :)

                            Do you know...LinFu?

                            C Offline
                            C Offline
                            CDMTJX
                            wrote on last edited by
                            #36

                            Thanks - had to laugh and print it out for my wall. The worst offenders of hard to maintain seem to be people who aren't programming in old dusty code where good practice (comments, well named variables) are lifelines to what was done and why. Or a consulting engineer who refused to comment code because he said comments were always wrong - out of date - see the code! And wrote frightfully elegant code that was very difficult to figure out.

                            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