Exercism: Bob

It is not just an elixir thing. When working with some construct like cond you should alsways have short and concise conditions, which are easy to read and tell you not only how data has to look like, but what it actually means.

When you want to know if some property p of data is either true or false you really should give that property a proper name and make it a function suffixed by a questionmark and use it. Just consider how much better ends_in_questionmark?(input) reads compared to input |> String.replace(~r/[\s]/, "") |> String.replace(~r/[\d]/, "") |> String.last == "?", just consider how much question?(input) does even better suites the context of the exercise!

Katrina Owen (creator of exercism) gave some nice talks about refactoring in ruby, one of these talks was even about our friend bob: Katrina Owen – Overkill; 2014. There is much stuff one can transfer to elixir. Propably not the stuff about extracting into various classes, but it would make sense to extract the predicates into separate modules. Haven’t done it so far in my own solutions though, since I’ve watched Katrinas talks just 14 days ago.

2 Likes