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. Programming isn't hard...

Programming isn't hard...

Scheduled Pinned Locked Moved The Lounge
66 Posts 31 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.
  • Sander RosselS Sander Rossel

    I just went for item. And yes, it is to remain abstract. It is an Interface Method that has a T (as in generic) as a parameter. That is the reason I did not want to go for obj. Because the parameter is of type T, which is more specific than an Object.

    It's an OO world.

    public class Naerling : Lazy<Person>{}

    B Offline
    B Offline
    BobJanova
    wrote on last edited by
    #48

    void DoSomethingGeneric(T t){ ... } If it's just any T, with no further restrictions, the fact it is a 'T' is the only thing that identifies it, so I'd call it 't'. The fact that it's a T that something is done with should be clear from the method name.

    1 Reply Last reply
    0
    • H Henry Minute

      This is a particularly stupid tip and would never work. Apart from the fact that it would require superhuman mental gymnastics, once you have more than 42 variables, in order to maintain alphabetic ordering, it is yet another invidious ploy by the militant fundamentalist wing of the ASL (Anti-Southpaw League). Please remember that The Lounge is no place for these religious outpourings.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #49

      I agree. Since all the syntactic characters are on the other side of the keyboard (parens, braces, semicolon, equals and single quote; double quote too for Americans), clearly variable names ought to use exclusively the right side of the keyboard (p0, p9, p8, ... p5, o0, ... etc).

      1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        Thinking of names for your classes and variables, THAT's hard... :doh: Frustration #1 of the evening... :sigh:

        It's an OO world.

        public class Naerling : Lazy<Person>{}

        R Offline
        R Offline
        radioman lt
        wrote on last edited by
        #50

        it's easy when you coding some useless crap, real programming never was easy and will never be :~

        d{^__^}b - it's time to fly

        Sander RosselS 1 Reply Last reply
        0
        • R radioman lt

          it's easy when you coding some useless crap, real programming never was easy and will never be :~

          d{^__^}b - it's time to fly

          Sander RosselS Offline
          Sander RosselS Offline
          Sander Rossel
          wrote on last edited by
          #51

          It's called irony :)

          It's an OO world.

          public class Naerling : Lazy<Person>{}

          1 Reply Last reply
          0
          • _ _beauw_

            When Black and Scholes were figuring out how to value options, though, they probably were using one- and two-letter variable names, and they ended up winning the Nobel Prize. Maybe the difference is that people don't have to "maintain" mathematics. There was a movie where Leo DiCaprio (or maybe Matt Damon?) was a maintenance man who did mathematics... but that's a different story. :-D

            A Offline
            A Offline
            adudley256
            wrote on last edited by
            #52

            I always get those two mixed up, made watching The Departed very difficult to begin with :)

            1 Reply Last reply
            0
            • I Ian Shlasko

              Dijkstra didn't have to debug an option valuation model written in C++ by a math PhD... True story... Almost every variable in the Black-Scholes calculation was one or two letters long, and none of them had any relevance to what they represented. Don't get me wrong... It (mostly) worked, and it was fast, but... Ow, my eyes!

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              M Offline
              M Offline
              Mike Winiberg
              wrote on last edited by
              #53

              I know what you mean - my colleague (who writes the B-S module for his option pricing program (which I maintain)) loves names like henry, peter, peterp, peter2 etc - I'm just glad I don't have to work on that bit of code. I used to employ a programmer who was very good, and very hard working, but he never used any kind of meaningful names for anything, so a complex C function representing, say, a vector drawing interpreter, would contain tens of variables named a,aa,aaa,aaa, x,xx,xxx,xxxx, i,ii,iii,iiii,iiiii and so forth... 8)

              1 Reply Last reply
              0
              • Q QuiJohn

                Ian Shlasko wrote:

                Tenagra t = new Tenagra(); t.Add(new Darmok()); t.Add(new Jilad()); t.Add(new TheBeast()); t.EpicBattle(); t.MoveItemsTo(new Ocean());

                Congratulations, this is the nerdiest thing I have read this month, on many levels. And considering the crap I read, that was an achievement.

                M Offline
                M Offline
                Mike Winiberg
                wrote on last edited by
                #54

                Temba(his)::arms(wide){} ;P

                1 Reply Last reply
                0
                • _ _beauw_

                  This is Dijkstra's opinion, not mine! But I think he would tell you that mathematicians get by with X, Y, theta, pi, etc., and that programming is just a species of mathematics. After all, Einstein didn't discover that realEnergy = realMass * [ (squareRootOfTheSpeedOfLight)² ] Rather, he was just fine with E=mc², and (amazingly, if all you know is programming) people still embraced his findings.

                  S Offline
                  S Offline
                  StarNamer work
                  wrote on last edited by
                  #55

                  _beauw_ wrote:

                  After all, Einstein didn't discover that
                  realEnergy = realMass * [ (squareRootOfTheSpeedOfLight)² ]

                  He didn't.

                  realEnergy = realMass * [ (theSpeedOfLightInVacuum)² ]

                  FTFY

                  1 Reply Last reply
                  0
                  • Sander RosselS Sander Rossel

                    Thinking of names for your classes and variables, THAT's hard... :doh: Frustration #1 of the evening... :sigh:

                    It's an OO world.

                    public class Naerling : Lazy<Person>{}

                    A Offline
                    A Offline
                    ARBebopKid
                    wrote on last edited by
                    #56

                    Back in College in 1995, a friend was working on his first RPG program. "What should I call this Dumaflopper?" He asked out loud. I said, "You know, you should just call every program this semester Dumaflopper." He did. Every assignment he turned in was dumaflopper.rpg.

                    Sander RosselS 1 Reply Last reply
                    0
                    • I Ian Shlasko

                      OriginalGriff wrote:

                      Star Fleet don't seem to have any truck with H&S legislation, or they wouldn't fill all the computer consoles with semtex...

                      Yeah, I always wondered why it was that they could manage matter-energy conversion, subspace communication, and warp drive... But couldn't seem to figure out how to make a surge protector or... *gasp*... a FUSE!

                      Proud to have finally moved to the A-Ark. Which one are you in?
                      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                      A Offline
                      A Offline
                      austin hamman
                      wrote on last edited by
                      #57

                      i always wondered that myself, its like they shunted warp plasma to run a frikken computer screen, and dont have anything to manage power surges. i think the poor ensigns on the terminals would rather have to switch a breaker than have their console explode in their face and kill them. while on the subject: seatbelts. how many poor ensigns and redshirts have met their fate from being thrown across the bridge and breaking their neck. seatbelts save lives, or at least save you from having to go back to a star base to get more troops. "darmok and jalad at tanagra" "i dont understand" "DARMOK AND JALAD AT TANAGRA!" great episode.

                      1 Reply Last reply
                      0
                      • _ _beauw_

                        This is Dijkstra's opinion, not mine! But I think he would tell you that mathematicians get by with X, Y, theta, pi, etc., and that programming is just a species of mathematics. After all, Einstein didn't discover that realEnergy = realMass * [ (squareRootOfTheSpeedOfLight)² ] Rather, he was just fine with E=mc², and (amazingly, if all you know is programming) people still embraced his findings.

                        B Offline
                        B Offline
                        bkebamc
                        wrote on last edited by
                        #58

                        Yes, but the reason he got away with E = mc2 is because physicists had, over the course many years, established conventions for the use of the symbols. A programmer must establish conventions in application domains that they are making up as they are going along. Ouch!

                        1 Reply Last reply
                        0
                        • _ _beauw_

                          Yeah, it's true. The theme of many of Dijkstra's arguments was that natural language is a poor vehicle for discussing problems in computation, and his writing style seems at times to be intended to prove this assertion! I have read through his "Meaningful Identifiers" paper, though, and in summary, his basic point seems to be that attempting to give variables descriptive natural language names is a trap. A natural language name can never truly express what a variable is, fundamentally, or what it does, only provide hints. Because these natural language names are subjective and ambiguous, a danger occurs when people (e.g. maintenance programmers) attempt to extract meaning from them instead of just reading the code, e.g.

                          #define max_subscript 4

                          //...

                          int some_array[max_subscript];

                          The declaration at the end of this snippet implies that the name max_subscript is actually an inaccurate description. The real maximum subscript is 3. But in order to detect this, one must 1) be familiar with C syntax and 2) actually see and consider this declaration (versus simply seeing the incorrectly named constant used elsewhere). As a result, we would be better off if max_subscript were simply called M (or iLikeFishTacos, brett_favre, etc.) Dijkstra's argument seems sound, but in practice I do give my identifiers meaningful natural-language names, because people expect this. It's not difficult to extend Dijkstra's argument about identifier names to comments as well... consider the following:

                          void a_function()
                          {
                          int * a = new int; //Allocate "a" on the stack

                          //...

                          }//All that stuff we allocated on the stack gets cleaned up automatically here

                          Again, this is a simplistic example (that int isn't on the stack and it won't get cleaned up automatically). Hopefully, though, the message is clear: we'd actually be better off without those supposedly helpful comments. As an experienced programmer, I have suffered through a few scenarios where an inaccurate comment actually did slow me down. However, I must be careful to point out that none of these extreme positions reflect my own personal programming practice... (although I do think that developers should at least acquaint themselves with Dijkstra's argument).

                          P Offline
                          P Offline
                          patbob
                          wrote on last edited by
                          #59

                          _beauw_ wrote:

                          .. his basic point seems to be that attempting to give variables descriptive natural language names is a trap. A natural language name can never truly express what a variable is, fundamentally, or what it does, only provide hints.

                          Sounds to me like Dijkstra completely missed the point of giving natural language names to variables. It isn't to try to describe the variable and its every nuance, it's to provide a mnemonic word or phrase that triggers the memory in the programmer's head of what what the variable holds and its every nuance. For a few, single letters suffice, for the rest of us, a word or phrase works better. Einstein's E=mc2 is a perfect example of mnemonics. "E" stands for energy, "m" for mass and "c" is the standard mnemonic letter used to represent the speed of light. His variable choice wasn't random, it was mnemonic. Pretty amazing it actually works as a mnemonic for us non-mathematician/non-physicist types too. The max_subscript example is bad because the mnemonic itself triggers a misunderstanding, which then fights with the true understanding.

                          We can program with only 1's, but if all you've got are zeros, you've got nothing.

                          1 Reply Last reply
                          0
                          • A ARBebopKid

                            Back in College in 1995, a friend was working on his first RPG program. "What should I call this Dumaflopper?" He asked out loud. I said, "You know, you should just call every program this semester Dumaflopper." He did. Every assignment he turned in was dumaflopper.rpg.

                            Sander RosselS Offline
                            Sander RosselS Offline
                            Sander Rossel
                            wrote on last edited by
                            #60

                            Where they flops too? :laugh:

                            It's an OO world.

                            public class Naerling : Lazy<Person>{}

                            R 1 Reply Last reply
                            0
                            • A AspDotNetDev

                              I prefer to call all my variables a1, a2, a3, a4, and so on. Also, once I get to a6, I use another letter (say, b1)... that way, I only ever have to use my left hand and can keep my right hand on the mouse. It's a very efficient technique I wish everybody else would adopt. Until then, I just refactor all the code I see with overly long variable names like "count" (that's a particularly bad name because some of the characters require the right hand to type). I sleep easily at night, comfortable in the knowledge that all my refactoring has made the world a better place. :-\

                              Somebody in an online forum wrote:

                              INTJs never really joke. They make a point. The joke is just a gift wrapper.

                              R Offline
                              R Offline
                              Rob Grainger
                              wrote on last edited by
                              #61

                              Saving the right hand for better uses?

                              1 Reply Last reply
                              0
                              • Sander RosselS Sander Rossel

                                Where they flops too? :laugh:

                                It's an OO world.

                                public class Naerling : Lazy<Person>{}

                                R Offline
                                R Offline
                                Rob Grainger
                                wrote on last edited by
                                #62

                                Naerling wrote:

                                Where they flops too?

                                Wow, he's going for the record in grammatical errors in 4 words ;-)

                                Sander RosselS 1 Reply Last reply
                                0
                                • R Rob Grainger

                                  Naerling wrote:

                                  Where they flops too?

                                  Wow, he's going for the record in grammatical errors in 4 words ;-)

                                  Sander RosselS Offline
                                  Sander RosselS Offline
                                  Sander Rossel
                                  wrote on last edited by
                                  #63

                                  Were* And that's the only one I can find... But let's see how well your Dutch grammar is :) Als je durft ;p (yeah, translate that!)

                                  It's an OO world.

                                  public class Naerling : Lazy<Person>{}

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    _beauw_ wrote:

                                    The declaration at the end of this snippet implies that the name max_subscript is actually an inaccurate description.

                                    I would agree, but that isn't a fault of the naming convention. Rather, it is a fault of the coder: max_subscript is wrong, and doesn't describe what the constant is used for: max_elements_count would have been better (or max_whatevertheheckthearrayholds_count even better still) For me, the problem is I grew up with Fortran, where a line of code was 80 characters, and variables were a max of six characters. Generally names were impenetrable, short and unrelated to the use. So, when I can I use "proper" names for things, because it means I can read the code in six months time and stand a vague chance of working out how it works. :laugh:

                                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                                    J Offline
                                    J Offline
                                    jsc42
                                    wrote on last edited by
                                    #64

                                    When I learnt Algol60 (no limit on variable names) after several years of writing FORTRAN IV / 66 (max 6 chars in variable names), our lecturer said we had to use long, meaningful identifiers and I failed to see what the advantage was. So, for an assessed piece of work, I used 80-char identifiers (as identifiers could not be broken across cards) causing even simple assignments to straddle multiple cards and to render the whole program totally unintelligible. [Using whole cards per identifier did make coding easy - I could just duplicate the cards rather than having to retype the identifier wherever it was used] I also submitted a legible version using short identifiers. The lecturer was not impressed.

                                    OriginalGriffO 1 Reply Last reply
                                    0
                                    • J jsc42

                                      When I learnt Algol60 (no limit on variable names) after several years of writing FORTRAN IV / 66 (max 6 chars in variable names), our lecturer said we had to use long, meaningful identifiers and I failed to see what the advantage was. So, for an assessed piece of work, I used 80-char identifiers (as identifiers could not be broken across cards) causing even simple assignments to straddle multiple cards and to render the whole program totally unintelligible. [Using whole cards per identifier did make coding easy - I could just duplicate the cards rather than having to retype the identifier wherever it was used] I also submitted a legible version using short identifiers. The lecturer was not impressed.

                                      OriginalGriffO Offline
                                      OriginalGriffO Offline
                                      OriginalGriff
                                      wrote on last edited by
                                      #65

                                      :laugh: I can't imagine why not!

                                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                      1 Reply Last reply
                                      0
                                      • OriginalGriffO OriginalGriff

                                        _beauw_ wrote:

                                        The declaration at the end of this snippet implies that the name max_subscript is actually an inaccurate description.

                                        I would agree, but that isn't a fault of the naming convention. Rather, it is a fault of the coder: max_subscript is wrong, and doesn't describe what the constant is used for: max_elements_count would have been better (or max_whatevertheheckthearrayholds_count even better still) For me, the problem is I grew up with Fortran, where a line of code was 80 characters, and variables were a max of six characters. Generally names were impenetrable, short and unrelated to the use. So, when I can I use "proper" names for things, because it means I can read the code in six months time and stand a vague chance of working out how it works. :laugh:

                                        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                                        B Offline
                                        B Offline
                                        Brady Kelly
                                        wrote on last edited by
                                        #66

                                        Reminds me of my SAP days, relatively recently, where table identifiers were normally four character acronyms, and field names six characters , both often based on the original German names. After a surprisingly short while I found these very easy to remember and use, considering we coded in a line editor without Intellisense.

                                        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