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
Last Visit: 31-Dec-99 18:00 Last Update: 29-Jul-21 0:18