# From Clever code to Better code

- Speaker: [Dror Helper](/wiki/speakers/dror-helper.md)
- Event: [Reversim Summit 2019](/wiki/years/2019.md)
- Video: https://www.youtube.com/watch?v=IHmgcO4Gaw0
- Transcript: [/transcripts/2019/22-IHmgcO4Gaw0.md](/transcripts/2019/22-IHmgcO4Gaw0.md)
- Language: Hebrew and English · Type: talk · Level: intermediate
- Topics: [Performance](/wiki/topics/performance.md), [Software Engineering](/wiki/topics/software-engineering.md), [Technical Debt](/wiki/topics/technical-debt.md), [Scalability](/wiki/topics/scalability.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker explores the temptation of writing "clever" or over-optimized code versus readable code. Through various examples in C and C++, the speaker shows how tricky code can provide a false sense of intellectual satisfaction while severely hurting maintainability. The audience learns to recognize when low-level tricks or excessive optimization are justified, such as in rare performance bottlenecks, and when they should be avoided in favor of clean, readable code.

## Key points

- [2:18](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=138s) Developers often write clever code out of a sense of capability, perceived constraints, or the belief that it improves performance.
- [4:23](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=263s) Clever optimizations like loop unrolling can make code functionally correct but extremely difficult for other developers to read and maintain.
- [6:27](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=387s) Bitwise operations are frequently used to show off skills, but simple arithmetic is usually much easier to understand.
- [11:32](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=692s) Using exceptions for normal control flow or unexpected behavior like a find function not returning a value violates user expectations.
- [13:32](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=812s) Reading and debugging code takes significantly more time and energy than writing it, making clever code a liability.
- [18:49](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=1129s) Extremely complex low-level hacks, such as the fast inverse square root from game engines, are sometimes justified by extreme performance requirements.
- [22:03](https://www.youtube.com/watch?v=IHmgcO4Gaw0&t=1323s) If complex low-level logic is truly necessary, it should be encapsulated inside a black box so consumers do not have to read the internals.

## Takeaways

- Prioritize code readability and maintainability over showing off technical cleverness.
- Do not optimize for performance without proving it is a genuine bottleneck.
- Encapsulate complex or low-level logic so that other developers can use it without needing to understand the underlying hacks.

## Questions this talk answers

- How can I balance extreme performance requirements with code readability?
- What are the best practices for encapsulating complex low-level code?
- Why is debugging complex code significantly harder than writing it?

## Technologies

C, C++, Visual Studio, AWS, .NET

## Tags

c++, clean code, code readability, low level programming, maintainability, performance optimization
