Re: question on anonymous type
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Sun, 8 Jun 2008 20:45:34 +0100
Arne Vajhøj <arne@xxxxxxxxxx> wrote:
In which case it would be interesting to see whether it becomes more
requested in a few years' time, when those developers have been using
C# 3 and become used to "var". It's too early to take results *now* and
draw any conclusions.
True. It could change.
But I doubt it will happen. It is not exactly a new concept.
It's not a new *concept* but it may be new in *practice* to a lot of
people. Heck, I'd never used a lambda expression in anger until C# 3,
and those have been around for ages too.
I don't even think C# would have gotten it if it had not been for LINQ.
Quite possibly not - but that doesn't mean the feature isn't handy
outside LINQ. Extension methods could be thought of in the same way,
and those *are* on the cards for Java 7.
But if it's obvious when *reading* the code what's going on, the
details only matter when you're looking more deeply into the code.
I don't consider the type a detail in OOP.
I do when it's a matter of skimming code. Do I care whether I'm using
an array or a List<T> if I'm just indexing it? Not really. Do I care
whether something is definitely a LinkedList<T> or any old
IEnumerable<T> if all I'm doing is iterating over it? Not really.
Bear in mind that the declared variable type won't tell you what the
actual type is anyway (unless it's a sealed type) - if you need that
information you've *got* to look to the right hand side of the
assignment. If you're going to do that, how much do you care about the
LHS?
I'm not saying it isn't important information - just that I don't find
it important in certain modes of reading code, and those modes account
for quite a lot of the time I may spend reading code (either for
debugging and trying to get to the critical spot quickly, then
understanding that critical spot in detail, or just getting the flavour
of a class).
But hey, it's definitely a style thing. If you don't like it, that's
fine.
I'm working on a problem, I don't actually need to read most of the
code closely - I'll skim a lot of it. Implicitly typed local variables
help the skimming mode, and arguably slightly harm the detailed part.
I believe many people will want to know the type even for skimming.
Then I believe they won't skim as quickly as they can, for the basic
level of "what's this method trying to achieve?" that I aim for with
skimming.
--
Jon Skeet - <skeet@xxxxxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
.
- References:
- question on anonymous type
- From: timor . super
- Re: question on anonymous type
- From: Jon Skeet [C# MVP]
- Re: question on anonymous type
- From: Arne Vajhøj
- Re: question on anonymous type
- From: Jon Skeet [C# MVP]
- Re: question on anonymous type
- From: Arne Vajhøj
- Re: question on anonymous type
- From: Jon Skeet [C# MVP]
- Re: question on anonymous type
- From: Arne Vajhøj
- Re: question on anonymous type
- From: Jon Skeet [C# MVP]
- Re: question on anonymous type
- From: Arne Vajhøj
- Re: question on anonymous type
- From: Jon Skeet [C# MVP]
- Re: question on anonymous type
- From: Arne Vajhøj
- question on anonymous type
- Prev by Date: Re: C# equivelent of VBA "with..end with" statement
- Next by Date: Re: embedding executable as resource?
- Previous by thread: Re: question on anonymous type
- Next by thread: Re: question on anonymous type
- Index(es):
Relevant Pages
|