Skip to content
Tech News
← Back to articles

No Semicolons Needed

read original more articles
Why This Matters

This article highlights the challenges and considerations in designing a programming language that omits semicolons, focusing on how different languages handle statement termination and line continuation. For the tech industry and developers, understanding these nuances can lead to more intuitive and user-friendly language design, ultimately improving coding efficiency and readability.

Key Takeaways

No Semicolons Needed

I'm making a scripting language called Roto. Like so many programming languages before it, it has the goal of being easy to use and read. Many languages end up making semicolons to delimit or terminate statements optional to that end. I want that too!

This sounds simple, but how do they implement that? How do they decide where a statement ends without an explicit terminator? To illustrate the problem, we can take an expression and format it a bit weirdly. We can start with an example in Rust:

fn foo ( x : u32 ) -> u32 { let y = 2 * x - 3 ; y }

In Rust, that is perfectly unambiguous. Now let's do the same in Python:

def foo ( x ) : y = 2 * x - 3 return y

We get an "unexpected indent" error! Since Python doesn't require semicolons, it gets confused. As it turns out, many languages have different solutions to this problem. Here's Gleam, for instance:

fn foo ( x ) { let y = 2 * x - 3 y }

That's allowed! And if we echo foo(4) we get 5 just like in Rust. So, how does Gleam determine that the expression continues on the second line?

I think these differences are important, especially when you're interested in programming language design. The syntax of the language need to be intuitive and clear for the programmer, so that they can confidently explain how an expression gets parsed.

... continue reading