Comments on: Do You Have a Case of var Guilt? https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/ Thu, 14 Jul 2016 19:08:34 +0000 hourly 1 https://wordpress.org/?v=7.0 By: Tion https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-157 Thu, 24 Jun 2010 23:05:35 +0000 https://simpleprogrammer.com/?p=812#comment-157 “Perhaps I just like to repeat myself = new Perhaps I just like to repeat myself.”

Actually made me laugh out loud! thankfully no one is around. Great post!

]]>
By: Andreas Jydebjerg https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-156 Wed, 19 May 2010 08:08:24 +0000 https://simpleprogrammer.com/?p=812#comment-156 For me your caveat says it all. The need for the ide to be able to supply you with the type information is a clear indicator that you need to know the type information. I feel that if you cannot read/write the code without the ide you did something wrong. Don’t get me wrong, I love the ide, I love the productivity gain, but I also love being able to use my skills even with inferior tooling. Personally I’m in agreement with Dejan, using var when the initialization clearly shows you what type your using is fine, but using var for every declaration does in my opinion makes your code harder to read because you have to backtrack to discover what types are in play.

]]>
By: Dan Wygant https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-155 Thu, 13 May 2010 07:55:31 +0000 https://simpleprogrammer.com/?p=812#comment-155 Ok, wild…. even the code definition window will work with the var keyword… bizzzzzarre!

I typically like to click the variable, hit F12, then click the type, and hit Ctl+\+d (control backslash d) to show the type def (frequently from metadata) in the Code Definition Window… or just F12 again.

But I was shocked when I changed Uri to var, hit Ctl+Sh+b (compile) and then hovered over the var … hit Ctl+\+d and there was Uri (from metadata) in the Code Definition Window… what a shocker.

I’m so confused! this seems just wrong from a best-practice standpoint, but totally Rock-N-Roll from the standpoint of how crappy JavaScript is regarding F12. It almost reels C# into VB territory… perhaps we’ll see something interesting now for C# like in VB now with COM interop…. perhaps I’m missing it and this IS it.

Dan “Stoic Strong Type’r” Wygant

]]>
By: jsonmez https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-154 Mon, 10 May 2010 16:39:30 +0000 https://simpleprogrammer.com/?p=812#comment-154 In reply to Dejan Radovic.

Good point, I still wonder in the first case do you actually need to know the type? You really just need to know the methods available on the type. Think about how we use interfaces. The same would apply about someone changing the type.

]]>
By: Dejan Radovic https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-153 Mon, 10 May 2010 16:20:46 +0000 https://simpleprogrammer.com/?p=812#comment-153 There’s no repetition in:
int lastCharIndex = toReverse.Lenght – 1
as opposed to:
Dictionary<int, Dictionary> lookup = new Dictionary<int, Dictionary>();

I’d rather use var in the 2nd case where initialization and declaration match. In the 1st case, the type might not always be evident without using the mouse – like in this example:
var table = GetBindingsTable();

And a second concern about the loose coupling: are you not afraid that one day you’ll get the wrong type because somebody else change a method and the compiler will not warn you just because it happens to have the same public API? I’m afraid that this could introduce subtle bugs…

]]>
By: jsonmez https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-152 Fri, 07 May 2010 18:13:19 +0000 https://simpleprogrammer.com/?p=812#comment-152 In reply to Bruce Lindsay.

Good call! Done!

]]>
By: Bruce Lindsay https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-151 Fri, 07 May 2010 18:05:22 +0000 https://simpleprogrammer.com/?p=812#comment-151 Nice. I can relate to feeling this way at first too. Now it’s time to change your ‘Email Me’ section to use var for your stringbuilder reference!

]]>
By: jsonmez https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-150 Fri, 07 May 2010 12:57:37 +0000 https://simpleprogrammer.com/?p=812#comment-150 In reply to Tim.

Did you just javascript rick roll me? Actually it is pretty interesting to look at it that way without even having the vars. Is the value in immediately knowing on a line if a variable is being delared or not? I’m not sure.

]]>
By: Tim https://simpleprogrammer.com/do-you-have-a-case-of-var-guilt/#comment-149 Fri, 07 May 2010 08:49:41 +0000 https://simpleprogrammer.com/?p=812#comment-149 So, why not:

01 public string reverse(string toReverse)
02 {
03 reversed = “”;
04 lastCharacterIndex = toReverse.Length -1;
05 firstCharacterIndex = 0;
06 for(index = lastCharacterIndex; index >= firstCharacterIndex; index–)
07 {
08 letter = toReverse[index];
09 reversed += letter;
10 }
11
12 return reversed;
13 }

]]>