Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Functions

As far as possible, we will avoid undeclared side effects in our functions. If a function is there to update a table, that's all it will do; it will have no effect on the rest of the program's data. If the data needs updating before we can use it in the table, then we will create and call a separate updateData function before updating the table itself.

Related to this, it should be possible to tell from a function's name, its arguments list, and its return statements, exactly what effects that a function will have. If our function destroys the Death Star and returns a random float between one and zero, we won't call it randomFloat(), but randomFloatWithDeathStarDestruction().