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.
  • V Vark111

    OriginalGriff wrote:

    Coming soon: "On Error Resume Next"

    What do you mean "coming soon"? It's already there:

    try
    {
        //some op
    }
    catch {}
    
    B Offline
    B Offline
    Bergholt Stuttley Johnson
    wrote on last edited by
    #41

    I did know a programmer that did just that, first thing he wrote in any method class etc was a try catch block in which he put all his code, and yes it had a empty catch oh and he was a ex-VB programmer too was soooo proud his code never threw exceptions

    You cant outrun the world, but there is no harm in getting a head start Real stupidity beats artificial intelligence every time.

    1 Reply Last reply
    0
    • L leppie

      viaducting wrote:

      So the bugs are deliberate?

      What bugs? ;P But in reality, I loathe typing, so I try code correctly the first time. I dont mind spending 90% of my time figuring out the entire solution mentally. You type less, and debug almost never :) Or maybe that is just how I work :rolleyes:

      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

      B Offline
      B Offline
      Bergholt Stuttley Johnson
      wrote on last edited by
      #42

      Sorry "Undocumented features"

      You cant outrun the world, but there is no harm in getting a head start Real stupidity beats artificial intelligence every time.

      1 Reply Last reply
      0
      • V Vark111

        OriginalGriff wrote:

        Coming soon: "On Error Resume Next"

        What do you mean "coming soon"? It's already there:

        try
        {
            //some op
        }
        catch {}
        
        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #43

        Takes too much typing for most idiots:

            Bitmap GetScreen()
                {
                try {Rectangle screenRegion = Screen.AllScreens\[0\].Bounds;} catch{}
                try {Bitmap grab = new Bitmap(SystemInformation.PrimaryMonitorSize.Width,
                                              SystemInformation.PrimaryMonitorSize.Height,
                                              PixelFormat.Format32bppArgb);} catch{}
                using (Graphics screenGraphics = Graphics.FromImage(grab))
                    {
                    try {screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);} catch{}
                    }
                return grab;
                }
        

        With resume next, you just add it once and walk away - until the problem is so big it bites you on the ass and you have no idea where it started... X|

        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!

          L Offline
          L Offline
          Luca Leonardo Scorcia
          wrote on last edited by
          #44

          While your example is clearly awful, I find myself using it quite consistently recently. It helps a lot with lambdas, nested generics and similar verbose type definitions. Guess it's just a language feature like the others. My personal rule is to use it only for complex (more than 1 type parameter) generic types. I'm a heavy Resharper user, but that var rule is the first one I turn off. The second one is the 'Warning on unnecessary this.' rule. Guess it's time to introduce your colleagues to FxCop :) Cheers!

          Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

          M 1 Reply Last reply
          0
          • L Luca Leonardo Scorcia

            While your example is clearly awful, I find myself using it quite consistently recently. It helps a lot with lambdas, nested generics and similar verbose type definitions. Guess it's just a language feature like the others. My personal rule is to use it only for complex (more than 1 type parameter) generic types. I'm a heavy Resharper user, but that var rule is the first one I turn off. The second one is the 'Warning on unnecessary this.' rule. Guess it's time to introduce your colleagues to FxCop :) Cheers!

            Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

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

            I need the machine that on StyleCop warning hits the responsible person with a bat! :)

            L 1 Reply Last reply
            0
            • M Mario Majcica

              I need the machine that on StyleCop warning hits the responsible person with a bat! :)

              L Offline
              L Offline
              Luca Leonardo Scorcia
              wrote on last edited by
              #46

              That's just fine, I'm completely irresponsible :-\ ;)

              Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

              1 Reply Last reply
              0
              • N Nish Nishant

                Peter Mulholland wrote:

                It was a mistake to add it to the C# language.

                C++ has it too now, it's called auto.

                auto x = SomeFunc();

                Regards, Nish


                Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com

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

                Wonderful, and I thought the C++ code I've been looking at for 3 years couldn't get any worse. Now it can.

                Pete

                N 1 Reply Last reply
                0
                • P Peter Mulholland

                  Wonderful, and I thought the C++ code I've been looking at for 3 years couldn't get any worse. Now it can.

                  Pete

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #48

                  :-D

                  Regards, Nish


                  Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com

                  1 Reply Last reply
                  0
                  • H hairy_hats

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

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #49

                    FYI, List takes a generic parameter.

                    Driven to the ARMs by x86.

                    1 Reply Last reply
                    0
                    • L leppie

                      BobJanova wrote:

                      It's nice to be able to read the code without hovering the mouse over things.

                      Knowing the type is not really necessary if the code is unambiguous. Just replace the type with some type 'Foo' with a property of 'Bar'. Now if we have 10 types, all with a property 'Bar', yeah then it gets shitty. :)

                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

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

                      There are a lot of 'Bars' in the real world though ... Close, Draw, Update, Refresh etc.

                      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