|
I think for man it's natural to think in sequence where->what->description to what
In c# declaration
long amount = obj.GetAmount();
sequence is
description to what->what->where
in modern var declaration
var amount = obj.GetAmount();
sequence is
what->where
'description to what' is missing and man usually have to use mouse to see what are the result type.
As for me i like c# for strong types, not for freedom haos as in Php
|
|
|
|
|
If you really think it's implemented like VB's Object. Really.
Typelessness is not the same thing as type inference.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
5'd. And just to add, C# 4.0 does have the dynamic keyword, which is similar to the old Object or VARIANT types.
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
ReSharper suggests using var all over the place. I find that I've gravitated to using it anywhere the type can be implied.
The cool thing about var is that is reduces the britleness of your code - arguments and return types can easily be switched between various implementations, and less underlying code breaks. It is also nice when using in "as" type conversions.
Get used to using var (and use ReSharper) you'll be glad you did.
Dale Thompson
|
|
|
|
|
Yes, but it makes C# look like javascript. Let's put a $ sign in front of every variable to make it look like PHP then. Besides strong types are recommended for function parameters. Lazy coding not always pays off in the long run.
|
|
|
|
|
@nsimeonov : well you can't use var as a parameter , var should have a value when you create it !
you can't do something like this
var x;
x = 1;
but you can do something like and it will be treated like an int at runtime
var x = 1;
|
|
|
|
|
I'm not sure I'm all that convinced by the brittleness of code argument. I can see that it would help slightly as all local scope variables returning off a refactored function would not have to be changed. let's all lobby for a typedef keyword
|
|
|
|
|
Don't use var in a program that doesn't otherwise rely on features that were introduced in .net 3.0 (e.g. Anonymous Types).
A .net program should compile on as many versions of the framework as practical. I'm not saying you shouldn't use Generics, Anonymous Types, or Extension Methods; if you use them, that's fine. But var is really just an enabling technology; it enables the use of Anonymous Types. If you're not using Anonymous Types, then you don't need var .
If you write an Awesome Class and publish it here, someone may want to use it, that's the whole point of publishing. If that person is limited to .net 2.0 and your code contains var , but no other .net 3.x and C# 3.0 features, he will have to edit your code to replace all those needless var s. The same goes for Extension Methods; use them sparingly.
The main point here is to consider future users of the code. You yourself may change jobs and be limited in what versions you can use.
Make the most with the least.
modified on Tuesday, August 18, 2009 1:02 PM
|
|
|
|
|
...as long as you use VS2008 with .NET 2.0 targetting.
Dale Thompson
|
|
|
|
|
Yes, but not C# 2.0 -- var is a feature of C#.
|
|
|
|
|
No doubt those who are comfortable with functional languages such as F# and Scala, with their pervasive type inference, are right at home with var in C#.
Kevin
|
|
|
|
|
who was voted for that, i didnt know an CCtrlList is it a modificated version of an CListCtrl?
do i need some updates?
|
|
|
|
|
They should have written:
var ctrl=new CListCtrl();
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
It turns out to be very useful with LINQ - which is the only place I use it.
The ambiguity issues about the type (i.e., readability) are reasonable concerns. My consolation, when I use it, is that it's existence is only for LINQ, and only real declarations are made elsewhere.
Alas - one further cavaet: I rarely use C# to begin with, as C++ is lingua franca of the discerning programmer.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"It's a sad state of affairs, indeed, when you start reading my tag lines for some sort of enlightenment. Sadder still, if that's where you need to find it." - Balboos HaGadol
|
|
|
|
|
I was violently opposed to var for a long time, for all the reasons cited by other people. I even turned off the feature in Resharper. Then, I coded this for about the zillionth time:
MyCollection<ViewType, DomainType> c = new MyCollection<ViewType, DomainType>
And it struck me--I was entering the type specification twice. So, I started using var for declarations where the type was obvious.
The world didn't end, and my code was no more difficult to read. So, on a whim, I tried using it wherever possible. Again the world didn't end, and I've grown rather fond of it. I turned the feature back on in Resharper, and I use it whenever possible these days.
David Veeneman
www.veeneman.com
|
|
|
|
|
or... use vb.net and only have to type that once.
Oh, I know... flame away!
Proudly drinking the finest Maryland craft beer. Visiting Maryland for business? First round is on me!
|
|
|
|
|
Consider yourself flamed.
David Veeneman
www.veeneman.com
|
|
|
|
|
Twice? Once you type new , Intellisense writes the second one for you (says the guy who mostly uses Edit rather than VS).
And if you use that type of collection frequently, just make a type of it:
DomainViewCollection : MyCollection<ViewType, DomainType> {}
and things will be even clearer.
|
|
|
|
|
I agree totally, why type or read the type twice? Once is enough, the second one is just noise.
(In the case of var, the first one is the noise )
All the people who say var makes the code unreadable, should use R#. R# intellisense and goto's makes all vars easy to understand again!
|
|
|
|
|
I agree, and what did you saved? Half a second? A second?
I think that time is payment enough for increased readability. Try other guy interpreting your code, and you will see.
|
|
|
|
|
I use C# as my primary programming language but have never heard of var .
According to some comments here, it seems it would be a pretty popular option
|
|
|
|
|
Yes.. It is ..
If you have used anonymous types ever, you would have come across with this ...
|
|
|
|
|
it's a lot more difficult to read the code.
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com
|
|
|
|
|
+5 it is... and it looks like javascript...C# code looks best without var .
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Unruled Boy wrote: it's a lot more difficult to read the code.
More difficult to read or understand?
IJunk awesomeJunk = new AwesomeJunk ();
vs
var awesomeJunk = new AwesomeJunk ();
I really don't see much of a difference..?
Todd Smith
|
|
|
|