Open Zamua opened 5 years ago
Very interesting. Are there any other languages with a "default true" return value?
Ruby by default returns nil
, and nil
is a falsy value so it's similar. LJ wouldn't have truthy and falsy values (unless we feel strongly about adding that)
Perhaps we should remove the use of void as a return type. Objects that perform an operation that modify themselves and don't necessarily have something to return can return themselves (similar to the builder pattern).
Example:
Procedures that aren't related to a class can always return a boolean indicating success or failure. We can even make the lack of a return be considered a success.
Example:
It might encourage chaining procedures together like so:
This is possible in the current state of LJ, but it might be further encouraged if we default return types to boolean (is this something we want to encourage?).
Presumably function definitions and class definitions would now also be expressions if we were strict about "no statements" which would mean LJ has first-class functions (and potentially lambdas).
Treating everything like an expression feels more clear. It might seem odd to beginners that some funny words "return" stuff while other funny words "do" stuff. Some beginners have trouble figuring out when to use
print()
and when to use areturn
for example.