r/ProgrammingLanguages • • Sep 21 '26

Discussion What’s one thing you wish more programming languages had?

If you could add one feature, behavior, or design choice to a programming language, what would it be?

It can be anything: syntax, type-system features, memory management, compiler behavior, tooling, error handling, performance-related features, or something completely different.

I'm especially curious about things you’ve wanted while actually programming but rarely see languages implement well.

Please keep the ideas reasonably practical and something that could realistically be implemented in a programming language.

58 Upvotes

299 comments sorted by

View all comments

Show parent comment

2

u/qalmakka Sep 23 '26

Yes, more or less tagged unions, which are surprisingly rare outside of functional languages

1

u/UdPropheticCatgirl Sep 23 '26

Which mainstream statically typed programming language, that’s not called Go or C# doesn’t have some form of sum types? I guess if you require safe discrimination then FORTRAN and C as well, and kinda C++ , but it has variant, it just sucks ass… Every other one has them, Java, Scala, Rust, Dart, Swift, Kotlin, Ada, Object Pascal and TS all have them…

1

u/qalmakka Sep 23 '26

Most of the java/.net languages don't really have tagged unions, they have sealed classes with a somewhat meh pattern matching. And pattern matching on types in typescript basically requires having an explicit discriminant due to its dynamic typing underneath. In most of the current crop of popular languages both sealed classes, variant, ... are a later addition and the path of least resistance is often to abuse inheritance (which is front back and centre) instead of that. The only exceptions are as you mention Rust, Swift and the functional languages

1

u/UdPropheticCatgirl Sep 23 '26 edited Sep 23 '26

> Most of the java/.net languages don't really have tagged unions, they have sealed classes with a somewhat meh pattern matching.

JVM and .NET are not similar at all here tho, like C# has pending proposal for this, but it’s pretty limited and the semantics are not particularly well thought out…

JVM on the other hand has had VM level support for sum types for years, and Java the language has support for full blown GADTs (which for example the aforementioned rust doesn’t), albeit actually using them can be bit awkward because of rules around type refinement in javas type system…

Also whether sum type is or isn’t tagged union is largely an implementation detail of the compiler… Neither Rust “enum”, nor Java “sealed interface” are actually implemented as “100% real & true” tagged unions anyway…

Also both Scala and Java support basically everything Rust supports in their pattern matching (Scala actually supports more, because it has decent support for GADTs)… So I don’t know what makes it meh for you, Kotlin is the only major JVM language with less expressive pattern matching system…

Also complaining about Java using “sealed interface” as a name for their nominal sum type is like complaining that languages like Scala and Rust opted to call theirs “enum”…

> are a later addition and the path of least resistance is often to abuse inheritance (which is front back and centre) instead of that. The only exceptions are as you mention Rust, Swift and the functional languages

Path of least resistance in Scala and Ada is most certainly not inheritance, and I would argue that neither is it in Java, the path of least resistance in modern Java is to spam records everywhere and those don’t even support actual inheritance, and the sealed types in Java aren’t even more verbose than inheritance in Java (both are pretty verbose since it’s java after all, but there’s no meaningful difference in how much you have to actually type out…)… Nor is it path of least resistance in TS, people just use structural subtypes there…

Weirdly enough I have also not found that to be true in my experience working with “modern” C++, path of least resistance, there typically involves doing something extremely convoluted with templates, but usually not inheritance…

1

u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Sep 24 '26

We just call them union types in Ecstasy.

typedef Table | Chair | Cupboard as Entity;

Whether they're tagged or not, that's an internal implementation detail.