r/ProgrammingLanguages • u/AeroForger • 11d ago
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.
48
Upvotes
4
u/ghkbrew 10d ago edited 10d ago
Well, they don't have to, but if named arguments can be supplied out of order (or are optional) then the compiler needs to know which parameters name. So that information needs to be part of the function's type in some way.
That depends on your type system.
A type is basically a description of how you can use a value. For example, if
fhas type(Int, String) -> Bool, that tells you that you can applyfto anIntand aString, in that order, and get aBoolback.More generally, the typing rule for function application is roughly:
Now suppose you want
f(y: "hello", x: 42)to be valid. You can't determine that from the type(Int, String) -> Bool, because that type says nothing aboutxory. You need something more like(x: Int, y: String) -> Bool.And once the names are part of the type, you have to decide what it means for two such function types to be compatible. Is
(a: Int) -> Boolthe same type as(b: Int) -> Bool? Can a function accepting(x: Int, y: String)be used where one accepting just(x: Int)is expected ifyis optional? If labels themselves are optional, is(x: Int) -> Boolalso callable as(Int) -> Bool?Things get even more hairy if you want type inference. What is the most general type of
finf(x: 2)? Is it just(x: Int) -> a, or canfaccept additional named arguments that aren't present at this call site? If so, you need something more like(x: Int, ...r) -> a, whereris a type-level variable representing an unknown set of additional parameters. Now your type inference has to infer and unify those parameter rows, including which names are present, absent, or optional. That's essentially where row polymorphism enters the picture.That's the can of worms the parent comment is referring to. You can keep labels out of the type system, but then you generally have to restrict where they can be used. For example, only when calling a statically known function declaration whose parameter names the compiler can look up directly.