I made this experiment yesterday:



The thread exploded with hundreds of insights and parallel discussions! Thanks to all who participated.

I'm gonna try to summarize the most interesting takes (from my POV) and thread in my own thoughts. Brace! 👇
First, as some suggested, this does happen in a couple languages:

JavaScript:


Groovy:


And even Python has optional semicolons:
docs.python.org/3/reference/si…
However, these are not so much "errors" fixed by the compiler, but actual features.

They are accounted for in the grammar, and only in specific constructions where it is mostly unambiguous to do so.

(🤔Whether this a good idea or not is a matter for another discussion).
Going back to the general question: if the compiler detects a syntax error, when (if ever) is it ok for it to correct it?

Most of the discussion in the thread revolves around the following idea:

💡 Upon a syntax error, it is ambiguous to determine what was the original intent.
There are many examples...

... where it is ambiguous what to fix:


... where it is ambiguous if the code is correct at all:


... and where even if possible, you may be on the point of diminishing returns:
🧐Formally speaking, a compiler should only make changes to the code that conserve the operational semantics.

This means that it is free to change how the code *looks* as long as what the code *does* remains unchanged.

🔍For example, removing dead code or inlining functions.
However, when the code has a syntax error, the operational semantics are undefined. It is simply impossible to determine, by definition, what is this code supposed to do, *with absolute certainty* 👈.

And this is the key point, the compiler cannot "guess" sometimes wrong.
At most, the compiler could suggest: "here are some changes that would make your code compilable". It could have some statistical model to suggest "most likely" fixes, but it cannot decide what is the "right" fix.

🔑Only programmers know their actual intentions (sometimes 😜).
❓What about the limited situations where the fix is fairly obvious? (e.g., a semicolon after the final return of a method).

Even in this case, I personally prefer a suggestion than an automatic fix (and yes, I hate optional semicolons).

But this is a philosophical position.
🔥And then comes the problem of, if you allow these fixes (I'm looking at you, JavaScript), then you have to formalize how they are supposed to be dealt with.

And this opens a whole new can of worms:
And that's it. I've tried to summarize some key points, but the thread is so full of interesting insights that I simply cannot hope to honour them all.

❤️Thanks to everyone who dropped a comment, a like or a retweet.

This was a fun conversation. Let's keep those coming!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alejandro Piad-Morffis

Alejandro Piad-Morffis Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!