loading...

re: The shortest way to conditional insert properties into an object literal VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Why should I choose the shortest way if it needs an article to be explained? In my opinion, the best code is the self-explanatory one, not the shor...
 

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.

 

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.

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.

Maybe you're right. Sorry for any misunderstanding.

No problems 😃!

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

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

Code of Conduct Report abuse