Specific functions vs many Arguments vs context dependent

后端 未结 6 800
生来不讨喜
生来不讨喜 2020-12-20 17:44

An Example

Suppose we have a text to write and could be converted to \"uppercase or lowercase\", and can be printed \"at left, center or right\".

Specific

6条回答
  •  太阳男子
    2020-12-20 17:59

    I suggest more cohesive functions as opposed to superfunctions that can do all kinds of things unless a superfunction is really called for (printf would have been quite awkward if it only printed one type at a time). Signature redundancy should generally not be considered redundant code. Technically speaking it is more code, but you should focus more on eliminating logical redundancies in your code. The result is code that's much easier to maintain with very concise, well-defined behavior. Think of this as the ideal when it seems redundant to write/use multiple functions.

提交回复
热议问题