|
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.
|
|
|
|
|
|
Right.
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: 4000 fields
I think I've located your problem.
|
|
|
|
|
It were only 150, but that already is bad enough.
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.
|
|
|
|
|
Yeah, that's just... ouch...
If my objects ever have more than a couple dozen fields, I start thinking of the most logical way to split them up.
But if you're manually initializing 150 fields at once, whether it's in one object or an object tree, it's time to rethink your design.
|
|
|
|
|
The database already was a horror by itself, but could not be changed without risking a complete collapse. They were simply attempting to add something like data access classes and initializing data objects from data query results. It was a feeble attempt to bring some order to this application because a good part of the application logic was hidden in database triggers. Doing CRUD operations with data access objects usually had unexpected side effects.
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.
|
|
|
|
|
I like the first. Less typing and more readable.
#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
|
|
|
|
|
Initializing is for sissies. Real programmers do not initialize.
|
|
|
|
|
I woud simply use a parametrized constructor to construct and initialize the instance at once.
var student2=new StidentName("Craig","Playstead");
|
|
|
|
|
Sadly I've been corrupted by javascript and I am currently finding this the most readable (and I do this for SQL as well for INSERT INTO column lists)
StudentName student2 = new StudentName {
FirstName = "Craig",
LastName = "Playstead"
};
I know, I've gone rabid and need to be put down out of humane concern.
|
|
|
|
|
Exactly what I like to use ... except I would never have a "student2" ... maybe "classClown"; etc.
|
|
|
|
|
I always hated that style of indent = { indent.
When I learned C it was:
void main()
{
IndentedCodeHere;
}
I cringed when I saw:
void main()
{
CodeHere;
}
as if that made it easier to read.
Then JavaScript came in
function main() {
Codehere;
}
Which I can live with, and I get. But it just seems wrong.
It is VERY hard to match the braces visually, but the editors do it for me...
But indentation matters.
|
|
|
|
|
Am I not seeing what you're seeing? I don't see ANY indentation there.
FWIW, I prefer this indentation:
var student2 = new StudentName
{
FirstName = "Craig",
LastName = "Playstead",
};
|
|
|
|
|
Just a personal thing but I hate code visually floating out to the right. I get that it lines up with the "new" but I find that disturbing, like I need to go in and fix it OCD style. I see the same thing with some default SQL formatters (like from RedGate). First thing I go to customize.
|
|
|
|