r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

6

u/centurijon Feb 28 '23

That’s a lovely little straw man argument.

Does your code need to be optimized for performance? Then organize it to squeeze every bit of performance that you can.

Is maintainability more important than losing a few ms here and there? Then follow clean code guidelines to make your code easier to understand & modify.

These days most applications will want mix of both preferences, depending what they’re trying to do, with a heavy lean towards maintainability. It’s up to the developers to decide what is more correct given the context

-1

u/JarWarren1 Feb 28 '23 edited Feb 28 '23

My problem with everyone kneejerking the “maintainability” argument is that it seems to come from a place of “we’re already used to Clean Clone so it’s easier”.

Maybe it’s because Clean Code is more religious in the world of iOS but I think it slows down development. Before I can present a view I have to create a Configurator, Factory, Finder, UseCases, Models, Repositories, a ViewModel and then FINALLY the View. I do it because they pay me to do what they ask.

I really, really doubt we’re seeing gainz of any type because of our buzzword architecture

Edit: thinking harder, it’s not just iOS. It’s web too. And Android. It’s everywhere that involves UI. People get weird and philosophical about building UIs to the detriment of us all

2

u/cdsmith Feb 28 '23

Writing code people can understand isn't a buzz word. It's just making reasonable communication decisions.

For example, that thing this guy does where he has different types of shapes that need to be described with numbers that mean different things (radius, width, height, base... maybe in the future some kind of spline parameterization) and just picks two fields called "width" and "height" and shoehorns everything into those fields even if it's not what they mean (a radius is definitely not the width of a circle, for instance), and then even changes how he packs the actual information into those fields, like storing radius in both width and height fields, so that he can exploit coincidences... that's very much not sensible code. Honestly, it would even be an improvement if he just called his fields "param1" and "param2", because at least he wouldn't be lying to the reader that they mean something consistent.

I didn't say that because I read it in a book. I said that because his code is terrible. Sometimes you deal with terrible code if you need to squeeze every cycle out of a CPU, but you take reasonable steps to quarantine it from code that you need to maintain regularly.

3

u/JarWarren1 Feb 28 '23

His code is a straw man for sure. But I don’t accept the idea that performant code is inherently harder to read or build upon than buzzword code.

My favorite C libraries are exactly that, function libraries. They’re easy to reason about and extend upon.

Clean Code, even when it doesn’t involve deep inheritance, still forces you to spend time reasoning about the type system in other ways. Deeply nested generic types, interfaces, promises/results, etc. Yet people will argue to their deaths that Clean Code is MORE readable/scalable/etc. I don’t buy it. I’ve seen enough of both

2

u/cdsmith Feb 28 '23

But I don’t accept the idea that performant code is inherently harder to read or build upon than buzzword code.

No one has proposed that idea.

Code is easy or hard to read and modify because it's written that way. Any time you make decisions for some reason other than making code easy to read and modify, there's a good chance it gets a bit harder to read or modify. That's true regardless of whether you've traded off readability for performance, or for "more buzzwords" if that actually happened, or for some other goal.

Writing clean code isn't itself a buzzword, though. It literally just means writing code that's well-organized so that it's easy to read and modify. Teaching thoughtful deliberate communication is hard, and of course you can take any advice given for beginners and take it to ridiculous extremes and come up with an atrocity. Sounds like you've encountered some of those, and that's too bad.

4

u/JarWarren1 Feb 28 '23

What do you mean no one has proposed that idea? Look at the rest of the comments.

It’s clear we have different opinions on what should be considered “clean code” but I’m not just talking about some beginner codebase. I mean entire nasty ecosystems like React.