Replies: 2 comments 1 reply
-
I looked at it and even did the changes but I'm not sure what's the best approach from a user perspective. While I understand your point of wanting things to be easy, I think that there's also value in guiding the user to make the right decision through the language. Here are some options:
This has the potential to hide important bugs while making the programmer's life easier. This is my least favorite but the most user-friendly.
This is also the most user-friendly but, exceptions should really be used sparsely in liquidsoap because we want scripts to run forever without errors.
This is the least user-friendly but, it forces the user to think about what to do when the string does not begin with the given prefix while also making sure that there will not be a bad error raised, potentially crashing the script. Lastly, it's important to remember that we have a coalesce notation to deal with
This makes it possible to have a default empty string from the function with very little added code. For these reasons, I'm in favor of keeping things the way they are. I think the extra coalesce is a fair compromise. |
Beta Was this translation helpful? Give feedback.
-
I'm happy with using the coalesce notation… I just usually don't think about it. Full explicit exception handling for that use-case would be avoided smartly by just rewriting string.residual() for that case ;) We again have many documentation / examples broken due to all that, I'll try to uncover them as I find them… |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
string.residual does not return a string, because it can return null(), and that seems counter-intuitive
To Reproduce
string.residual(prefix='toto_', 'toto_titi)
So I need to string() the output, and I'd say that's because of the null() in src/libs/string.liq#L108 which is somehow reasonable, but makes that function a bit annoying to use if you ask me ;)
Expected behavior
Maybe return "" so it can be a string, like string.sub() does?
Version details
Install method
Using assets from github actions
Beta Was this translation helpful? Give feedback.
All reactions