The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
I think you can find instructions on how to create your own programming language here on CP, actually...
Anything that is unrelated to elephants is irrelephant Anonymous - The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944 - Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
Ah, the use of var. I know that some people use var to do code alignment on variable names; the idea being that it's easier to scan the name if it lines up.
var apiEndpoint = new Uri("http://someapi");
var retryCount = 10;
var longClassName = new ThisIsAReallyLongNameThatWouldReallyScrewUpTheClassNameDeclaration();
// body of the method.
the idea being that it's easier to scan the name if it lines up.
That's my main argument (readability) and why I like it.
On the other hand, incoming Option #3[^] is good too.
It is a bit less readable, but still "forces" you to by type strong but combined with the lazyness / don't break the lines with long names too.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
Does it work. Unfortunately yes and Fortunately yes.
AS mentioned already when refactoring code and say a variable changes from int to long or even to a string it makes sure the code continues to work.
I don't like it. but that does not mean I have never used it. I have and I hate myself for it. But I remember one time I had to write a bit of code. The co-workers insisted that the variable would always be an integer. ALWAYS they said. having some experience I knew probably gonna change. About a year later system requirements changed. I had used var and the code still worked. sooooooo
tldr; lazy yes, flexible yes, hate myself yes.
To err is human to really mess up you need a computer
The problem with that is that you are working to what should have been a breaking change. And that's important, because if you were assuming int division as a result of the original type spec for example, then a breaking change means you know it's just failed and can adapt to it. var in that case means you don't know, and output can be subtly wrong and unnoticed until it's a real problem.
I'd say var should be there for temporary storage of Linq results, and nowhere else ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
When I moved from VB (where purists dump on var from a great height) to c# where explicit types were mandatory I lost all faith in var, it became the one thing in VB that I loathed. Now that it has phoenixed in c# I refuse to use it.
As for var content changing type and not having to refactor, what a croc of sh*t, you should HAVE to refactor if you change type or at least check your usage of the variable.
Never underestimate the power of human stupidity -
I'm old. I know stuff - JSOP
I use var almost exclusively these days.
I started out using it sometimes, but then I started using it more and more.
To me, it just seems nice to have all my vars lined up nicely
Some people thing the var keyword isn't strongly typed, but it is (we have dynamic for that).
It's only absolutely necessary to use var when working with anonymous types (still strongly typed!).
The C# "var" construct and other such constructs in both C# and VB.NET are merely short-cuts or the usage of system defaults.
This makes for very ambiguous code over the length of an application's development.
This is why I don't even use the generic list-type and still use array-lists instead. Despite the slight performance decreases (which most will not notice since such constructs often do not contain thousands of objects or items in general), having easy to read strongly typed code makes my applications much more easily maintainable.
Sr. Software Engineer
Black Falcon Software, Inc.
The last place I worked would fail you in code reviews if you did not use var. Their (ill) logic was something to do with a design pattern, and when Entity Framework would cough on var, they added lines of code to get it to pass instead of just using the correct type.
Last Visit: 13-Jul-20 11:06 Last Update: 13-Jul-20 11:06