Am I understanding premature optimization correctly?

前端 未结 3 1237
别跟我提以往
别跟我提以往 2021-01-06 02:43

I\'ve been struggling with an application I\'m writing and I think I\'m beginning to see that my problem is premature optimization. The perfectionist side of me wants to mak

3条回答
  •  被撕碎了的回忆
    2021-01-06 03:12

    We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. -- Hoare

    While @John Saunders nails it, applying TDD alone might not completely addresses your concerns. I adhere to TDD, and when you do TDD correctly, and if you can apply refactoring effectively, you typically end up with much leaner code, and with the benefit that you know it works. No arguments there.

    However, I see too many developers write performance-ignorant code - avoiding premature optimization is no excuse for writing sloppy / lazy / naive code. Writing unit tests doesn't prevent this. Although someone who writes unit tests is probably a better coder, and better coders are less apt to write bad code as often.

    Do write tests, and do include performance testing into your suite of tests for the scenarios your stakeholders identify. e.g. retrieve 100 discounted products for a specific vendor, and include stocking levels and format as Xml in under 3 seconds

    The fallacy that "premature optimization" is the same thing as "concern about performance" should not guide software development. -- Randall Hyde

    If you leave performance concerns too late, you may find it's too hard, or too costly to change.

    Some articles

    • The Fallacy of Premature Optimization
    • Premature Optimization

提交回复
热议问题