Alex Rivera | Logout

Performance vs Readability

Asked 2008-08-27T18:09:42.877
21

Reading this question I found this as (note the quotation marks) "code" to solve the problem (that's perl by the way).

100,{)..3%!'Fizz'*\5%!'Buzz'*+\or}%n*

Obviously this is an intellectual example without real (I hope to never see that in real code in my life) implications but, when you have to make the choice, when do you sacrifice code readability for performance? Do you apply just common sense, do you do it always as a last resort? What are your strategies?

Edit: I'm sorry, seeing the answers I might have expressed the question badly (English is not my native language). I don't mean performance vs readability only after you've written the code, I ask about before you write it as well. Sometimes you can foresee a performance improvement in the future by making some darker design or providing with some properties that will make your class darker. You may decide you will use multiple threads or just a single one because you expect the scalability that such threads may give you, even when that will make the code much more difficult to understand.

Edit
Report

2 Answers

1

I would say that you should only sacrifice readability for performance if there's a proven performance problem that's significant. Of course "significant" is the catch there, and what's significant and what isn't should be specific to the code you're working on.

answered 2008-08-27T18:12:20.407
1

"Premature optimization is the root of all evil." - Donald Knuth

answered 2008-08-27T18:18:24.557

Your Answer