Execute ruby code sometimes (little helpers to encourage variety)
github.com
github.com
That said, I think that incorporating randomness or hidden variables into a user interface is rather misguided. Making a system harder to reason about takes control away from the user- it's basically an even more severe version of the problems with "Do What I Mean" in general.
I like that "action potential" idea – I was trying to think of a good implementation for "do something twice a month per user" — decaying counter is a nice idea.
I'm with you on willy nilly making parts of your UI random — my use case is for changing up the text in greetings, general play with copy, and once in a while showing something like a tip or a "welcome back" message. Basically, small touches that convey a small sense of variety (vs. RANDOMLY DONT SHOW THE NAV!)
Then whoever looks after the wording can just add as many strings as they like, for any messages they think could do with some variety. No forward planning required, because the code to do this is centralized, so it works for any string.
What is awesome about what you've done is the idea and the interface. I'd focus on expanding that with more interesting use cases. For example it would be cool if this hooked more neatly into rails localization where I could say something like:
= t('some_set_of_possible_stuff.*')
Or whatever. I agree with the other poster who states it makes your app more hard to test however that is not a good enough reason to not do something by itself. It just means you need to be measured in how and where you do it and careful. In the right app, the value to the end user experience wrt personalization is super high so it is worth it.
> rarely do
Are terrible for maintainability. Imagine that you are reading through the code of a programmer who used this library - What is 'sometimes'? What is 'rarely'? It would need to be documented on each usage to save half an hour of digging and cursing for the poor sap who encounters it.
> 1.percent_of_the_time do
For the same reasons, this would be better named "times_out_of_one_hundred" since The Time usually means a time of some sort being somewhere (i.e. the 21:43:21 type of time).
At least you foresaw some peoples' reactions to this:
https://github.com/sudara/sometimes/blob/master/test/helper....
So — my thinking for those two methods is to purposefully encourage being imprecise. We are always so obsessed with being exact in programming. And typically for good reasons. But in some cases, perhaps it doesn't matter if it's 50% of the time or 20% or 10% of the time. Just sometimes, not all of the time.
That being said, you bring up a fantastic point: what the hell does 'sometimes' mean? Half the time? What does rarely mean? It's certainly going to depend on the individual. No answers here, except I'm leaning towards redefining "sometimes" to mean between 15-50% of the time.
My system Yo's me ever since.