Optimizing Python Code for Readability

In some Python Deep Learning example code I used for one of my cameras, one line does 20 things at once...slices one array to use as an index into another, filters, slices, dices, rotates...yech! It took me a loooong time to pull that line of code apart piece by piece... The rule developed over time was readability over obfuscated, cutesy bullsh*t... Somehow we have regressed.

Your "clean code" is slowing your team down. Unpopular opinion: the obsession with "clean code" creates more problems than it solves. I've reviewed thousands of lines of "clean" code that was: → So abstracted that nobody understood the flow → So DRY that changing one thing broke 5 features → So patterned that simple tasks required 8 files → So "elegant" that onboarding took 3x longer Here's what I've learned from 8+ years in enterprise codebases: The best code isn't the most elegant. It's the code your team can understand, change, and ship with confidence at 2AM when production is down. "Clean" is subjective. Readable is measurable. What actually matters: 1. Can a new team member understand this in 5 minutes? 2. Can we change this without breaking something else? 3. Can we ship this with confidence? 4. Can we debug this at 2AM? If the answer is yes to all four, your code is good enough. Ship it. If you spent 3 days making it "clean" and the answer is still no to #1, you wasted your time. Pragmatism over purism. Every time. Agree or disagree? I want to hear your take. #softwareengineering #cleancode #programming #hottake

  • No alternative text description for this image

But, if understanding everything in the code is now optional since we are delegating this part to AIs ("explain what this class does" or even "change this class to do Y and Z" - meaning "I do not care what was there nor do I need to understand it") then maybe indeed "clean code" is less valuable? Though, the core point this guy makes - pragmatism over purism - is not a bad philosophy.

Mike Schoonover I’m curious - what did your final readable version look like? Did you break it into multiple lines or helper functions?

I agree that going to extremes is never good. However, it's important not to fall into the other trap — creating 'spaghetti code.' The original idea of 'Clean Code' is actually meant to help a new team member understand it quickly. The problem isn't the concept itself, but rather its misinterpretation and blind fanaticism.

After one writes a compiler or two, and an interpreter, one goes: “did they cram all this in, thinking it would save what, exactly? Disk space for the source?” I’m all for Obvious Code.

If Clean Code is slowing your team down then it's not Clean Code. CC also depends on Clean Architecture and consistent programming standards.

c - code review---- so if somebody doesn't understand clean code - write comment. Code is incremental process, code review not only for quality but for understanding for sure.

See more comments

To view or add a comment, sign in

Explore content categories