A piece of advice I read somewhere early in my career was "a boolean should almost never be an …
A piece of advice I read somewhere early in my career was "a boolean should almost never be an argument to a function". I didn't understand what the problem was at the time, but then years later I started at a company with a large Lua code-base (mostly written by one-two developers) and there were many lines of code that looked like this: serialize(someObject, true, false, nil, true) What does those extra arguments do? Who knows, it's impossible without looking at the function definition. Basically, what had happened was that the developer had written a function ("serialize()", in this example) and then later discovered that they wanted slightly different behaviour in some cases (maybe pretty printed or something). Since Lua allows you to change arity of a function without changing call-sites (missing arguments are just nil), they had just added a flag as an argument. And then another flag. And then another. I now believe very strongly that you should virtually never have a boolean as an argument to a function. There are exceptions, but not many.
Original discussionThat boolean should probably be something else136 source comments · at import