|
You wouldn't have been the only one.
|
|
|
|
|
|
Did you ever meet Roger Wilco? He used to be a little star[^].
Quote: The games follow the adventures of a hapless janitor named Roger Wilco as he campaigns through the galaxy for "truth, justice and really clean floors".
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Old Sierra games never disappoint!
GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
So I'm not here to start a holy wvar , but this must be the worst use of var I've ever come across.
var dossier = GetDossier(id); Three guesses what type dossier has?
Trick question, three guesses isn't enough.
It's actually dynamic and going into GetDossier tells me it can be four different types (or null )!
There's actually a switch with some magic number that returns a different model on 1, 2, 3 and 4...
Come to think of it, not only the var is very misleading, it's a bad case of dynamic as well
Not the best code I've come across
|
|
|
|
|
I have met that type of programmer once too often. Or should I say 'barely missed him', as they tend to disappear and leave their works of art for others to clean up.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Well i really avoid var, because i think (yeah even for simple types) you should be able to see what values / types are expected without naming your variable like a scottish dish.
But yeah, this is the wuorst!
Rules for the FOSW ![ ^]
if(!string.IsNullOrWhiteSpace(_signature))
{
MessageBox.Show("This is my signature: " + Environment.NewLine + _signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
I can agree with that. I usually try to limit my use of var to the blatantly obvious such as:
var fileList = new Dictionary<string, FileStream>(); I also find myself using it a lot in foreach iterators where it's easy to deduce what type it is.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
We need an option Strict for C# as well.
|
|
|
|
|
C# is strict by default, dynamic is the Option Strict Off
|
|
|
|
|
I have seen a VB var reused to hold a different variable elsewhere in the code. And the comment the original coder wrote was "reusing a variable, this is really efficient coding".
What a prat.
|
|
|
|
|
I guess it keeps the stack nice and clean
Too bad his comment takes up the resources that his efficient coding saved
|
|
|
|
|
Comments aren't compiled.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
<- sarcasm face...
|
|
|
|
|
I have a strong dislike for var . Makes me guessing the data type while reviewing someone's code. It's a true irritant. May be I'm very old school, but this is how I feel. I cannot look at a variable name without it's data type explicitly specified.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
|
|
|
|
|
I can see why you need var - you can't use Linq properly without it - but it gets used as a lazy "I don't care" variable type which doesn't help comprehension and maintenance at all.
And dynamic I suspect is only there so VB programmers feel at home...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
dynamic is part of the Dynamic Language Runtime, which allows interoperability with loosely typed languages such as Ruby (or so I'm told).
It also comes in handy when using late binding with COM objects.
And I've used it once or twice with some Type<T> where T isn't really important, but can't be deduced, for example List<T>.Count.
var is really only necessary for anonymous types.
|
|
|
|
|
OriginalGriff wrote: you can't use Linq properly without it
You mean stuff like =>
MyModel _currentModel = _myModelList.Find(Mml => Mml.IdModel == InIdOfModel);
?
Yeah, my codestyle might be offending...
Rules for the FOSW ![ ^]
if(!string.IsNullOrWhiteSpace(_signature))
{
MessageBox.Show("This is my signature: " + Environment.NewLine + _signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
Yes, you can use bits of linq without var, but once you get to anonymous types (which is one of it's big strengths) you need var as you can't declare a variable of an anonymous type.
It should have stayed that way: var would have been a whole load better if it only contained anonymous types and null values...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The most offending is your mix of camelCase, PascalCase and underscores in variable names...
|
|
|
|
|
But actually there is a logic behind it
Rules for the FOSW ![ ^]
if(!string.IsNullOrWhiteSpace(_signature))
{
MessageBox.Show("This is my signature: " + Environment.NewLine + _signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
How else do you quickly identify between private, protected, and public? Or properties and fields? Or foos vs bars?
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hungarian notation, of course, but at least properly camelCase and PascalCase them
Unless you're serious, in which case I don't know how to answer that
|
|
|
|
|
Only a little. I like camelCase for javaScript and Pascal for C#, and the only reason I do that is to keep it 100% clear if a variable lives on the client or the server.
Hungarian notation. So gross.
(PS: You could answer it with "Go look at the declaration, fool!")
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Nathan Minier wrote: Hungarian notation
Quote: Linus Torvalds
“Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged – the compiler knows the types anyway and can check those, and it only confuses the programmer.”
Rules for the FOSW ![ ^]
if(!string.IsNullOrWhiteSpace(_signature))
{
MessageBox.Show("This is my signature: " + Environment.NewLine + _signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|