News for hackers. Stuff that matters.
Re:“Clean Code, Horrible Performance” Discussion by userbinator on Saturday March 11, 2023 @02:31AM (#35106281)
So many times I've seen a more readable, simpler code turned out to be more efficient as well.

In other words, if it's easy for the CPU to read, it's probably going to be easy for a human too. They both stumble a little on indirection and jumping around.

The other advantage of simple (macro-level, and not "one line functions" micro-level simplicity) code is that it also tends to have fewer bugs, and what bugs do appear, are also easier to find and fix.

Re:“Clean Code, Horrible Performance” Discussion by jenadine on Saturday March 11, 2023 @03:14AM (#35106472)
I disagree. Many abstraction makes it easier to read for human. Example, the first abstraction is to use functions, if/else, and loops instead of plain goto everywhere like the CPU like.

Now abstraction also have a cost that needs to be kept under control. (Some have zero costs, some have compile-time costs, some have different level of run-time costs) And of course, not every abstraction is a good one: Sometimes it can even be counter productive to hide details if these details are simpler than the abstraction itself.

In summary, it's all about trade-offs and not over-doing it.

Re:“Clean Code, Horrible Performance” Discussion by dsego on Saturday March 11, 2023 @05:44AM (#35107150)
> Many abstraction makes it easier to read for human.

Many abstractions are also conventions, just look at the js/react world. There is redux stores, mobx stores, hooks, class-based components, signals. All different abstractions with various performance and readability concerns. Someone used to one of them would say the others are not readable or maintainable. So maybe we can choose the more performant abstractions and teach them, so it becomes institutional knowledge.

Re:“Clean Code, Horrible Performance” Discussion by badpun on Saturday March 11, 2023 @12:15PM (#35110366)
> Example, the first abstraction is to use functions, if/else, and loops instead of plain goto everywhere like the CPU like.

CPU likes if/else and loops just as much as it like its gotos. If/else and loops are just conditional jump (with a comparison done before the jump), and gotos are uncoditional jumps. Both are very much machine code constructs, that's why they're in C (which is basically a syntactic sugar over assembly).

Function calls are slightly more involved, but basically also very, very low level.

Re:“Clean Code, Horrible Performance” Discussion by jenadine on Saturday March 11, 2023 @03:24PM (#35112301)
you don't write

   if (!condition) 
       goto else_;
   // some code
   goto endif;
   else_:
   // the else block
   endif:
   // More code

Same for loop. That's what we mean by "goto considered harmful".
Re:“Clean Code, Horrible Performance” Discussion by kaba0 on Saturday March 11, 2023 @03:48AM (#35106651)
So why don’t we write plain old assembly then, ad absurdum?

Here are my thoughts in a bit more detail from a previous thread: https://news.ycombinator.com/item?id=35061151

Re:“Clean Code, Horrible Performance” Discussion by fulafel on Saturday March 11, 2023 @06:51AM (#35107522)
A problem with that is that compiler technology hasn't really progressed to do big whole-program or data-layout optimizations from high level specs.

If we were closer to the model where a program would read its fixed inputs (for the run) and it would be specialized in place for the input using partial evaluation, with profile feedback for data accesses to help transforming the internal data representations to optimize storage requirement and cache access patterns, we would be much more motivated to specify many things abstractly enough to give machine representations of the code and data more freedoms.

Re:“Clean Code, Horrible Performance” Discussion by haspok on Saturday March 11, 2023 @08:41AM (#35108182)
The whole C64 scene are shaking their head in disbelief. The CPU couldn't care less about "easy readability" (whatever that even means) of your code. Ever heard of self-writing / self-modifying code? Probably an extreme example, and it can be used both ways - for performance reasons (unroll those loops!) or for abstraction (macros are your friend!).
Re:“Clean Code, Horrible Performance” Discussion by bigbillheck on Saturday March 11, 2023 @10:20AM (#35108947)
One thing you have to remember about modern CPUs is that they are not fast 6502s.