r/ProgrammingLanguages • • Dec 13 '20

if … then … else had to be invented

Thumbnail
github.com
143 Upvotes

r/ProgrammingLanguages • • Oct 07 '24

Discussion What is the coolest feature of a programming language you have seen?

142 Upvotes

If you have a quick code snippet too, that would be amazing.


r/ProgrammingLanguages • • Apr 09 '23

Resource Writing a Simple Garbage Collector in C

Thumbnail maplant.com
142 Upvotes

r/ProgrammingLanguages • • Oct 30 '22

What are the worst features you've tried in your programming language?

142 Upvotes

A few years ago I had a talk with a professor on ways to shape the development of physics. A problem we identified is that everyone celebrates their successes, without going too much into the details of why the failures encountered along the way didn't work. So the mistakes don't get shared, and every research group tries the same failed ideas at least once.

In the PL world, we have sort of a celebration of very very bad (or simply very weird) programming ideas in esolangs. That being said, most esolangs are jokes, and nobody would think of non-ironically implementing a brainfuck-like interface in their language. I'm more interested in things that appeared to be good ideas but end up backfiring or not being a right fit.

So to the question, does anyone in here have a feature you've tried that ended up not working out?


r/ProgrammingLanguages • • Nov 11 '20

Learn Assembly by Writing Entirely Too Many Brainfuck Compilers in Rust

Thumbnail
github.com
142 Upvotes

r/ProgrammingLanguages • • Apr 30 '20

Discussion What I wish compiler books would cover

142 Upvotes
  • Techniques for generating helpful error messages when there are parse errors.

  • Type checking and type inference.

  • Creating good error messages from type inference errors.

  • Lowering to dictionary passing (and other types of lowering).

  • Creating a standard library (on top of libc, or without libc).

  • The practical details of how to implement GC (like a good way to make stack maps, and how to handle multi-threaded programs).

  • The details of how to link object files.

  • Compiling for different operating systems (Linux, Windows, macOS).

  • How do do incremental compilation.

  • How to build a good language server (LSP).

  • Fuzzing and other techniques for testing a compiler.

What do you wish they would cover?


r/ProgrammingLanguages • • Dec 11 '22

Epic Games Verse - new information

141 Upvotes

Since 2020 it was radio silence on Verse - I was quite hyped up because they hired Simon Peyton Jones to work on it.

And suddenly they revealed something new about it. Firstly, just look into these names: Lennart Augustsson, Joachim Breitner, Koen Claessen, Ranjit Jhala, Simon Peyton Jones, Olin Shivers, Tim Sweeney. Turns out they all work on it

So, there was a talk about Verse at Haskell eXchange 2022, here are the paper and the slides:

https://simon.peytonjones.org/assets/pdfs/verse-conf.pdf

https://simon.peytonjones.org/assets/pdfs/haskell-exchange-22.pdf

It looks like superheroes gathered to work on something truly innovative.

Whoa, just look at that!

P.S. I dreamed of something like this since my uni years - types should be just functions that filter values and can be easily composed https://kvachev.com/blog/posts/we-need-simpler-types/. It's so amazing that humanity finally came up with a similar thing. So, to me it looks like a revolution is coming, let's see


r/ProgrammingLanguages • • Nov 09 '25

the clickbait headline programming language

Thumbnail
tabloid.vercel.app
139 Upvotes

r/ProgrammingLanguages • • Nov 15 '22

Let's collect relatively new research programming languages in this thread

139 Upvotes

There is probably a substantial number of lesser known academic programming languages with interesting and enlightening features, but discovering them is not easy without scouring the literature for mentions of these new languages. So I propose we list the languages we know of thus helping each other with this discoverability issue. The requirement is that the language in question should have at least one published paper associated with it.


r/ProgrammingLanguages • • Jul 23 '22

Nulls really do infect everything, don't they?

139 Upvotes

We all know about Tony Hoare and his admitted "Billion Dollar Mistake":

Tony Hoare introduced Null references in ALGOL W back in 1965 "simply because it was so easy to implement", says Mr. Hoare. He talks about that decision considering it "my billion-dollar mistake".

