Skip to main content
deleted 1 character in body
Source Link
Glorfindel
  • 3.2k
  • 6
  • 27
  • 33

The reason is that in Python, newlines are an unambiguous way of separating code lines; this is by design, and the way this works has been thoroughly thought through. As a result, python code is perfectly readable and unambiguous without any special end-of-statement markers (apart from the newline).

JavascriptJavaScript, on the other hand, was designed with a C-like syntax in mind, where statements are always terminated with a semicolon. To make the language more tolerant to errors, it tries to guess where extra semicolons should go to make the code correct. Since this was sort of retro-fitted onto the C-like syntax, it doesn't always work as expected (sometimes, the script interpreter guesses wrong), and can make for fairly counter-intuitive code.\

Or, arguing in terms of "explicit is better than implicit": In Python, a newline is already completely explicit, while in JavascriptJavaScript, it is ambiguous, so you add the semicolon to make it explicit.

The reason is that in Python, newlines are an unambiguous way of separating code lines; this is by design, and the way this works has been thoroughly thought through. As a result, python code is perfectly readable and unambiguous without any special end-of-statement markers (apart from the newline).

Javascript, on the other hand, was designed with a C-like syntax in mind, where statements are always terminated with a semicolon. To make the language more tolerant to errors, it tries to guess where extra semicolons should go to make the code correct. Since this was sort of retro-fitted onto the C-like syntax, it doesn't always work as expected (sometimes, the script interpreter guesses wrong), and can make for fairly counter-intuitive code.\

Or, arguing in terms of "explicit is better than implicit": In Python, a newline is already completely explicit, while in Javascript, it is ambiguous, so you add the semicolon to make it explicit.

The reason is that in Python, newlines are an unambiguous way of separating code lines; this is by design, and the way this works has been thoroughly thought through. As a result, python code is perfectly readable and unambiguous without any special end-of-statement markers (apart from the newline).

JavaScript, on the other hand, was designed with a C-like syntax in mind, where statements are always terminated with a semicolon. To make the language more tolerant to errors, it tries to guess where extra semicolons should go to make the code correct. Since this was sort of retro-fitted onto the C-like syntax, it doesn't always work as expected (sometimes, the script interpreter guesses wrong), and can make for fairly counter-intuitive code.

Or, arguing in terms of "explicit is better than implicit": In Python, a newline is already completely explicit, while in JavaScript, it is ambiguous, so you add the semicolon to make it explicit.

Source Link
tdammers
  • 52.9k
  • 15
  • 112
  • 155

The reason is that in Python, newlines are an unambiguous way of separating code lines; this is by design, and the way this works has been thoroughly thought through. As a result, python code is perfectly readable and unambiguous without any special end-of-statement markers (apart from the newline).

Javascript, on the other hand, was designed with a C-like syntax in mind, where statements are always terminated with a semicolon. To make the language more tolerant to errors, it tries to guess where extra semicolons should go to make the code correct. Since this was sort of retro-fitted onto the C-like syntax, it doesn't always work as expected (sometimes, the script interpreter guesses wrong), and can make for fairly counter-intuitive code.\

Or, arguing in terms of "explicit is better than implicit": In Python, a newline is already completely explicit, while in Javascript, it is ambiguous, so you add the semicolon to make it explicit.