News for hackers. Stuff that matters.
Re:“Clean” Code, Horrible Performance by TheFattestNinja on Tuesday February 28, 2023 @04:38AM (#34967443)
Casey is a bit of a hardcore crusader on the topic, but I'd hardly call dogmatic someone who can provide you evidence and measurements backing their thesis.

The tests he put together here are hardly something I'd call a straw-man argument, they seem like reasonable simplification of real-cases.

Re:“Clean” Code, Horrible Performance by st3fan on Tuesday February 28, 2023 @07:19AM (#34968469)
Evidence in a micro benchmark of a single page of code.

The focus on performance here ignores the fact that most programs are large systems of many things that interact with each other. That is where good design and abstractions and “clean code” can really help.

Like all things it is about finding a balance and applying the right techniques to the right parts of a larger system.

Re:“Clean” Code, Horrible Performance by TheFattestNinja on Tuesday February 28, 2023 @08:21AM (#34968966)
True, the example is simplistic, but that's just to make it fit within reasonable exposition. The author has in the past shown (elsewhere) how his techniques can actually make dramatic differences in more concrete examples (he rose to some Internet fame for building a performant shell that could actually handle larger outputs orders of magnitude better than most available alternatives).

To me the interesting point is the reminder that there is an innate tension between going fast and being "clean" (i.e. maintanable/understandable). And once you are aware of it you can make your decisions in an informed way. Too often this tension is forgotten/ignored/dogmatically put to the back ("performance doesn't matter over cleanliness" and the likes).

Mind you, I'm also of the camp that performance is very secondary to cleanliness in modern enterprises, but I appreciate a reminder of just how much we are sacrificing on this altar.

Re:“Clean” Code, Horrible Performance by cma on Tuesday February 28, 2023 @09:35AM (#34969712)
It was Windows Terminal he wrote something faster than. Windows terminal was doing a whole GPU draw call per character (at 2x standard terminal height, 160x25, it was as many draw calls as a AAA game).
Re:“Clean” Code, Horrible Performance by gongle on Tuesday February 28, 2023 @04:44PM (#34975294)
No matter what design choices you argue for there are always ways to be an idiot about the implementation
Re:“Clean” Code, Horrible Performance by vkou on Tuesday February 28, 2023 @07:34PM (#34977109)
Which is an excellent argument for why the WT team should have done some benchmarking, identified that they have a really dumb O(M*N) bottleneck in their rendering code, and optimized it.

It is not an excellent argument for why 'clean code' is not a better fit for the other 99% of their codebase.

Re:“Clean” Code, Horrible Performance by gjadi on Tuesday February 28, 2023 @09:28AM (#34969642)
I'd say that it really depends on what the code needs to do.

For example, if the code is to be distributed and extended as a third-party library, then the class hierarchy is probably a better fit to allow extensibility.

But if the purpose of the API is to compute the area of given shapes (as in the example), then it makes sense to make it efficient and there is no use to provide extensibility to the outside world.

The advocates of "clean code" that Casey mentions will go for extensibility no matter the use.

I find it very interesting to have numbers to weight what you are leaving when you go the extensibility route instead of the non-pessimistic route.

Re:“Clean” Code, Horrible Performance by st3fan on Tuesday February 28, 2023 @10:43AM (#34970518)
> The advocates of "clean code" that Casey mentions will go for extensibility no matter the use.

Unfortunately this is just some catchy stereotyping that probably doesn't match reality.

Re:“Clean” Code, Horrible Performance by gjadi on Tuesday February 28, 2023 @10:58AM (#34970717)
I don't know. Before reading Casey, I'd say most, if not all, of my APIs would look like the "clean code" style.

The process was "think about the model, design a class hierarchy that fits with the model, add the operations". Even if I don't think about extensibility, that's how I thought my code.

Why? Because when I think about performance, I used to think about algorithms and I/O optimizations (for example batching).

Now I'll look into this data-oriented programming-thing and see how that applies to my platform (embedded Java) :D

Re:“Clean” Code, Horrible Performance by jstimpfle on Tuesday February 28, 2023 @04:29PM (#34975100)
The code examples with the abstract / virtual methods for the most straightforward concepts are a clown show. Not cleanliness but madness.
Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @06:45PM (#34976603)
That's what you get with SOLID. Madness.
Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @06:44PM (#34976580)
I've seen at least one embodiment of the stereotype 3 months ago. It wasn't pretty, I was able to shrink his code by a factor of 5, and make it more flexible in the process. Among other mistakes he had some idea of flexibility, put part of the infrastructure in place, and then utterly failed to use it, such that when it came to test he required a monkey patching framework for C (Ceedling) so he could mock what he almost already mocked in the source code.

That's a fairly rare breed for sure, but the real problem was that nobody called him out. Well I did, but I'm no longer working there. I couldn't.

Re:“Clean” Code, Horrible Performance by ajmurmann on Tuesday February 28, 2023 @04:27PM (#34975075)
Unfortunately, everything in our profession is a tradeoff. Faster and maintainable are two of the many quality metrics you can optimize for that will be at odds at times. What the right balance is for a given piece of code depends on so much context. It's a hard balance to get right.
Re:“Clean” Code, Horrible Performance by Barrin92 on Tuesday February 28, 2023 @04:34PM (#34975169)
> they seem like reasonable simplification of real-cases.

Paraphrasing Russ Ackoff, doing the right thing and doing a thing right is the difference between wisdom and efficiency. What Casey is doing here may be efficient, but calculating a billion rectangles doesn't present a realistic or general use case.

"Clean Code" or any paradigm of the sort aims to make qualitative, not quantitative improvements to code. What you gain isn't performance but clarity when you build large systems, reduction in errors, reduce complexity, and so on. Nobody denies that you can make a program faster by manually squeezing performance out if it. But that isn't the only thing that matters, even if it's something you can easily benchmark.

Looking at a tiny code example tells you very little about the consequences of programming like this. If we program with disregard for the system in favour of performance of one of its parts, what does that mean three years down the line, in a codebase with millions of lines of code?`That's just one question.

Re:“Clean” Code, Horrible Performance by vore on Tuesday February 28, 2023 @05:00PM (#34975542)
Performance measurements are only one dimension of code quality. Having a laser focus on it disregards why you would want to sacrifice performance for a different dimension of code quality, such as extensibility for different requirements.

You should check if your code is in the hot path before optimizing, because the more you couple things together the harder it is to change it around. For instance, in Casey's example, if you wanted to add a polygon shape but you've optimized calculating area into multiplying height x width by a coefficient, that requires a significant refactor. If you are sure you don't need polygons, that's a perfectly fine optimization. But if you do, you need to start deoptimizing.

Re:“Clean” Code, Horrible Performance by lmm on Tuesday February 28, 2023 @06:09PM (#34976235)
These examples are absolutely a strawman. He's imagining there's one specific access pattern that's executed thousands of times per second. In a realistic codebase you're accessing the data less often but in multiple different (often subtly so!) ways. Cache efficiency is everything for modern CPUs, so you can't "simplify" the access patterns without making your benchmarks unrepresentative.
Re:“Clean” Code, Horrible Performance by _dain_ on Wednesday March 01, 2023 @09:26AM (#34982723)
How is it a strawman when it's literally taken from a Clean Code textbook?
Re:“Clean” Code, Horrible Performance by lmm on Wednesday March 01, 2023 @05:28PM (#34989225)
His benchmarks aren't taken from the textbook. If you benchmarked the textbook's changes in a realistic context you'd get quite different results.
Re:“Clean” Code, Horrible Performance by mtrower on Thursday March 02, 2023 @02:48AM (#34993166)
What defines a codebase as realistic, exactly? There are many, many programs out there doing various things in various ways.