But i'm not here looking at it not just null pointer exceptions,
but how they really can infect a language,
and make the right thing almost impossible to do things correctly the first time.

Leading to more lost time, and money: contributing to the ongoing Billion Dollar Mistake.

It Started With a Warning

I've been handed some 18 year old Java code. And after not having had used Java in 19 years myself, and bringing it into a modern IDE, i ask the IDE for as many:

  • hints

  • warnings

  • linter checks

as i can find. And i found a simple one:

Comparing Strings using == or !=

Checks for usages of == or != operator for comparing Strings. String comparisons should generally be done using the equals() method.

Where the code was basically:

firstName == ""

and the hint (and auto-fix magic) was suggesting it be:

firstName.equals("")

or alternatively, to avoid accidental assignment):

"".equals(firstName)

In C# that would be a strange request

Now, coming from C# (and other languages) that know how to check string content for equality:

  • when you use the equality operator (==)

  • the compiler will translate that to Object.Equals

And it all works like you, a human, would expect:

string firstName = getFirstName();
  • firstName == "": False

  • "" == firstName: False

  • "".Equals(firstName): False

And a lot of people in C#, and Java, will insist that you must never use:

firstName == ""

and always convert it to:

firstName.Equals("")

or possibly:

firstName.Length == 0

Tony Hoare has entered the chat

Except the problem with blindly converting:

firstName == ""

into

firstName.Equals("")

is that you've just introduced a NullPointerException.

If firstName happens to be null:

  • firstName == "": False

  • "" == firstName: False

  • "".Equals(firstName): False

  • firstName.Length == 0: Object reference not set to an instance of an object.

  • firstName.Equals(""): Object reference not set to an instance of an object.

So, in C# at least, you are better off using the equality operator (==) for comparing Strings:

  • it does what you want

  • it doesn't suffer from possible NullPointerExceptions

And trying to 2nd guess the language just causes grief.

But the null really is a time-bomb in everyone's code. And you can approach it with the best intentions, but still get caught up in these subtleties.

Back in Java

So when i saw a hint in the IDE saying:

  • convert firstName == ""

  • to firstName.equals("")

i was kinda concerned, "What happens if firstName is null? Does the compiler insert special detection of that case?"

No, no it doesn't.

In fact Java it doesn't insert special null-handling code (unlike C#) in the case of:

firstName == ""

This means that in Java its just hard to write safe code that does:

firstName == ""

But because of the null landmine, it's very hard to compare two strings successfully.

