Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In my view you should make it a habit to write optimized code.

It depends on your domain.

If you're writing for embedded, or games, or other things where performance is table stakes, then sure.

If you're writing code to meet (always changing) business requirements in a team with other people, writing optimized code first is actively harmful. It inhibits understandability and maintainability, which are the most important virtues of this type of programming. And this is true even if performance is important: optimizations, i.e. any implementation other than the most obvious and idiomatic, must always be justified with profiling.



You're mostly right, but even in typical LOB applications, there are some low-hanging fruits you should really pay attention to. One common example are N+1 queries.

And if you do find yourself writing an algorithm (something which happens more rarely in LOB applications, but can still happen occasionally), it's probably still good to create algorithms that are of a lower complexity class, provided they are not that much harder to understand or don't have other significant drawbacks. I remember that I once accidentally created an algorithm with a complexity of O(n!).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: