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/Inconstant_Moo 🧿 Pipefish Jan 14 '26
I do that. Except that this works fine if you're using it as a declarative language in the REPL, an error is just an error, when it goes up the stack then if it isn't caught along the way it'll eventually hit the REPL and tell you that you tried to divide it by 0, don't do it again.
But if you write a Good Old Fashioned App with a
maincommand, then this doesn't work, ifmaindoesn't catch the error then the only way for it to go up the stack is to return itself as what you got when you calledmain, at which point it has in fact behaved like a panic and aborted the program.