|
Yeah, but that's the point. If you could pick any language, or make up your own language, how would you declare variables? Or does it just not matter?
I wrote this because I'm switching between C# and TypeScript and Javascript and SQL and bash and Powershell and VBScript and I'm all over the shop and I am constantly tripping up on declaring variables. You'd think I'd have that skill sorted by now...
cheers
Chris Maunder
|
|
|
|
|
It's a solid question.
I, like many others, appear to prefer the C style.
One think I liked about the C style was
int a,b,c,d[12]; // so concise, and it emphasizes the types
I use pascal/Delphi a lot, so I have to do:
a,b,c: Integer;
Which honestly makes it harder to split and document at the end of the line.
But with most of todays editors, I am surprised you did not commonize Ctrl-D,V (Define Variable),
to be dynamic depending on the language you are using.
As an Oracle person, I trip up on MSSQL syntax, so my MSSQL editor has Oracle keywords defined to inject comments (TO_DATE(), NVL -> Coalesce(), etc)
And the same for SQLite, and MySQL. Otherwise I lose my sanity.
Finally it looks like it would fit on a 3x5 card
Oh, and I use AHK for date formatting file names with todays date, with a popup.
And I have another popup that reminds me all of the hotkeys, LOL
Screenshot
So I only have 1 hot key to remember (Win-H, for Help, LOL)
Reminds me of the old TSRs in DOS days!
|
|
|
|
|
I feel your pain. I like the C#, the most I guess.
Yep!
|
|
|
|
|
I've been switching Android over to Kotlin and it uses that new syntax (as does Swift) like TypeScript and I've been stumbling around with it too.
It really looks odd to me when you initialize the var in these languages bec it looks like you are setting the type to a value.
var thing : String = "this is the thing"
I sat down and really tried to think about why the new languages made this change. It seems far more cryptic than the old way. I think I had decided on one reason why they'd done it and then I forgot again.
Oh, now I remember what I thought it might be:
They are moving toward dynamically typed languages (of course, laziness rules today ) so now when you leave the type off you'll just have:
var [name] = Thing;
So this is probably some middle-ground syntax and the middle-ground is always weak!!
|
|
|
|
|
Variable declaration isn't the problem, it's the rest of the coding.
Nit pick time, it REALLY bothered me that you didn't terminate the statements.
int count;<-where were the semi-colons?
count: Integer;<-where were the semi-colons?
|
|
|
|
|
MarkTJohnson wrote: where were the semi-colons?
Actually, that is going by the way-side too.
In Swift, they are extraneous.
In Kotlin too.
I don't think Python uses them.
I come from C/C++/C# and now doing a lot of Swift (iOS) and now Kotlin (Android) and it gets really weird because sometimes the compiler doesn't know where the line ends and complains about the wrong things.
I type in semi-colons all the time in Swift and Kotlin though. Just can't help it.
|
|
|
|
|
Count DD 0 MASM, how we've missed ye.
Software Zen: delete this;
|
|
|
|
|
Nullable? Maybe a DB int? Maybe a nullable DB int? Maybe a ranged int? Maybe an int that's the imaginary part of an imaginary number?
Life is no longer as simple as int count = 0; !!!
Nowadays, and int might look like this (mind you, this is fictional code, but probably exists somewhere):
var count = new Nullable<int>(
min: 0,
max: 999,
rangeException: OutOfRangeException,
DBNullDefaultValue = 0);
|
|
|
|
|
Marc Clifton wrote: Maybe an int that's the imaginary part of an imaginary number?
in an imaginary planet, in an imaginary universe?
|
|
|
|
|
var number = 0;
var result = method();
Wake up! The Singularity is coming.
|
|
|
|
|
nmarcel wrote: var number = 0;
The type inferred there is specifically a 32 bit signed integer.
If we intended "number" to be an Int64 for example, we'd have to either default it to a value that's too large for a 32 bit int and reset it to 0 or just take the simple route and declare it explicitly as an Int64.
What is the actual benefit of "var" here? "int number = 0;" is both more readable (we can see what type of int it is without resorting to tool-tips) and we're explicitly telling the compiler what to do rather than hoping it infers our intended type.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
|
|
|
|
|
PeejayAdams wrote: If we intended "number" to be an Int64 for example, we'd have to either default it to a value that's too large for a 32 bit int and reset it to 0 or just take the simple route and declare it explicitly as an Int64.
Or you could use:
var number = 0L;
Not that I would use it, it's just another way.
Although I would probably use:
long number = 0;
|
|
|
|
|
Absolutely!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
PeejayAdams wrote: What is the actual benefit of "var" here?
There is none.
We would do int number = 0 or decimal number = 0 , but never var number = 0 .
|
|
|
|
|
C# is essenially C++ as far as BNF concerned
|
|
|
|
|
count = 0 In Rexx everything's a string until it needs to be otherwise.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
C/C# style
int count = 0;
“The palest ink is better than the best memory.” - Chinese Proverb
|
|
|
|
|
This.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
var is a very helpful typesafe way to more loosely declare your variables. I quite like it.
dynamic would be closer to something like a script's object variable.
either might apply to this quiz
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
A rather weird survey as Mike B. pointed out.
So let's get down to the heart of the matter: VAR IS EVIL.
I shall now adopt my flame-proof suit.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
|
|
|
|
|
the real war is the naming battleground. Lately a collegue coded this:
testHelper.add() I politly stayed silent...
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
var is not evil, when used correctly, but it is also a pointless and futile debate topic.
No flame wars on this one.
|
|
|
|
|
Awwww... *puts away the popcorn*
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I love "var". I use when writing a declaration for the first time and then see what the actual type is, using intellisense, and change it to that. It makes working out what some of the more obscure method calls actually return a lot easier.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|