|
|
I have to admit I use single characters for linq but I do at least try to to use the first letter of the object type (Person => p) etc.
I am not a big fan of var. I think it encourages lazy programming, though used well it makes sense.
|
|
|
|
|
Quote: I am not a big fan of var. I think it encourages lazy programming, though used well it makes sense. Rarely is the "var" keyword used as it was intended. I blame this on lazy programmers blindly following ReSharper's suggestion to replace every single variable declaration with "var".
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
Dominic Burford wrote: blindly following ReSharper's suggestion to replace every single variable declaration with "var" At that suggestion I removed ReSharper for good...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Dominic Burford wrote: blindly following ReSharper's suggestion to replace every single variable declaration with "var".
My Resharper doesn't do that, and I don't think I've changed any of the defaults
Even obvious stuff like:
string message = string.Format("Error in xyz method: {0}", ex.Message);
doesn't get flagged by it.
|
|
|
|
|
thought someone would mention this (but then read the dislike of var )
With
return source.Select(t => new
{
Index = rand.Next(),
Value = t
})
What is 't' short for? Table?
With loops, 'i' and 'x' (I assume) come from iterator and Maths use of variables.
(then subsequently y follows from 'x')
with linq, it is a sort of replacement for the item working on.
In the case above 'source'
so maybe 's' or 'src' if 'source' is too long to type.
|
|
|
|
|
Because LINQ is evil.
Regards,
Rob Philpott.
|
|
|
|
|
Hear hear!
I may not last forever but the mess I leave behind certainly will.
|
|
|
|
|
I could have told you 20 years ago that that's a battle you're certain to lose.
But I guess you know that by now.
Kitty at my foot and I waAAAant to touch it...
|
|
|
|
|
Lambdas are exactly the same - thousands of inline functions all called f()...
(Some people still think that Maths is the only metaphor in IT[^] )
modified 12-Aug-15 5:41am.
|
|
|
|
|
What! You can use more than one letter?
|
|
|
|
|
Oh oh, I think he's complaining about me
|
|
|
|
|
|
If it's a single lambda parameter, and its use is limited to a few lines, I nearly always only use a one char parameter, like:
var bachelors = _people.Where(p => !p.IsMarried);
I'm also a one letter man with basic loops. i and j all the way.
No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
|
|
|
|
|
Brady Kelly wrote: var bachelors = _people.Where(p => !p.IsMarried);
Generally, that's how I code, also. I specifically don't code that way when the LINQ code involves joins across a series of sources/tables. The
(a,b)=>
can get really messy, esp. if you need
(a,b)=> new {}
multiple times.
vuolsi così colà dove si puote
ciò che si vuole, e più non dimandare
--The answer to Minos and any question of "Why are we doing it this way?"
|
|
|
|
|
I think everyone is right here. The var keyword was put in specifically for LINQ. Yes - it does introduce a chance to code sloppy. Its a trade off. I like to use LINQ to slice over CSV Files, and other such collection queries.
I don't like var though, outside on its own, without a leash.
Where there's smoke, there's a Blue Screen of death.
|
|
|
|
|
Well, I wouldn't say you're TOO grumpy though I always considered those three (i,j,k) to be reserved as loop variants (Ever since FORTRAN IV) and still only use 'em for that even in my C# code!
Yeah, variable names ought to be a bit more descriptive!
|
|
|
|
|
This isn't isolated to LINQ. You see the same behavior in for/foreach loops as well. The only time I use single letters is when the variable is for an index.
Scott E. Corbett
|
|
|
|
|
I agree with you on the first Select because there's a little complexity in that lambda, but for the OrderBy and second Select, its one line of code, and if it isn't obvious what the parameter represents and how its being used, then a longer variable name isn't going to help the reader much.
Personally, for those one-liners, I prefer the simple 'p' argument -- less for my eye to read and my brain to parse (and ignore), which means I reach understanding of the code a lot faster.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
I have always attributed this to the "it's a sample" mentatility. In samples you variables named myObj and newVar and stuff. You should not name things like that in production code, and neither should you use single letter small scope variables.
While I have seen both in production code (really, you named the search parameters myString?), I discourage their use (even in linq) in favor of more descriptive names. Perhaps we should insist on better quality examples for teaching these technologies to help instill better habits in new and learning programmers.
|
|
|
|
|
Yes, you are but so am I. I guess that linq is all about lazyness, don't you think?
Instead of using single char variable names I mostly use a short descriptive name for the type like 'car' or 'person'.
In this case I'd use 'ivpair' instead of sortItem, since the OrderBy is clear enough for me. Also 'item' adds no more clarity than 'i' or 't' because the item type is irrelevant for sorting.
The lazyness is IMHO encouraged by the numerous examples available and course exercises; they tend to save on keystrokes and sacrifice maintainance. Can't change the world though...
|
|
|
|
|
I program 30+ years. 30+ years before I'd start programming, i,j,k,n were well known cycle counter variables for one page code.
|
|
|
|
|
Update: Maintenance done, and we're now just waiting and watching SQL spool back up. things may be slow for a a couple of hours but after that we should be good to go.
We're adding the final touches to our migration to a new hosting centre which requires a rebuild of our database server. To make this easy and painless for the poor souls involved we're going to go read-only for 2-3 hrs while the maintenance is completed. We're hoping it'll all be done by 9pm US Eastern tonight.
I'll update this as soon as we have progress.
cheers
Chris Maunder
modified 11-Aug-15 20:54pm.
|
|
|
|
|
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|