You’re Creating a New Programming Language — What Will the Syntax Look Like?

I asked a bunch of programmers about their favorite syntax — here’s what they said

Yakko Majuri
Jul 29 · 4 min read
Image for post
Image for post

A little while ago I decided to have a little fun and wrote an article titled “My Favorite Pieces of Syntax in 8 Different Programming Languages.”

I published it and then decided to share it on a subreddit — r/ProgrammingLanguages. This led to an interesting discussion about programming language syntax, as users shared their own favorites.

It left me with no choice: I had to write a new article with my favorite pieces of syntax from the r/ProgrammingLanguages community.

A Compilation of Adored Syntax Across Programming Languages

Before we get into it, I should quickly clarify what this article is and what it isn’t.

While it would be awesome to go in-depth into each of the snippets, there are just too many of them. In any case, I’m not familiar with all the languages mentioned.

As such, I’ll add a bit of the explanation from the user who posted it if one was available. However, you’re welcome to contribute on GitHub to this list, and more in-depth explanations are welcome there.

Finally, the reason for the title of this article is that many users in the subreddit actually have built or are building their own programming languages, and some have mentioned that they’re looking to include their favorite syntax from other languages in it.

Maybe you can draw inspiration from for your own programming language from this list.

Image for post
Image for post

Generator Expressions/ List Comprehensions

Posted by: u/ibrahimqasim and u/usernamecreationhell

Variable Unpacking and Multiple Assignment

Posted by: u/ibrahimqasim

‘With’ Blocks

Posted by: u/Beefster09

Image for post
Image for post

Do Notation

Posted By: u/superstar64

do notation is “syntactic sugar for combining monadic functions.”

List Comprehensions

Posted By: u/batllista101

Variable Unpacking and Multiple Assignment

Posted by: u/batllista101

Image for post
Image for post

Anonymous Functions

Posted By: u/Yul3n

OCaml has anonymous functions using the function keyword auto-trigger pattern matching so you can write something like this:

Image for post
Image for post
Yes, this one looks weird. Have to be consistent though!

Bracketless Control Structures

Posted by: u/Yul3n

Control structures with a one-line body can have brackets omitted:

Image for post
Image for post

Array Destructuring

Posted by: u/That-Thou-Art

Image for post
Image for post

Variable/ Constant Declaration and Import Blocks

Posted by: u/almbfsek

Receiver Functions

Posted by: u/almbfsek

Image for post
Image for post

Case Classes

Posted by: u/Adriandmen

Image for post
Image for post

Flexible Call Syntax

Posted by: u/xigoi

Style Insensitivity

Posted by: u/xigoi

Pragmas

Posted by: u/xigoi

Pragmas removes the need for keywords like inline and you can easily define your own.

Result Variable

Posted by: u/xigoi

Every procedure automatically defines a variable called result, which is initialized to the default value and automatically returned at the end unless you explicitly return something else.

That’s it, thanks for reading!

Further Reading

Interested in learning about different programming languages?

Check out this tutorial about a powerful yet little-known programming language called Nim: “A Python Substitute? I Tried Out the Best Programming Language You’ve Never Heard Of”.

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store