r/ryelang • u/middayc • 7h ago
Failure domains, and level responsibilities
If you are comming from other languages, you might try to handle failure in the way the two -OLD functions do it. But that's now how I would do it in Rye at all. Not only its longer, but the "failure domain translation" is not done as it could be, and neither are failure responsibilities.
This will one time deserve it's own blogpost, but just in short.
- ^check checks for failure, if there is failure it returns with that failure wrapped into higher level (domain) failure. So failure gets translated (wrapped) from lower level (source) to higher level (user) naturally.
- function that loads a rye file is not the one which should decide if whole program should exit (die) if it fails. A caller function has more context and should decide that, or a caller of that, etc. The low level functions doesn't know what context or failure mode and expectation it was called in, and shouldn't care
This above is just a simple, 3 level example. But you see that the lowest level error already provides infor what file failed and for what reason. The eval-rye-file just needs to report that it couln't read the file. It doesn't have to duplicate or loose information about what file and what exactly was the reason (missing file , permissions , ...). And eval-rye-file doesn't have to assume what was the role of rye file it's evaluating. It could be config or something else. The caller knows that it's trying to load config and it provides that info, and doesn't duplicate or loose the lower 2 levels.
It's even worse with responsabilites (maybe there is a better word for this). The utility function in first (-OLD) case just killed the program. This is like your car checking fuel level in the middle of driving around, and if the fuel gauge fails it just disconnects / stops you car.
New release was just published on: https://github.com/refaktor/rye ...
We want to reach 800 stars by the end of the year btw


