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. AARRGGHHHH!!!!!

AARRGGHHHH!!!!!

Scheduled Pinned Locked Moved The Lounge
comfunctionalquestion
58 Posts 27 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.
  • P Pete OHanlon

    Try doing a code review in Crucible where someone's abused var and then see how you feel about that. ;)

    P Offline
    P Offline
    Paul Benson
    wrote on last edited by
    #34

    Interesting discussion. I found var a bit difficult to cope with at first as it does hide the actual type. Fortunately many IDEs will, as has been pointed out elsewhere, give you the type if you hover over the 'var'. This, however, doesn't help when dealing with printed/quoted code snippets or when working in an environment that doesn't reveal the type. So, my definition of 'appropriate' is where the type is obvious (usually because the assignment includes the type as part of a 'new' or a typecast of some kind) or because the type is so complicated that it obfuscates itself (e.g. nested generics with multiple parameters). In the latter case I either rely on VS for an explanation or, where possible, simplify the type by creating a new wrapper class/struct with XML help to explain what the class is about. The basic rule is "Think about other people when writing your code." Always ask yourself 'Can this be understood without having to look through reams of code or relying on an IDE to find variable/type definitions?' If not can it be simplified or explained?" If all else fails use a comment to explain (and thereby starts another argument :sigh: ).

    F 1 Reply Last reply
    0
    • J Jorgen Andersson

      So you like assembly? Everything else is just reducing the amount of code you need to type.

      Wrong is evil and must be defeated. - Jeff Ello

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

      Really? Writing (perhaps) a lable, an opcode and typically 0 - 2 operands actually looks quite spartan to me. Also, you have the single most important abstraction at your disposal: Structuring your code in subroutines or functions. The biggest bonus: There is little room for religious wars over styles or language features.

      The language is JavaScript. that of Mordor, which I will not utter here
      This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
      "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

      J 1 Reply Last reply
      0
      • M Mladen Jankovic

        I am. Why the hell not? It's more aesthetically pleasing and in most cases it does not reduce readability (for me, for you - don't care). I haven't use it much in C# before C++11 assigned new meaning to auto. Then I started replacing crap like this std::unordered_map<std::string, boring_class>::const_iterator with auto and then moved the habit to C#.

        Commodore 64 emulator for Windows Phone

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

        Well ok, if it's some shitty long name it makes sense. If it's int or similar, it does not.

        1 Reply Last reply
        0
        • S Slacker007

          harold aptroot wrote:

          There's a school of thought that it is applicable any time it is allowed.

          I use ReSharper a lot, and it will ask you everytime it can to use implicit type declaration. So, I can see why some devs out there may think that it is good for everything. However, I have debugged code files that have had "var" all over the place, and it has not been an issue. If for some reason, I cannot tell the type, then hovering over "var" will tell you.

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

          Slacker007 wrote:

          f for some reason, I cannot tell the type, then hovering over "var" will tell you.

          Yes, it will - but that wastes time and breaks the "flow" when reading the code. An explicit declaration is always clearer - particularly when it's to hold a method return value:

          var myVar = GetSomething();

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          "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
          • L Lost User

            Really? Writing (perhaps) a lable, an opcode and typically 0 - 2 operands actually looks quite spartan to me. Also, you have the single most important abstraction at your disposal: Structuring your code in subroutines or functions. The biggest bonus: There is little room for religious wars over styles or language features.

            The language is JavaScript. that of Mordor, which I will not utter here
            This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
            "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #38

            It would obviously depend on what you're doing, but let's just say that I wouldn't enjoy writing a website from scratch in assembly.

            Wrong is evil and must be defeated. - Jeff Ello

            L 1 Reply Last reply
            0
            • J Jorgen Andersson

              It would obviously depend on what you're doing, but let's just say that I wouldn't enjoy writing a website from scratch in assembly.

              Wrong is evil and must be defeated. - Jeff Ello

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

              Who enjoys writing websites in the first place?

              The language is JavaScript. that of Mordor, which I will not utter here
              This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
              "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

              J 1 Reply Last reply
              0
              • L Lost User

                Who enjoys writing websites in the first place?

                The language is JavaScript. that of Mordor, which I will not utter here
                This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #40

                It's a job. :sigh:

                Wrong is evil and must be defeated. - Jeff Ello

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  JimmyRopes wrote:

                  They unify the way many various things are accessed

                  To the lowest common, and therefore the least efficient, method possible. And it's unreadable.

                  S Offline
                  S Offline
                  Slacker007
                  wrote on last edited by
                  #41

                  PIEBALDconsult wrote:

                  And it's unreadable.

                  When done correctly, it is very readable and strongly encouraged in all of our software teams. However, I have seen it done poorly, which validates your comment, IMO.

                  1 Reply Last reply
                  0
                  • L Lost User

                    No. I will not rely on some IDE to tell me what my code means. Often enough the IDE is too busy showing me hysterical error messages or the parser got lost a little further up in the code and simply is not able to provide any useful information anymore. Second, especially when I have to work with complex baseclasses, I tend to use some good oldschool printouts of those baseclasses as reference. I tried using intellisense on a printout, but the result always was a classic 'Funny, no response!'. Third. I don't hover, not even when flying a helicopter.

                    The language is JavaScript. that of Mordor, which I will not utter here
                    This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                    "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                    S Offline
                    S Offline
                    Slacker007
                    wrote on last edited by
                    #42

                    Interesting view points. ;)

                    L 1 Reply Last reply
                    0
                    • L Lost User

                      No. I will not rely on some IDE to tell me what my code means. Often enough the IDE is too busy showing me hysterical error messages or the parser got lost a little further up in the code and simply is not able to provide any useful information anymore. Second, especially when I have to work with complex baseclasses, I tend to use some good oldschool printouts of those baseclasses as reference. I tried using intellisense on a printout, but the result always was a classic 'Funny, no response!'. Third. I don't hover, not even when flying a helicopter.

                      The language is JavaScript. that of Mordor, which I will not utter here
                      This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                      "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                      S Offline
                      S Offline
                      Sentenryu
                      wrote on last edited by
                      #43

                      CDP1802 wrote:

                      or the parser got lost a little further up in the code and simply is not able to provide any useful information anymore.

                      after saying that you really think you are in position to say that var is a problem? you just said you write code that the machine that will compile and run it can't understand.

                      L 1 Reply Last reply
                      0
                      • S Sentenryu

                        CDP1802 wrote:

                        or the parser got lost a little further up in the code and simply is not able to provide any useful information anymore.

                        after saying that you really think you are in position to say that var is a problem? you just said you write code that the machine that will compile and run it can't understand.

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

                        No. When the parser is a little upset and confused, the code will not compile. Nor will it be able to provide me with some of the information I may need to correct this. In this situation I prefer not having to rely on intellisense.

                        The language is JavaScript. that of Mordor, which I will not utter here
                        This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                        "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                        1 Reply Last reply
                        0
                        • S Slacker007

                          Interesting view points. ;)

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

                          Actually I have nothing against hovering with a helicopter. It's just because I gave a friend the nickname 'Hoverfly' because he keeps practicing hovering and did not want to carefully start flying around. Last weekend he did and crashed his helicopter and has been repairing since then. Now I can't just say that hovering is ok, or he will never try again.

                          The language is JavaScript. that of Mordor, which I will not utter here
                          This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                          "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                          1 Reply Last reply
                          0
                          • V V 0

                            There's a synonym for "punching bag". It's called "colleagues". Knock yourself one out! ;P

                            V.
                            (MQOTD rules and previous solutions)

                            G Offline
                            G Offline
                            GuyThiebaut
                            wrote on last edited by
                            #46

                            V. wrote:

                            Knock yourself one out!

                            Not sure if you intended to, or did so by mistake, but that phrase has a very particular meaning. Maybe type the phrase into google images and click on the I'm feeling lucky button :~

                            “That which can be asserted without evidence, can be dismissed without evidence.”

                            ― Christopher Hitchens

                            V 1 Reply Last reply
                            0
                            • P Paul Benson

                              Interesting discussion. I found var a bit difficult to cope with at first as it does hide the actual type. Fortunately many IDEs will, as has been pointed out elsewhere, give you the type if you hover over the 'var'. This, however, doesn't help when dealing with printed/quoted code snippets or when working in an environment that doesn't reveal the type. So, my definition of 'appropriate' is where the type is obvious (usually because the assignment includes the type as part of a 'new' or a typecast of some kind) or because the type is so complicated that it obfuscates itself (e.g. nested generics with multiple parameters). In the latter case I either rely on VS for an explanation or, where possible, simplify the type by creating a new wrapper class/struct with XML help to explain what the class is about. The basic rule is "Think about other people when writing your code." Always ask yourself 'Can this be understood without having to look through reams of code or relying on an IDE to find variable/type definitions?' If not can it be simplified or explained?" If all else fails use a comment to explain (and thereby starts another argument :sigh: ).

                              F Offline
                              F Offline
                              Fabio Franco
                              wrote on last edited by
                              #47

                              Couldn't agree more with you. I would also like to add that even if you have Visual Studio it interrupts reading and interpreting the code. Making it harder to understand for someone that is reading the code for the first time. I blame ReSharper for the fever of using var everywhere. That's the argument of many: "Oh, but Resharper says to use var everywhere". I wish I knew who at ReSharper dev team decided it was a good thing.

                              To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                              P 1 Reply Last reply
                              0
                              • M Mladen Jankovic

                                I am. Why the hell not? It's more aesthetically pleasing and in most cases it does not reduce readability (for me, for you - don't care). I haven't use it much in C# before C++11 assigned new meaning to auto. Then I started replacing crap like this std::unordered_map<std::string, boring_class>::const_iterator with auto and then moved the habit to C#.

                                Commodore 64 emulator for Windows Phone

                                F Offline
                                F Offline
                                Fabio Franco
                                wrote on last edited by
                                #48

                                Hardly the rule and only applicable for complex names. Now, people use it on method returns and everywhere. I happen to be in a position that I have to read a lot of other people's code and it's a pain to read them when var is used everywhere. On generic types it's even more disrupting.

                                To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                1 Reply Last reply
                                0
                                • S Slacker007

                                  Thank you. Exactly.

                                  F Offline
                                  F Offline
                                  Fabio Franco
                                  wrote on last edited by
                                  #49

                                  How often do you have to declare stuff like in C++ std::unordered_map::const_iterator? It's hardly the rule. If you're declaring

                                  Tuple, KeyValuePair>

                                  or something like that, maybe it makes sense. But more often than not, it doesnt.

                                  To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                  1 Reply Last reply
                                  0
                                  • M Marc Clifton

                                    I absolutely despise when people say "oh, I'm using this because it reduces the amount of code I have to type". F**** me. If you don't like typing, why are you a programmer? I need a punching bag in my home-office. Marc

                                    Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                                    F Offline
                                    F Offline
                                    Fabio Franco
                                    wrote on last edited by
                                    #50

                                    F*** me too. And Resharper that says lazy mode var is a good thing. :mad:

                                    To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                    1 Reply Last reply
                                    0
                                    • G GuyThiebaut

                                      V. wrote:

                                      Knock yourself one out!

                                      Not sure if you intended to, or did so by mistake, but that phrase has a very particular meaning. Maybe type the phrase into google images and click on the I'm feeling lucky button :~

                                      “That which can be asserted without evidence, can be dismissed without evidence.”

                                      ― Christopher Hitchens

                                      V Offline
                                      V Offline
                                      V 0
                                      wrote on last edited by
                                      #51

                                      I didn't know :doh:

                                      V.
                                      (MQOTD rules and previous solutions)

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        I absolutely despise when people say "oh, I'm using this because it reduces the amount of code I have to type". F**** me. If you don't like typing, why are you a programmer? I need a punching bag in my home-office. Marc

                                        Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                                        G Offline
                                        G Offline
                                        Gerald Gardner
                                        wrote on last edited by
                                        #52

                                        If I liked typing I'd have been a typist. If I could write code without typing at all I would. BTW: I almost exclusively use "var" and see little wrong with it. I guess I'm an "implied typist"! :laugh: But I also use bigLongVariableNames, because that's where the real value of all those extra characters comes in.

                                        9 1 Reply Last reply
                                        0
                                        • P PIEBALDconsult

                                          JimmyRopes wrote:

                                          They unify the way many various things are accessed

                                          To the lowest common, and therefore the least efficient, method possible. And it's unreadable.

                                          J Offline
                                          J Offline
                                          JimmyRopes
                                          wrote on last edited by
                                          #53

                                          PIEBALDconsult wrote:

                                          To the lowest common, and therefore the least efficient, method possible.

                                          Is this just speculation or can you cite data to back up your psition?

                                          PIEBALDconsult wrote:

                                          And it's unreadable.

                                          I, personally, find this a lot more readable than the alternative.

                                          XDocument xml = XDocument.Load(Environment.GetEnvironmentVariable("SystemDrive") + @"\manifest.xml");

                                                      var oledbconn = from el in xml.Root.Elements("webservice")
                                                                      where el.Attribute("name").Value == ServiceName
                                                                      select el.Element("OleDbConnection").Value;
                                                      OleDbConnectionString = oledbconn.FirstOrDefault();
                                          

                                          You, of course, are entitled to your opinion.

                                          Once you lose your pride the rest is easy. In the end, only three things matter: how much you loved, how gently you lived, and how gracefully you let go of things not meant for you. – Buddha Simply Elegant Designs JimmyRopes Designs

                                          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