3 ms·
I posted this article less for the negative "countering the myth" that the comments here seem to be responding to, and more for the positive description of how
by jerf 11y ago
I posted this article less for the negative "countering the myth" that the comments here seem to be responding to, and more for the positive description of how exactly you write code in a thoughtful manner while not overdoing it into "performance uber alles".
I tend to think of it more as not painting myself into a corner than necessarily getting it perfect the first time. It's amazing what some thought, maybe a day in the profiler per couple of months of dev work to catch out the big mistakes (and as near as I can see, nobody ever gets quite good enough to be able to never make such mistakes), and some basic double-checking (like "are any of my queries are doing table scans?") can do for performance, long before you pull out the "big guns".
- markbnj 11y agoIf it were positioned as an article about writing thoughtful code then I doubt the comments would be as focused on the claim in the headline. Knuth's point was that even thoughtful programmers could get caught up in pursuing performance in areas where it ultimately didn't matter, and even more critically, that even thoughtful programmers could be guilty of discarding a clear, comprehensible piece of code in favor of something terser, and less accessible due to a perceived performance benefit.
- jerf 11y ago"If it were positioned as an article about writing thoughtful code then I doubt the comments would be as focused on the claim in the headline." Sorry, I did not mean to delegitimize those points. I understand where they are coming from.
- abraae 11y agoI found this deeply ironic given the article's premise: "are any of my queries are doing table scans?" It makes me grind my teeth when developers apply brute force thinking like this. There are many times when full tables scans are fine - e.g. used on a small table, or when a query returns more than a few percent of the rows in a table. imo, blindly hunting out full table scans is a textbook case of premature optimization.
- jerf 11y agoHas it occurred to you that, in context, there's no way I meant blindly checking? Besides, this may "grind your teeth" but I see the opposite at least a full order of magnitude more often, if not two. I'm far more likely to get someone asking me "What's EXPLAIN?" (when working with MySQL) than to see someone going nuts making sure they have 0 table scans.
- akkartik 11y ago"I tend to think of it more as not painting myself into a corner than necessarily getting it perfect the first time." Yeah, that's exactly right. I was reading the article with that lens, and found some of its examples less than compelling. It may not matter if Linq is doing a bunch of allocations; you could always replace it with the in-place loop later. Starting with Linq doesn't cost any potential energy. I had a couple more nuanced reactions to the OP. a) While this is an argument that needs to be made more often, and one that I've made before, characterizing careless optimization as just lack of thoughtfulness is underestimating the problem. The real problem when I end up writing carelessly slow code is that I had no conception of the internal details of some library or service. The best programmers know they have to gradually break down every abstraction in their mind, and gain the ability to think about its internals when the need arises. It took me a long time to realize that my mindset when using a library should be to gradually understand how it works. Heck, I stared at the sql statements emitted in Rails logs for years before I realized they were telling me something useful. It's not about not being thoughtful, it's about being on a path of learning long before you need it. And we need to be spreading this word far and wide. b) The standard of "all great software programmers I know are proactive in writing clear, clean, and smart code. They pour love into the code they write." is incredibly rare. That isn't going to change. So as long as we place the onus on considering alternatives up front, we're always going to be disappointed. Particularly when new programmers come in late in a project's life cycle and weren't around since it started, they may not actually be aware of all the different situations it's invoked in, and how bad worst-case might be. They'll also be less intrinsically motivated because they have less of a sense of ownership for the codebase. Things get even worse in projects that started out as prototypes, because of course there it makes sense to just go with the first idea that pops into your head. I think we should make it easy for people to contribute by making it easier to perform radical rewrites of parts of codebases. That way there's less pressure on perfectly checking all possible alternatives up front. The difficulty of a rewrite has less to do with the raw effort of the rewrite and more with the prospect of causing regressions, and the stress emanating from that prospect. I've been exploring making codebases more rewrite-friendly, using more comprehensive white-box tests: https://news.ycombinator.com/item?id=11052322 https://news.ycombinator.com/item?id=11052322.