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. var abuse

var abuse

Scheduled Pinned Locked Moved The Lounge
question
50 Posts 17 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.
  • M Offline
    M Offline
    Mario Majcica
    wrote on last edited by
    #1

    I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

    var metadataValues = new List<object>();
    foreach (var metadataDefName in metadataDefNames)
    {
    var name = metadataDefName;
    // Search definition with the same name.
    var metadata = metadataCollection.FirstOrDefault(
    metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
    ...

    Cheers!

    R R P OriginalGriffO P 8 Replies Last reply
    0
    • M Mario Majcica

      I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

      var metadataValues = new List<object>();
      foreach (var metadataDefName in metadataDefNames)
      {
      var name = metadataDefName;
      // Search definition with the same name.
      var metadata = metadataCollection.FirstOrDefault(
      metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
      ...

      Cheers!

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      I suppose it depends upon how you intend to use it but that does seem a little lazy if you know what the type will be beforehand. var (C# Reference)[^]

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      H 1 Reply Last reply
      0
      • R R Giskard Reventlov

        I suppose it depends upon how you intend to use it but that does seem a little lazy if you know what the type will be beforehand. var (C# Reference)[^]

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        H Offline
        H Offline
        hairy_hats
        wrote on last edited by
        #3

        var is good for LINQ but I'd avoid it in most other places for clarity.

        M 1 Reply Last reply
        0
        • M Mario Majcica

          I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

          var metadataValues = new List<object>();
          foreach (var metadataDefName in metadataDefNames)
          {
          var name = metadataDefName;
          // Search definition with the same name.
          var metadata = metadataCollection.FirstOrDefault(
          metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
          ...

          Cheers!

          R Offline
          R Offline
          RugbyLeague
          wrote on last edited by
          #4

          var list = new List(); is good var x = GetStuff(); is not good

          H M P 3 Replies Last reply
          0
          • R RugbyLeague

            var list = new List(); is good var x = GetStuff(); is not good

            H Offline
            H Offline
            hairy_hats
            wrote on last edited by
            #5

            List list=new List(); is only one extra character to type, and is clearer IMO.

            R A 2 Replies Last reply
            0
            • R RugbyLeague

              var list = new List(); is good var x = GetStuff(); is not good

              M Offline
              M Offline
              Mario Majcica
              wrote on last edited by
              #6

              And why? I can understand some cases in which you want to make code more compact, as

              List myName = new List();

              to use a

              var myName = new List();

              or as mentioned before in cases that you do not know the return type. But using always var only because of laziness, just pisses me of!

              R B 2 Replies Last reply
              0
              • H hairy_hats

                var is good for LINQ but I'd avoid it in most other places for clarity.

                M Offline
                M Offline
                Mario Majcica
                wrote on last edited by
                #7

                I totally agree with you. And when people start abusing of var makes me go raging bull!

                1 Reply Last reply
                0
                • H hairy_hats

                  List list=new List(); is only one extra character to type, and is clearer IMO.

                  R Offline
                  R Offline
                  RugbyLeague
                  wrote on last edited by
                  #8

                  Declarations get a lot more complex than that and it is wasteful to repeat it on both sides.

                  1 Reply Last reply
                  0
                  • M Mario Majcica

                    And why? I can understand some cases in which you want to make code more compact, as

                    List myName = new List();

                    to use a

                    var myName = new List();

                    or as mentioned before in cases that you do not know the return type. But using always var only because of laziness, just pisses me of!

                    R Offline
                    R Offline
                    RugbyLeague
                    wrote on last edited by
                    #9

                    I agree. It has its uses but also its abuses

                    1 Reply Last reply
                    0
                    • M Mario Majcica

                      I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

                      var metadataValues = new List<object>();
                      foreach (var metadataDefName in metadataDefNames)
                      {
                      var name = metadataDefName;
                      // Search definition with the same name.
                      var metadata = metadataCollection.FirstOrDefault(
                      metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
                      ...

                      Cheers!

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      Or you are using ReSharper and tell it to autofix the "problems" in your code.

                      Forgive your enemies - it messes with their heads

                      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                      M L 2 Replies Last reply
                      0
                      • M Mario Majcica

                        I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

                        var metadataValues = new List<object>();
                        foreach (var metadataDefName in metadataDefNames)
                        {
                        var name = metadataDefName;
                        // Search definition with the same name.
                        var metadata = metadataCollection.FirstOrDefault(
                        metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
                        ...

                        Cheers!

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

                        It's VB creep: The bits of VB that mean that you don't have to think about what you are doing are slowly being introduced to C#. Coming soon: "On Error Resume Next" Then it will be time to go back to C++ because C# will be mostly used by lazy idiots who don't care a fig for maintenance.

                        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

                        M F V 3 Replies Last reply
                        0
                        • P Pete OHanlon

                          Or you are using ReSharper and tell it to autofix the "problems" in your code.

                          Forgive your enemies - it messes with their heads

                          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                          M Offline
                          M Offline
                          Mario Majcica
                          wrote on last edited by
                          #12

                          Is there a function in ReSharper that teaches up colleagues not doing it? :) I tried in many ways to explain why of some practices, even tried to make them read the book as http://www.amazon.com/Practical-Guidelines-Practices-Developers-Pro-Developer/dp/0735621721[^] but nothing. The most difficult think is to convince people to change! But without the passion for your job, it is a difficult task (to change).

                          1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            It's VB creep: The bits of VB that mean that you don't have to think about what you are doing are slowly being introduced to C#. Coming soon: "On Error Resume Next" Then it will be time to go back to C++ because C# will be mostly used by lazy idiots who don't care a fig for maintenance.

                            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."

                            M Offline
                            M Offline
                            Mario Majcica
                            wrote on last edited by
                            #13

                            I think you're right. But I hope not! Recently I helped on a badly written project in VB.NET and it was a nightmare.

                            1 Reply Last reply
                            0
                            • OriginalGriffO OriginalGriff

                              It's VB creep: The bits of VB that mean that you don't have to think about what you are doing are slowly being introduced to C#. Coming soon: "On Error Resume Next" Then it will be time to go back to C++ because C# will be mostly used by lazy idiots who don't care a fig for maintenance.

                              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."

                              F Offline
                              F Offline
                              Firo Atrum Ventus
                              wrote on last edited by
                              #14

                              OriginalGriff wrote:

                              Coming soon: "On Error Resume Next"

                              I thought it was "On Error GoTo Hell" Oh well, I never attend VB class in the second year of my high school

                              You can flame me whichever way you want and I wouldn't care a bit. But if you group me with some idiots, I'll turn into your worst nightmare.

                              OriginalGriffO 1 Reply Last reply
                              0
                              • F Firo Atrum Ventus

                                OriginalGriff wrote:

                                Coming soon: "On Error Resume Next"

                                I thought it was "On Error GoTo Hell" Oh well, I never attend VB class in the second year of my high school

                                You can flame me whichever way you want and I wouldn't care a bit. But if you group me with some idiots, I'll turn into your worst nightmare.

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

                                :laugh: No, Resume Next is much more damaging in the long term!

                                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
                                • M Mario Majcica

                                  I'm so pissed of by var abusers. They do not understand that are making code unreadable, for what, writing var instead of string? Having the same problems in your company? ex.

                                  var metadataValues = new List<object>();
                                  foreach (var metadataDefName in metadataDefNames)
                                  {
                                  var name = metadataDefName;
                                  // Search definition with the same name.
                                  var metadata = metadataCollection.FirstOrDefault(
                                  metadataDef => String.Equals(metadataDef.MetaData.Name, name, StringComparison.OrdinalIgnoreCase));
                                  ...

                                  Cheers!

                                  P Offline
                                  P Offline
                                  Peter Mulholland
                                  wrote on last edited by
                                  #16

                                  I agree, I've seen code here with var used everywhere (C#), complained to the SW Architect, he sent out an email saying it sould only be used where required. It's the newest, youngest guy in the place using it most. It's F***in sloppy, lazy sh*t!

                                  Pete

                                  S 1 Reply Last reply
                                  0
                                  • R RugbyLeague

                                    var list = new List(); is good var x = GetStuff(); is not good

                                    P Offline
                                    P Offline
                                    Peter Mulholland
                                    wrote on last edited by
                                    #17

                                    RugbyLeague wrote:

                                    var list = new List();
                                     
                                    is good

                                    WTF!!! IList<string> list = new List<string>(); // is good (your < and > hid the string bit (I think)) List<string> list = new List<string>(); // is good var list = new List<string>(); // is sloppy, lazy sh1t!

                                    Pete

                                    R 1 Reply Last reply
                                    0
                                    • P Peter Mulholland

                                      RugbyLeague wrote:

                                      var list = new List();
                                       
                                      is good

                                      WTF!!! IList<string> list = new List<string>(); // is good (your < and > hid the string bit (I think)) List<string> list = new List<string>(); // is good var list = new List<string>(); // is sloppy, lazy sh1t!

                                      Pete

                                      R Offline
                                      R Offline
                                      RugbyLeague
                                      wrote on last edited by
                                      #18

                                      Ah, I wondered what happened to the generics bit on my OP How is it sloppy and lazy?

                                      P 2 Replies Last reply
                                      0
                                      • R RugbyLeague

                                        Ah, I wondered what happened to the generics bit on my OP How is it sloppy and lazy?

                                        P Offline
                                        P Offline
                                        Peter Mulholland
                                        wrote on last edited by
                                        #19

                                        You know what the variable type is, so declare it!

                                        Pete

                                        R 1 Reply Last reply
                                        0
                                        • P Peter Mulholland

                                          You know what the variable type is, so declare it!

                                          Pete

                                          R Offline
                                          R Offline
                                          RugbyLeague
                                          wrote on last edited by
                                          #20

                                          Why? What is the point of repeating information?

                                          N 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