r/ProgrammingLanguages • u/yassinebenaid • Jan 14 '26
Requesting criticism Panic free language
I am building a new language. And trying to make it crash free or panic free. So basically your program must never panic or crash, either explicitly or implicitly. Errors are values, and zero-values are the default.
In worst case scenario you can simply print something and exit.
So may question is what would be better than the following:
A function has a return type, if you didn't return anyting. The zero value of that type is returned automatically.
A variable can be of type function, say a closure. But calling it before initialization will act like an empty function.
let x: () => string;
x() // retruns zero value of the return type, in this case it's "".
Reading an outbound index from an array results in the zero value.
Division by zero results in 0.
View all comments
Show parent comment
1
u/syklemil considered harmful Jan 15 '26
The general idea of trying your damnedest to recover and move forward with wrong data rather than erroring out already exists, though. E.g. the following Perl program:
prints
the value of x is ''.and then exits successfully. Perl over time moved away from that style and towards pragmas likeuse warningswhich produces the same output and still completes successfully, but prints some warnings, anduse strict, which crashes the program with an error messageThe same general trend can be seen in PHP and Javascript, which over time have added more strictness (like introducing and recommending
===over their variant of==). Both of them have been considered easy to get into, but then ultimately hard to get working right, exactly because of that wish to never panic.You could probably look to Js for some inspiration around numbers. It's all floats, which means that they also don't panic on division by zero, but they do return plus/minus
Infinityfor most cases, andNaNfor the0/0case, which is more correct than your idea of just returning 0.