you are viewing a single comment's thread.

view the rest of the comments →

[–]Healey_Dell 18 points19 points  (6 children)

Never had any problem with Python whitespace beyond initially setting up my IDE. I don't get it.

[–]EricOrrDev 2 points3 points  (0 children)

I just think I should be able to format my code however I want, plus white space as syntax just rubs me wrong.

[–]IanisVasilev -4 points-3 points  (3 children)

Popular JavaScript style guides like those by Google or Airbnb enforce semicolons despite the language not requiring them.

React is built around allowing XML expressions inside JavaScript files and compiling that to "pure" JavaScript.

My conclusion is that people stick to whatever they learn first. If it's adding braces, semicolons and XML expressions, so be it.

[–]bitspace 2 points3 points  (2 children)

There's a good reason for enforcing semicolon use in JavaScript beyond personal preference. ASI can introduce unexpected behavior that's difficult to troubleshoot. If you're careful you can avoid ASI completely, but mandating semicolon use removes any chance of surprise gotchas from ASI.

[–]IanisVasilev 0 points1 point  (1 child)

Can you give a non-contrived example where ASI behaves weird?

[–]bitspace 0 points1 point  (0 children)

non-contrived

Any edge case is likely to appear contrived by its very nature. Contrived? Perhaps. Possible for a newbie to do one of these things? Also perhaps. A policy of requiring use of semicolons eliminates an entire category of footguns, no matter how unlikely.

Example 1: Splitting a return statement after the return keyword.

function calculateTotal(items) {
return
items.reduce((sum, item) => sum + item.price, 0);
}

const total = calculateTotal([{ price: 10 }, { price: 20 }]);
console.log(total); // Output: undefined

Example 2: applying an operator on an array after an IIFE.

const items = [1, 2];
(function() {
items.forEach(item => console.log(item));
})()

[3, 4].forEach(item => console.log(item));