(Not even including the fact that Java's equality operator always checks for reference equality - not actual string equality.)

I'm sure Java has a helper function somewhere:

StringHelper.equals(firstName, "")

But this isn't about that.

This isn't C# vs Java

It just really hit me today how hard it is to write correct code when null is allowed to exist in the language. You'll find 5 different variations of string comparison on Stackoverflow. And unless you happen to pick the right one it's going to crash on you.

Leading to more lost time, and money: contributing to the ongoing Billion Dollar Mistake.

Just wanted to say that out loud to someone - my wire really doesn't care :)

Addendum

It's interesting to me that (almost) nobody has caught that all the methods i posted above to compare strings are wrong. I intentionally left out the 1 correct way, to help prove a point.

Spelunking through this old code, i can see the evolution of learning all the gotchas.

  • Some of them are (in hindsight) poor decisions on the language designers. But i'm going to give them a pass, it was the early to mid 1990s. We learned a lot in the subsequent 5 years

  • and some of them are gotchas because null is allowed to exist

Real Example Code 1

if (request.getAttribute("billionDollarMistake") == "") { ... }

It's a gotcha because it's checking reference equality verses two strings being the same. Language design helping to cause bugs.

Real Example Code 2

The developer learned that the equality operator (==) checks for reference equality rather than equality. In the Java language you're supposed to call .equals if you want to check if two things are equal. No problem:

if (request.getAttribute("billionDollarMistake").equals("") { ... }

Except its a gotcha because the value billionDollarMistake might not be in the request. We're expecting it to be there, and barreling ahead with a NullPointerException.

Real Example Code 3

So we do the C-style, hack-our-way-around-poor-language-design, and adopt a code convention that prevents a NPE when comparing to the empty string

if ("".equals(request.getAttribute("billionDollarMistake")) { ... }

Real Example Code 4

But that wasn't the only way i saw it fixed:

if ((request.getAttribute("billionDollarMistake") == null) || (request.getAttribute("billionDollarMistake").equals("")) { ... }

Now we're quite clear about how we expect the world to work:

"" is considered empty
null is considered empty
therefore  null == ""

It's what we expect, because we don't care about null. We don't want null.

Like in Python, passing a special "nothing" value (i.e. "None") to a compare operation returns what you expect:

a null takes on it's "default value" when it's asked to be compared

In other words:

  • Boolean: None == false true

  • Number: None == 0 true

  • String: None == "" true

Your values can be null, but they're still not-null - in the sense that you can get still a value out of them.


r/ProgrammingLanguages • • Sep 05 '20

Discussion What tiny thing annoys you about some programming languages?

139 Upvotes

I want to know what not to do. I'm not talking major language design decisions, but smaller trivial things. For example for me, in Python, it's the use of id, open, set, etc as built-in names that I can't (well, shouldn't) clobber.


r/ProgrammingLanguages • • May 01 '23

Flattening ASTs (and Other Compiler Data Structures)

Thumbnail
cs.cornell.edu
138 Upvotes

r/ProgrammingLanguages • • Nov 02 '22

I wrote my first interpreter!

136 Upvotes

Hi! Hope you guys are doing great!

I've been part of this subreddit for a while now (I haven't posted anything until now, but I do read most of the posts on the sub and most of the comments on such posts) and after a lot of inspiration and good ideas gathered from multiple places, I was able to write my first tree walk interpreter for a superset of the Lox programming language.

Initially the whole project started as a read through of Crafting Interpreters and Compilers, but after a while I decided to add additional features (that I consider cool and useful), in order to keep on learning how the different parts on an interpreter fit together and how to represent certain language constructs on my own. It may not be the most efficient or cool implementation, but it definitely was a good starting point.

I decided to name my superset L# (it's written on C# and it's a Lox superset. How original, right?), it's in a super alpha stage but again, I think it is a good starting point. I want to thank all of you, since your comments on certain questions were pretty useful when I had a blurry idea on mind and needed some guidance to materialize it.

You can take a look at the GitHub repo if you want. Any comments will be well appreciated!

Have an awesome day!


r/ProgrammingLanguages • • Feb 28 '22

Lambda Calculus in 400 Bytes

Thumbnail
justine.lol
136 Upvotes

r/ProgrammingLanguages • • Jan 25 '24

Discussion A list of the worst gotchas of each language?

135 Upvotes

I like to choose languages by the pain they don’t cause me.

I’m about to rage quit Python because i discovered, after hours of debugging, that singletons like enums are not actually singletons. If you imported a module via a relative path in one spot, and an absolute path in another. Those are two different modules, as far as Python is concerned. Here's a demo:

https://github.com/dogweather/python-enum-import-issue

Has anyone made a list of tragic flaws like the above? I need a new language and it doesn’t have to have a million features. It just can’t be Mickey Mouse.


r/ProgrammingLanguages • • Nov 14 '23

Blog post A decade of developing a programming language

Thumbnail yorickpeterse.com
135 Upvotes

r/ProgrammingLanguages • • Jan 27 '23

Language announcement Cyber is a new language for fast, efficient, and concurrent scripting

Thumbnail
cyberscript.dev
134 Upvotes

r/ProgrammingLanguages • • Jul 05 '20

How JIT Compilers are Implemented and Fast: Julia, Pypy, LuaJIT, Graal and More

Thumbnail
carolchen.me
134 Upvotes

r/ProgrammingLanguages • • Apr 05 '20

Blog post Crafting "Crafting Interpreters"

Thumbnail
journal.stuffwithstuff.com
134 Upvotes

r/ProgrammingLanguages • • Nov 30 '19

Garbage Collection · Crafting Interpreters

Thumbnail
craftinginterpreters.com
134 Upvotes

r/ProgrammingLanguages • • Aug 21 '25

I designed an assembly language, built a compiler for my own high-level language, and now I'm writing an OS on top of it.

Thumbnail
github.com
133 Upvotes

I've been working on Triton-64, a 64-bit virtual machine I built in Java to better understand how computers and compilers actually work. It started as a small 32-bit CPU emulator, but it slowly grew into a full system:

  • Custom 64-bit RISC architecture (32 registers, fixed 32-bit instructions)

  • Assembler with pseudo-instructions (like `LDI64`, `PUSH`, `POP`, and `JMP label`)

  • Memory-mapped I/O (keyboard input, framebuffer, etc.)

  • Bootable ROM system

  • A high-level language called Triton-C (how original) and a compiler that turns it into assembly with:

    • Custom malloc / free implementations + a small stdlib (memory, string and console)

    • Structs and pointers

    • Inferred or explicit typing / casting

  • Framebuffer that can display pixels or text

I'm wondering if I should refactor the compiler to have an IR (right now I'm translating directly to ASM) but that'd take a very long time. Also right now the compiler has a macro so you can declare strings directly (it calls malloc for you and then sets the memory to a byte array) but I don't really have a linker so you'd always have to provide a malloc implementation (right now im just pasting the stdlibs in front of any code you write before compiling so you always have a malloc and free) I'd like to know what you think about this.

I’m also trying to write a minimal OS for it. I’ve never done anything like that before, so honestly, I’m a bit out of my depth. I've started with a small shell / CLI which can run some commands, but before starting with different processes, stacks and memory seperation I'd like to hear some feedback:

  • Are there changes I should consider in the VM / Tri-C compiler to make OS development easier?

  • Anything missing that would help with the actual OS?

  • Any resources or projects you’d recommend studying?

I’m trying to keep things simple but not limit myself too early.

Github: https://github.com/LPC4/Triton-64

Thanks for reading, any thoughts are welcome.


r/ProgrammingLanguages • • Nov 21 '20

[meme] Isn't it?

Post image
133 Upvotes

r/ProgrammingLanguages • • Jul 29 '24

What are some examples of language implementations dying “because it was too hard to get the GC in later?”

132 Upvotes

In chapter 19 of Crafting Interpreters, Nystrom says

I’ve seen a number of people implement large swathes of their language before trying to start on the GC. For the kind of toy programs you typically run while a language is being developed, you actually don’t run out of memory before reaching the end of the program, so this gets you surprisingly far.

But that underestimates how hard it is to add a garbage collector later. The collector must ensure it can find every bit of memory that is still being used so that it doesn’t collect live data. There are hundreds of places a language implementation can squirrel away a reference to some object. If you don’t find all of them, you get nightmarish bugs.

I’ve seen language implementations die because it was too hard to get the GC in later. If your language needs GC, get it working as soon as you can. It’s a crosscutting concern that touches the entire codebase.

I know that, almost by definition, these failed implementations aren't well known, but I still wonder if there were any interesting cases of this problem.


r/ProgrammingLanguages • • Apr 15 '22

Requesting criticism A somewhat old-fashioned programming language

132 Upvotes

easylang is a rather minimalistic simple programming language. Because of the clear syntax and semantics it is well suited as a teaching and learning language. Functions for graphic output and mouse input are built into the language.

The language is written in C and is open source. Main target platform is the web browser using WASM. However, it also runs natively in Windows and Linux.

The one-pass parser and compiler is quite fast. In the Web IDE, each time the Enter key is pressed, the program is parsed and formatted up to the current line.

The AST interpreter is fast, much faster than CPython for example.

The language is statically typed and has as data types numbers (floating point) and strings and resizeable arrays. Variables are not declared, the type results from the name (number, string$, array[]).

Uses: Learning language, canvas web applications, algorithms.

For example, I solved the AdventOfCode tasks with easylang.

https://easylang.online/

https://easylang.online/ide/

https://rosettacode.org/wiki/Category:EasyLang

https://easylang.online/aoc/

https://github.com/chkas/easylang