The Art of Readable Code

📖 Summary of The Art of Readable Code 1. Code Should Be Easy to Understand Key Idea: Minimize time-till-understanding. Readable code is more important than short code. Example: // Less clear return exponent >= 0 ? mantissa * (1 << exponent) : mantissa / (1 << -exponent); // Clearer if (exponent >= 0) { return mantissa * (1 << exponent); } else { return mantissa / (1 << -exponent); } 2. Packing Information into Names Names are mini-comments. Use specific and concrete words. Attach units or attributes if critical. Example: # Bad def GetPage(url): ... # Better def FetchPage(url): ... Example with units: ...

29/08/25 · 4 min · 698 words · me

Handle Json Key Case

When working with JSON data from different sources, you might see inconsistent key names, like: { "tTien": 1000, "ttien": 1000, "tthue": 100, "tThue": 100, "TThue": 100 } Different places use different names, which is annoying. Using try/except, if/else, or match/case makes the code messy and error-prone. Simple solution: Before processing, convert all keys to lowercase. It’s fast and easy to maintain: data = {k.lower(): v for k, v in original_data.items()} Now you can just use data['ttien'], data['tthue'] without writing long code. ...

03/07/25 · 1 min · 111 words · me