|
Give it another iteration of new language features and we'll probably have the even shorter C++ version. At times I wish they went faster but at least MS is steadily chipping away at language verbosity in C#; unlike Sun/whOracle who seem to revel in Java's bloatyness.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
I would Java.Lang.Objection.RaiseSpecificObjection.Object to that slam on Java being wordy!
|
|
|
|
|
I just love it. Most of the terseness is easy to read as well, except those LINQ monsters that ReSharper turns your loops into. Even a few of them are easier to read.
Do what thou wilt shall be the whole of the Law. - Liber AL vel Legis 1:40, Aleister Crowley
|
|
|
|
|
I like it when it's short enough to fit on a line:
StudentName student2 = new StudentName{FirstName = "Craig", LastName = "Playstead"};
But when it gets bigger than that I prefer the older form. Or, if it could indent it like this:
StudentName student2 = new StudentName{FirstName = "Craig",
LastName = "Playstead"};
I'd be happy.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I always use your second style here, all function calls are broken up with one param per line, all neatly lined up. (I am so anal about code tidyness )
|
|
|
|
|
Munchies_Matt wrote: I am so anal about code tidyness
... and sooo paid by the LOC it seems
modified 19-Nov-18 21:01pm.
|
|
|
|
|
We actually align the = signs as well. It makes it MUCH easier to read the 2 columns of assignment!
(so you shouldn't feel overly anal about it)
|
|
|
|
|
Anything that gets rid of squirly brackets has got to be good.
|
|
|
|
|
Chris C-B wrote: Anything that gets rid of squirly brackets has got to be good. Long live VB!
There are only 10 types of people in the world, those who understand binary and those who don't.
modified 24-Aug-16 9:30am.
|
|
|
|
|
My thoughts exactly!
|
|
|
|
|
StudentName student2 = new StudentName
{
FirstName = "Craig"
,LastName = "Playstead"
};
Nothing at all wrong with that, and requires less typing than your preferred method. Of course, the ultimate in "less typing" is a constructor with a parameter for each property:
StudentName student2 = new StudentName("Craig", "Playstead");
In the end, your preference doesn't matter within the context of your employer's coding standards, and no matter which way you go, they all do essentially the same thing.
".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
|
|
|
|
|
You moved the comma in the initializer though; saves a keypress if one would copy/paste an entry
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I moved the comma because when you're typing that initializer, you need to type a space (or the first letter of a property name that hasn't already been initialized) for intellisense to work. Keeps things lined up as well until I can fiddle with it a little more to make it pretty.
".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
|
|
|
|
|
John Simmons / outlaw programmer wrote: Nothing at all wrong with that,
Except for the leading comma, which is an abomination.
I see people use that in SQL queries, who argue that it makes it easier to rearrange the lines without having to remember to add/remove the comma. But it doesn't - you've just moved the problem from the end of the list to the start of the list.
And in C#, that's not even a real problem. You can have a trailing comma on every item, including the last:
StudentName student2 = new StudentName
{
FirstName = "Craig",
LastName = "Playstead",
};
As for invoking Intellisense, Ctrl+Space will do the trick without having to insert extra spaces.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I view the trailing unnecessary comma as an abomination.
".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
|
|
|
|
|
It's not quite the same, in the matter of debugging.
If initializing gets a little more complex, the former syntax do not allow stepping to find which assignment is throwing the exception.
It's not the end of the world, but it slows you down, so I prefer the latter. It doesn't even require more typing as you can type several lines at the same time in the editor.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
Not only that. It does not introduce any real benefit. Sure, the inititialisation now is atomic, but that can become a pain when debugging (which one of those 4000 fields threw that exception during the initialisation?) and actually is not needed so often.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
Yes, worth it to use the longer syntax just for better debugging
|
|
|
|
|
I had that problem with a data object for a database table with about 150 columns (a monstrosity by itself). Somewhere in the initialisation a simple null reference exception occured, but for which column. But my cow-orkers insisted on using the initializers because they are soooo cool (why, exactly?), muuuuuch more readable (why, exactly?) and because they are atomic (which we needed for what reason, exactly?).
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
0) If you can't discern which of the properties is throwing the exception, maybe you should let someone else do the debugging.
1) If you have 400 properties that need to be initialized in an object, maybe you should rethink your design and pass a single model object (or a limited number of model objects) to a constructor and debug in the object being initialized.
2) After my first experience with a null reference exception as a result of a database query, I started writing my stored procs in such a way as to NOT return null values for any column.
".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
modified 24-Aug-16 8:20am.
|
|
|
|
|
0) I did that by leaving the company.
1) Agreed, but it was not my design and the last survivor of the original 'designers' was the company's second in command who took any proposals as a personal insult. Another good reason to leave that place.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
CDP1802 wrote: It does not introduce any real benefit.
Lambda expressions? LINQ? Anonymous types?
There are plenty of cases where you need to initialize a new object but you can't use multiple statements to do it.
If you've never encountered one, then feel free to ignore the syntax. But that doesn't mean they don't exist!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I try to avoid such an unreadable mess where I can. Initializing objects with many members within some other construct is an unreadable mess.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
If that causes an "unreadable mess", may I suggest that indicates a different problem.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Yes, and that was the least of their problems. They also found it nice and well that the application logic resided under the data access layer, in stored procedures and triggers.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|