“Function calls are expensive” vs. “Keep functions small”

前端 未结 5 703
执笔经年
执笔经年 2020-12-12 23:45

On the one hand, I read or hear that \"function calls are expensive\" and that they impact efficiency (for example, on Nicholas Zakas\' Google tech talk).

On the oth

5条回答
  •  一整个雨季
    2020-12-13 00:10

    In a perfect world, where there's no bugs (because code just fixes itself magically), and requirements are frozen from the day one, it may be possible to live with huge omnipotent functions.

    But in this world it turns to be just too expensive - and not only in terms of 'man-month'. Nicholas Zakas wrote a brilliant article describing most of the challenges software developers face these days.

    The transition may seem somewhat artificial, but my point is that 'one function - one task' approach is much more maintainable and flexible - in other words, it's what makes BOTH developers and customers happy, in the end.

    It doesn't mean, though, that you'd not strive to use as few function calls as possible: just remember that it's not a top priority.

提交回复
热议问题