DEV Community

Discussion on: The shortest way to conditional insert properties into an object literal

Collapse
 
jfet97 profile image
Andrea Simone Costa • Edited

I completely disagree because lot of JS syntax and features need an explaination. Think about coercion, generators, arrow functions, async await, the asynchronous iteration, proxies, ecc.
More generally each concept in every programming language, also the basic ones, may need an explanation.

And, with your line of thinking, people risk to never learn anything and never improve themselves.

The article is explaining why the syntax is valid. But the main concept, the optional insertion of a property, is understandable in 10 seconds.
After a little example, if you spend 5 mins with it, you can already understand what's going on:

...condition && {prop:value}

If the condition is true a prop will be added. No side effects in the other case. Simple.

It's something with which one can become familiar in no time, it's something immediately teachable to others and I've demostrated that it works not because an undefined, untrustable behaviour but thanks to a precise logic put black on white in the spec.

Collapse
 
andychiare profile image
Andrea Chiarelli • Edited

I don't criticize the use of idiomatic code (I often use it, too) but the emphasis on the shortest way.
It seems to encourage the writing of compact or idiomatic code at any cost, and it is not always the best choice.
As with natural language, if you use very strict jargon, you reduce the number of people who are able to understand it with little effort.

Thread Thread
 
jfet97 profile image
Andrea Simone Costa

The shortest way means only one thing: fewer characters are required.
The second part you deduced is your personal interpretation of the title, which obviously does not reflect my thinking at all.

Thread Thread
 
andychiare profile image
Andrea Chiarelli

Maybe you're right. Sorry for any misunderstanding.

Thread Thread
 
jfet97 profile image
Andrea Simone Costa

No problems 😃!

See you at the DevFest, with peaceful intentions of course 😝

Thread Thread
 
andychiare profile image
Andrea Chiarelli

I've never had any non-peaceful intentions :-)
See you at the DevFest!