|
var has its place, but the potential for misuse is very high, even among CodeProjectors.
I say, if you know the type, use the type; var is for when you don't or can't know the type.
|
|
|
|
|
var is NOT the same as a Variant from the old VB days. It is a statically inferred type that remains that type through the duration of its scope. It is not like the old VB variant where the compiler had to leave enough "space" for whatever type of variable you put in. This kind of typing has been done for years successfully in functional languages like scheme and ocaml.
|
|
|
|
|
Gadbad Singh wrote: does this mean we are going back to the good old (or bad old) days of Visual Basic VB6 and earlier when any and every variable was of type Object.
Not at all. var is just an unfortunate keyword for type inference[^], which is very different from dynamic typing with variants.
|
|
|
|
|
Wasn't there some rumbling about putting this in C++0xx sometime within the next millennium?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Jim Crafton wrote: Wasn't there some rumbling about putting this in C++0xx sometime
Yes, but the keyword is different[^]
Jim Crafton wrote: within the next millennium?
Blessing and curse of a mature and standardized language - changes come slowly.
|
|
|
|
|
It would have been better if they'd come up with a different keyword. I've seen lots of confusion over it - even if it's only short-lived confusion.
Kevin
|
|
|
|
|
That question has been answered so many times that is getting bored.
var != VB6VariantObjectType
|
|
|
|
|
why are you getting so "bored" , i have not said that
var != VB6VariantObjectType
i just mentioned that var is similar to Object in C# or VB which is way too confusing when it comes to guessing the underlying datatype, something similar to var used in scripting langugage jscript used in in html files.
|
|
|
|
|
It's not like object as the compiler does check for it's type. If it were an object the compiler would eat it if you assigned a string first and an integer later. variables declared as var can be quite useful when working with anonymous types in LINQ queries, in fact it is required.
WM.
What about weapons of mass-construction?
"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
My blog
|
|
|
|
|
Read the docu about the var KEYWORD (see other comments) it's not RTTI... It's main use is for very long type names like "List<list><someobj>>>"
But the compiler "knows" the type at compile-time - so everything keeps strongly typed.
|
|
|
|
|
why..... because it's newer, newer = better (hopefully).
Ps. I'm in research
|
|
|
|
|
Yes..... but it is newer, so less people have it
|
|
|
|
|
Not really an issue within research I find...
|
|
|
|
|
Cameron_DeW wrote: but it is newer, so less people have it
Does it matter? The installer will get rid of this.
Best regards,
Jaime.
|
|
|
|
|
Yes, it does matter.
Since MS dropped support for Win2K with .NET 3.0, all our customers with Win2K could not be served if we used anything newer than 2.0, and there's still quite a lot especially in health services here in Germany.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
mav.northwind wrote: Yes, it does matter.
Since MS dropped support for Win2K with .NET 3.0, all our customers with Win2K could not be served if we used anything newer than 2.0
I agree 2.0 is still the best choice - supported on every system and has all the features typical developer needs. Plus most users (people eage 30-50 now) when buying software expect same looks as win 95 or 98 - aame datagrid look same dialog boxes and so on. 3.0 and later versions give developers cool new features like LINQ or XAML - no argue about that. You can make your app look like a xmas tree =] but this will confuse 99% of older users (they usualy own a company and they decide if a new software will be purchased =]). Also 2.0 works on Linux (haven't done any app for Linux myself but a lot of people do, it's a great way to expand your aplications "SUPPORTED SYSTEMS" menu ), higher versions are still not available - this will change but for now 2.0 is the only option.
|
|
|
|
|
mav.northwind wrote: Since MS dropped support for Win2K with .NET 3.0
Things are due to get murkier given that Silverlight 2 (effectively a subset of .NET 3.5) is slated to include Win2k as a target. They should really have kept Win2k targeting form .NET 3 or else not made VS 2005/.NET 2 available or Win 2k.
Kevin
|
|
|
|
|
I target 2.0, as it can reach more people....
What version do you target, why?
|
|
|
|
|
I start at targetting 2.0, and upgrade the target to a higher version when I need functionality of it.
But till now, I never needed a higher version.
|
|
|
|
|
never needed a new .net version? ohhh.
i really would miss generics, anonymous methods and newly also the lamba-expressions and linq at all. we use this stuff heavily in here is makes a lot fun (and is more efficient) then writing the same things again and again . in our opinion microsoft did a really good job for 2.0, 3.0 and finally for 3.5 so why not use this really cool and handy new stuff.
this is why we target 3.5 and therefore moved all projects to 3.5 and VS2008. framework-version is no problem for out customers as they don't really care if they have to deploy 2.0 or 3.5 - they have to make the deployment anyway for other products our installers check for 3.5 and if needed download and install it so deployment of the newer .net framework here is really no issue anymore.
|
|
|
|
|
Agree with you. There are so many futures in 3.5 that makes life easier
|
|
|
|
|
That's really lucky.. or I'm very unlucky - it seems like the majority of the target audience of most of my .NET programs do not even have .NET 2.0..
|
|
|
|
|
I think the issue with targetting 3 or 3.5 is that it will not run on Windows 2000. Believe it or not, when targetting the masses, this can make a huge difference.
Tim Friesen
|
|
|
|
|
yeah, that can make a difference... a surprising number or people still use Windows 2000
|
|
|
|
|
maybe yes and i agree that our .net apps currently do not target the masses but our customers.
for other apps i wrote targeting the masses i don't really support win2000 anymore. people can try it but if even microsoft does not support it anymore why should my company? this operating system is more then 8 year! one day people have to upgrade to a slightly newer operating system or stay with the old version of my apps. sure, i not only support the newest OS but win2000 ist just to old to focus on this audience and therefore make all the development less efficient.
you're right if you core-audience is still on win2000 then probably you have to stay with all the old technology.
|
|
|
|