var abuse
-
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
-
It's nice to be able to read the code without hovering the mouse over things. And one might not be in an IDE at the time.
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. :)
-
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."
-
OriginalGriff wrote:
Coming soon: "On Error Resume Next"
What do you mean "coming soon"? It's already there:
try { //some op } catch {}
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.
-
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:
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.
-
OriginalGriff wrote:
Coming soon: "On Error Resume Next"
What do you mean "coming soon"? It's already there:
try { //some op } catch {}
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'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!
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
-
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
I need the machine that on StyleCop warning hits the responsible person with a bat! :)
-
I need the machine that on StyleCop warning hits the responsible person with a bat! :)
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
-
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
Wonderful, and I thought the C++ code I've been looking at for 3 years couldn't get any worse. Now it can.
Pete
-
Wonderful, and I thought the C++ code I've been looking at for 3 years couldn't get any worse. Now it can.
Pete
:-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
-
List list=new List();
is only one extra character to type, and is clearer IMO.FYI, List takes a generic parameter.
Driven to the ARMs by x86.
-
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. :)