var abuse
-
Ah, I wondered what happened to the generics bit on my OP How is it sloppy and lazy?
You know what the variable type is, so declare it!
Pete
-
You know what the variable type is, so declare it!
Pete
Why? What is the point of repeating information?
-
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
Peter Mulholland wrote:
It's F***in sloppy, lazy sh*t!
:thumbsup:
----------------------------- Just along for the ride. -----------------------------
-
Ah, I wondered what happened to the generics bit on my OP How is it sloppy and lazy?
Coming from a C++ background, I feel it doesn't improve the readability of the code, particularly when used to accept a return value from a method. In my experience, those that like it overuse and abuse it. It was a mistake to add it to the C# language.
Pete
-
Coming from a C++ background, I feel it doesn't improve the readability of the code, particularly when used to accept a return value from a method. In my experience, those that like it overuse and abuse it. It was a mistake to add it to the C# language.
Pete
I come from a C++ background too and I like var - I agree using it to accept a return value from a method is a poor use of it.
-
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!The 'why' is because the type is already there in the line, so using var doesn't remove any information. Personally I only use it very rarely but that's a matter of style, I think it is fine when the type is in the line anyway (either as a new expression or an explicit cast:
var something = (TypeName)expression
). -
I'm so pissed of by
var
abusers. They do not understand that are making code unreadable, for what, writingvar
instead ofstring
? 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!
Reason for my 1 vote: There is nothing wrong with that. If you need to get the type, just hover over the 'var' in the IDE.
-
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
Well put. Exactly why I do NOT use handholding tools like Reshaper. Clearly their definition of 'problems' is very subjective, and personally does not suite me. I write the code exactly how I want it!
-
Reason for my 1 vote: There is nothing wrong with that. If you need to get the type, just hover over the 'var' in the IDE.
Meanwhile I'm reading the code I can't constantly hover the vars! Com'on, how can you say that??? :)
And this is the lounge, I'm not discussing about what should be a good practice, I lament about things that makes me piss off.
-
Meanwhile I'm reading the code I can't constantly hover the vars! Com'on, how can you say that??? :)
And this is the lounge, I'm not discussing about what should be a good practice, I lament about things that makes me piss off.
Mario Majcica wrote:
Meanwhile I'm reading the code I can't constantly hover the vars!
Use Reflector then :) If the code is well written, you should be able to infer the type while reading. What does get me is the person using 'var' instead of 'object', now that is silly. :)
-
Coming from a C++ background, I feel it doesn't improve the readability of the code, particularly when used to accept a return value from a method. In my experience, those that like it overuse and abuse it. It was a mistake to add it to the C# language.
Pete
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
-
Why? What is the point of repeating information?
Many people don't know what C#'s
var
means. They incorrectly think it's not type-safe! :-)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
-
Well put. Exactly why I do NOT use handholding tools like Reshaper. Clearly their definition of 'problems' is very subjective, and personally does not suite me. I write the code exactly how I want it!
leppie wrote:
I write the code exactly how I want it!
So the bugs are deliberate?
-
Many people don't know what C#'s
var
means. They incorrectly think it's not type-safe! :-)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
I haven't looked at it enough to concern myself with whether or not it's type safe. I don't think it aids code readability, and I've never found a situation where I needed to use it.
Pete
-
Reason for my 1 vote: There is nothing wrong with that. If you need to get the type, just hover over the 'var' in the IDE.
-
Reason for my 1 vote: There is nothing wrong with that. If you need to get the type, just hover over the 'var' in the IDE.
I can't hover over it when it's printed on a page, posted in a message here, displayed by someone else on a big screen in a meeting, etc.
-
I'm so pissed of by
var
abusers. They do not understand that are making code unreadable, for what, writingvar
instead ofstring
? 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!
GAH! I don't need to see that when I first wake up in the morning! What were you thinking, man? Post it later in the day. :~ But I certainly agree with you.
-
GAH! I don't need to see that when I first wake up in the morning! What were you thinking, man? Post it later in the day. :~ But I certainly agree with you.
Healing my frustrations here!
-
leppie wrote:
I write the code exactly how I want it!
So the bugs are deliberate?
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:
-
I haven't looked at it enough to concern myself with whether or not it's type safe. I don't think it aids code readability, and I've never found a situation where I needed to use it.
Pete
Peter Mulholland wrote:
I don't think it aids code readability, and I've never found a situation where I needed to use it.
You absolutely need it with anonymous types, and it's more than handy with LINQ where you know it's returning some collection but don't know or care what type it is.
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