News for hackers. Stuff that matters.
Re:Counting the number of matching characters in two ASCII s... by sm4sh on Friday May 21, 2021 @11:31AM (#27235347)
Well okay, but guess which one I'd rather have to maintain in a big codebase? Clearly written by a theoretical engineer.
Re:Counting the number of matching characters in two ASCII s... by humblepie on Friday May 21, 2021 @11:36AM (#27235406)
For a large codebase, this would be encapsulated and heavily commented, etc. It's something that you pull out when you need to make something "go to eleven" kind of thing.
Re:Counting the number of matching characters in two ASCII s... by raldi on Friday May 21, 2021 @11:44AM (#27235509)
Exactly. You could have some exhaustive unit tests as well, and after that there would be nothing to maintain.
Re:Counting the number of matching characters in two ASCII s... by teachingassist on Friday May 21, 2021 @11:44AM (#27235505)
Plenty of library functions are already going to be optimised in this type of way - just because they're not visible in your codebase doesn't mean they are not there.
Re:Counting the number of matching characters in two ASCII s... by rocqua on Friday May 21, 2021 @01:24PM (#27237034)
So if your big codebase were profiled, and the 99th percentile case happened to spend 80% of its time in this function, you would still stick to the old function unwaveringly? Even if your system was latency sensitive, and your 99 percentile spikes were far from acceptable?

Sure, there are many cases where this is a premature optimization. This blog never said otherwise. But that doesn't mean there is never a time for optimization. And if profiling points at this, then this speedup can be valuable.

Re:Counting the number of matching characters in two ASCII s... by commandlinefan on Friday May 21, 2021 @12:54PM (#27236585)
> rather have to maintain

Well, as long as it works, what difference does it make? As long as it's prefixed with a

// This compares the matching number of bytes

comment, you should never have to mess with it.

Re:Counting the number of matching characters in two ASCII s... by rocqua on Friday May 21, 2021 @01:25PM (#27237050)
With a compiler or architecture change, I guess this could create awkward to handle performance regressions.
Re:Counting the number of matching characters in two ASCII s... by Forge36 on Friday May 21, 2021 @11:57AM (#27235717)
It's about use cases.

There was an old lady 6 about unoptimized behavior in VB6 and why is wasn't necessary to do so. I had to write a wrapper for it which was optimized in my code. Was it harder to read? Yes. Did it produce a significant performance improvement? Also yes.

Software development is about tradeoffs. Demoing one way to improve a simple function helps others trunk how they write code, and more importantly why they wrote specific code

Re:Counting the number of matching characters in two ASCII s... by JKCalhoun on Friday May 21, 2021 @12:43PM (#27236413)
I've worked with engineers that must read these blogs and try to out-clever everyone.

They succeed, and that's the problem.