avatarYakko Majuri

Summary

The article discusses a compilation of favorite programming language syntax features as shared by the r/ProgrammingLanguages community, intended to inspire creators of new programming languages.

Abstract

The author of the article, inspired by a previous piece on favorite syntax in programming languages, decided to delve deeper into the preferences of the r/ProgrammingLanguages subreddit community. This led to the creation of a new article that showcases a variety of syntax features beloved by different programmers. The article emphasizes that it is not a tutorial nor an in-depth explanation of the syntax snippets presented but rather a fun compilation of opinions. It encourages readers to contribute with their own favorite syntax examples on GitHub. The features highlighted range from generator expressions and list comprehensions to variable unpacking, 'with' blocks, do notation, anonymous functions, bracketless control structures, array destructuring, import blocks, receiver functions, case classes, flexible call syntax, style insensitivity, pragmas, and result variables. These features are illustrated with code snippets and brief explanations when available, and the article concludes with a suggestion for further reading on the Nim programming language.

Opinions

  • Generator expressions and list comprehensions are favored for their concise representation of data transformation and filtering.
  • Variable unpacking and multiple assignment are appreciated for their ability to simplify code and enhance readability.
  • 'With' blocks are liked for their convenience in resource management and exception handling.
  • do notation in Haskell is seen as valuable syntactic

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

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.

❌ It isn’t a programming tutorial.

❌ It isn’t going to explain the snippets presented.

❌ It isn’t an objective list.

✅ It is meant for fun.

✅ It is a compilation of opinions from various people.

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.

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

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

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:

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:

Array Destructuring

Posted by: u/That-Thou-Art

Variable/ Constant Declaration and Import Blocks

Posted by: u/almbfsek

Receiver Functions

Posted by: u/almbfsek

Case Classes

Posted by: u/Adriandmen

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”.

Programming
Software Engineering
Technology
JavaScript
Python
Recommended from ReadMedium