The Mini Micro environment has a number of utility modules in the /sys/lib folder. These are the place for functions that are not so commonly needed that they deserve to be part of the MiniScript core, but they are handy enough that we want to make them available for people who need them.
You add these extra functions to your environment by doing, for example:
And now you have a module of handy functions to reverse a list, remove a list element by value rather than by index, etc. Other modules would add math utilities, string utilities, etc.
The question is, for functions that act directly on a particular data type, like a list... would you prefer:
- Ordinary methods you call via the module name, and pass the list in, e.g.:
listUtil.removeVal someList, "foo" ? Or,
- Methods added to the list datatype, so you call them like the built-in ones, e.g.:
I suppose I could provide both... perhaps "listUtil" is a module of methods you invoke like
listUtil.removeVal (option 1) but "listExt" actually extends the list type with things like
list.removeVal (option 2). Then users could use whichever they prefer.
Normally I don't like to provide lots of different ways of doing the same thing; I think it just adds confusion, especially when people share code. But in this case I'm really on the fence. I started with option 1, thinking that this was clearer and less mysterious; when you read the code, you can immediately tell that removeVal is part of the listUtil module when it's written as
listUtil.removeVal. So, option 1 wins on clarity. But as I've been using it myself, it's starting to annoy me — it's a lot more to type, and doesn't fit with what I've come to expect based on all the built-in methods. Option 2 wins on ease of use.
I need some opinions to help push me off the fence. What do you all think?