News for hackers. Stuff that matters.
Re:Simple, correct, fast: in that order by michaelcampbell on Monday July 09, 2018 @10:12AM (#17490275)
The old yarn I'd heard for years is close to this.

Make it work. Make it work right. Make it work fast.

In that order.

Now it could be argued that "work right" can be read as "make it (work right)", or "(make it work) right", or both, but I think the point of this saying is that the "fast" part should always come later.

Re:Simple, correct, fast: in that order by taneq on Monday July 09, 2018 @10:37AM (#17490448)
Yep, this is the version I heard. I think the distinction between "make it work" and "make it work right" is important, though - where "work" means "solve the problem", and "work right" means "solve the problem in a robust and reliable manner."

If your software doesn't solve the problem, it's useless, no matter how correct or fast it is. Once it solves the problem, then you can work on making it bug free and elegant. Once you're done with that, only then should you look at making it fast.

Note, of course, that "make it fast" refers to gratuitous optimisation. If it's too slow to solve the problem, then it doesn't work, and that needs to be fixed.

A similar adage states the rules of code optimisation:

1) Don't.

2) (For experts only) Do it later.

Re:Simple, correct, fast: in that order by sethrin on Monday July 09, 2018 @12:04PM (#17491231)
3) Profile before optimization.
Re:Simple, correct, fast: in that order by AstralStorm on Monday July 09, 2018 @01:19PM (#17491807)
4) After thinking how to get beat bang for buck when optimizing. Profilers don't always pinpoint the culprit.
Re:Simple, correct, fast: in that order by kungtotte on Monday July 09, 2018 @02:41PM (#17492418)
I have a hard time seeing how profilers don't at least point you in the right direction. Or are we using different definitions of the word? They tell you how much time is spent in any given section of your program. If 80% of the time is spent in 20% of the code, it's usually a safe bet that's where you should start looking!
Re:Simple, correct, fast: in that order by taneq on Monday July 09, 2018 @07:30PM (#17494270)
Generally I agree, but after you've picked off a few low hanging fruit, you'll end up with the profiler pointing at the function which does most of your grunt work, at which point you'd expect that to take up most of the time.

Once you've got this pretty optimized and it's still taking up the lion's share of your execution time, you have to look elsewhere (probably changing your overall approach or applying some higher level optimisation) to improve things further.

Re:Simple, correct, fast: in that order by AstralStorm on Tuesday July 10, 2018 @01:41AM (#17495727)
Yes, at that point you typically get to apply far reaching architectural changes or switch out the algorithm.

Sometimes it is quicker to start with just that instead of "polishing a turd". You can get it to be shiny but still nowhere near as shiny as gold.

Hope the code is testable and reasonably easy to modify. Otherwise it's going to be a rewrite.

The profile is then useful as a benchmark on real data. If you have enough time, you can turn that into a high level performance test.

Re:Simple, correct, fast: in that order by sethrin on Monday July 09, 2018 @03:05PM (#17492610)
Profilers have limitations like anything else, and it's possible to be pointing the flashlight in the wrong place. I probably wouldn't include that as a list item.

By the by, is there more than one kungtotte on the Internet? It took me a minute to think why that name was so familiar, but then I remembered watching a few hundred Beaglerush videos.

Re:Simple, correct, fast: in that order by kungtotte on Monday July 09, 2018 @11:08PM (#17495132)
There must be more than one, because I've never heard of Beaglerush.

I've used this handle for a long time though (20 years or so), so it's all over the internet.

Re:Simple, correct, fast: in that order by sethrin on Tuesday July 10, 2018 @02:33AM (#17495882)
Kk, thank you for indulging my curiosity. Beaglerush is a very humorous Aussie who is notable for a video series on the Long War mod for the game XCOM. Long War turns a moderately challenging game of thirty or forty hours into an extremely complex, impossibly difficult ordeal of at least 400 hours per game. Beagle apparently often uses the handles of his friends as character names, and one of the best/worst parts of XCOM is that it's really good at making you care about the little blobs of pixels you order into virtual mortal peril, so to me kungtotte is like, the hero of 100 missions :)

If you're into strategy games, XCOM is good, and Long War is matchless. However, Beaglerush is actually surprisingly entertaining even if you don't care for his subject; the girlfriend is still not much into the game, but after the first couple episodes she insisted on watching the other hundred-thirty-odd videos. It's probably not everyone's cuppa, but it could be a thing.

Re:Simple, correct, fast: in that order by kungtotte on Tuesday July 10, 2018 @05:31AM (#17496533)
Oh, that's me then :) I didn't put two and two together because I knew him as just beagle, and it was a long time ago that I hung out with him. We played together in a gaming community known as ShackTac or ShackTactical, playing a game called Armed Assault/ArmA.

Way back when a bunch of us put our names into a custom name file for XCOM so people could make campaigns featuring ShackTac people instead of generic dudes. I completely forgot about that until you reminded me. It must be five years since I talked to him :)

Re:Simple, correct, fast: in that order by sethrin on Tuesday July 10, 2018 @09:18AM (#17497775)
Oh cool :) Yeah, I did get the impression that the name list represented more former acquaintances than current ones, and I think he got pretty burnt out on YouTube generally. He seemed like a pretty great guy, and the series was excellent, so it seems you have a small measure of reflected glory at least :)
Re:Simple, correct, fast: in that order by Buttons840 on Monday July 09, 2018 @02:21PM (#17492262)
Sometimes I try to implement a common task in a new library, and I find that if I chain these 4 API calls and then extract some data with a regex, it will do what I want. I rarely actually implement the task this way though, because I know it's a common task, and there must be a better way. Sure enough, after some more research and reading of documentation I find one simple API call that does what I want.

I take this to the extreme, I probably wouldn't implement the complicated API / regex chain without 4+ hours of reading documentation and other research. It bothers me that much. If it seems like a simple and common task, I refuse to believe that there isn't a simple API call already to do what I want, I just have to find it. Sometimes, the simple API call really doesn't exist though, and you have to do what you can, with some comments explaining why.

I've noticed some developers will implement the 4 API chain followed by a regex as soon as they find it, and never give a second thought that there might be a simpler way.

Re:Simple, correct, fast: in that order by nicbou on Tuesday July 10, 2018 @12:28PM (#17499590)
This is good, because that process now becomes the API's problem and not yours. Their tests cover it, not yours, and it makes your work simpler.
Re:Simple, correct, fast: in that order by cbsmith on Monday July 09, 2018 @10:39AM (#17490466)
The make it work fast portion isn't controversial. Premature optimization and all that...

The "make it work" implies a level of correctness & performance that is acceptable, which is why any subsequent steps are after thoughts.

Re:Simple, correct, fast: in that order by AstralStorm on Tuesday July 10, 2018 @01:55AM (#17495766)
The missing part is "make it workable". By that I mean reasonably easy to modify. This may or may not involve simplicity but usually involves modularity and lack of hard impingement interdependencies - weak coupling.

If you skip that, you will relatively quickly reach the point of a full rewrite.