Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #79412
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: C++ may sometimes be *too* simple (to use) |
| Date | 2021-05-04 15:20 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <s6rhma$f9h$1@dont-email.me> (permalink) |
| References | (5 earlier) <s6ddkc$19ag$1@gioia.aioe.org> <3d6f3bcc-63a8-4498-9600-69a3c6b5088cn@googlegroups.com> <s6gl2d$2v3$1@gioia.aioe.org> <566e0717-f1e7-4b47-8b1f-4a4d0d9685bfn@googlegroups.com> <s6r8h6$9ar$1@gioia.aioe.org> |
On 04/05/2021 12:43, Juha Nieminen wrote: > Öö Tiib <ootiib@hot.ee> wrote: >> But performance does not *actually* matter most of software >> development life cycle. Donald Knuth's fat volumes of science of >> optimizing algorithms are outright admirable. Yet he wrote in >> "Computer Programming as an Art" (1974) golden words that >> every programmer I know can cite "premature optimization is >> the root of all evil". So come back from dark and evil side, Juha. >> Performance starts to matter only after correctness has been >> reached from end to end and then only to minor subpart of >> whole program. > > When Knuth wrote "premature optimization is the root of all evil" > in 1974, I doubt he was thinking about std::string::substr() > vs. std::string::compare() in a language standardized in 1998. > > In fact, I personally consider the (in)famous adage to have caused > more harm than good overall because way, way, way too many programmers > have interpreted it to mean "deliberately and purposefully make your > program as inefficient as you possibly can, because optimization, > any kind of optimization, is one of the worst things you could > possibly do". > > I'm not even kidding. I have encountered that sort of attitude in the > real world out there many times. People deliberately choosing a less > efficient algorithm or data container even when a significantly > more efficient one is available, because "premature optimization > is the root of all evil", and there's literally zero reason not to > use the more efficient version. > I have certainly seen code written without any thought given to efficiency (like "x * 0.5" instead of "x / 2" on an 8-bit embedded system). But I don't believe I have seen anyone deliberately choosing a less efficient algorithm when the efficiency was the only difference. > I don't think many people even understand what he meant by it. > Does anybody understand what he meant by it? By "premature optimization" > didn't he merely mean ugly hacks that supposedly make the program > a few clock cycles faster at the cost of making it almost unreadable > (something that was especially common in the 70's and 80's, when > compilers were extraordinarily basic and bad at optimization). > Such as explicitly using bitshifting instead of multiplication, > manually inlining code, and other such hacks. The more such hacks > are used, the less readable and maintainable the code belongs, and it > becomes. > > "Premature optimization" does not mean using quicksort instead of > bubble sort. Or using a balanced binary tree instead of an array (and > linear searches). Or using std::string::compare() instead of > std::string::substr(). > For most code, efficiency does not particularly matter (pick your own favourite statistic - 95.32% of run time is spent inside 2.12% of the code). It might begin to matter if the bulk of the code uses really bad algorithms, but you don't need to put special effort into it. In particular, you should not optimise for efficiency at the expense of making code less clear, or increasing the risk of making it incorrect. I can't remember if it was Knuth or someone else who said that optimising for speed is easy if you don't worry about correctness. There are good reasons why most code these days is not written in compiled languages - developer time, ease of maintenance, flexibility, etc., are often more important than absolute speed. But premature pessimisation follows close behind premature optimisation as the root of all evil. So it might be better to write a piece of code in Python rather than C++, but you still want to make sure you use lists or dicts as appropriate and avoid needlessly inefficient algorithms.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 12:07 +0000
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-27 17:57 +0300
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-04-27 18:14 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-04-28 05:21 +0000
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-04-28 09:09 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-04-29 04:45 +0000
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-04-29 15:16 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-04-30 10:10 +0000
Re: C++ may sometimes be *too* simple (to use) Bo Persson <bo@bo-persson.se> - 2021-04-30 15:33 +0200
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-04 10:32 +0000
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-01 06:51 -0700
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-05-03 21:38 +0300
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-06 18:21 -0700
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-05-07 12:05 +0300
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-04 10:43 +0000
Re: C++ may sometimes be *too* simple (to use) David Brown <david.brown@hesbynett.no> - 2021-05-04 15:20 +0200
Re: C++ may sometimes be *too* simple (to use) Manfred <noname@add.invalid> - 2021-05-04 16:41 +0200
Re: C++ may sometimes be *too* simple (to use) James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-05-04 23:42 -0400
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-05 05:01 +0000
Re: C++ may sometimes be *too* simple (to use) David Brown <david.brown@hesbynett.no> - 2021-05-05 11:26 +0200
Re: C++ may sometimes be *too* simple (to use) James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-05-05 09:53 -0400
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-06 21:40 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-07 07:38 +0000
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-05-07 22:32 +0300
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-08 03:27 -0700
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-05-07 12:10 +0300
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-07 09:40 -0700
Re: C++ may sometimes be *too* simple (to use) red floyd <no.spam.here@its.invalid> - 2021-05-07 17:59 -0700
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-08 03:42 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-08 20:27 +0000
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-09 09:56 -0700
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-10 05:07 +0000
Re: C++ may sometimes be *too* simple (to use) Richard Damon <Richard@Damon-Family.org> - 2021-05-10 07:29 -0400
Re: C++ may sometimes be *too* simple (to use) Öö Tiib <ootiib@hot.ee> - 2021-05-10 20:18 -0700
Re: C++ may sometimes be *too* simple (to use) Hans Bos <hans.bos@xelion.nl> - 2021-05-07 16:06 +0200
Re: C++ may sometimes be *too* simple (to use) Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-04-27 19:57 -0700
Re: C++ may sometimes be *too* simple (to use) wij <wyniijj@gmail.com> - 2021-04-27 21:15 -0700
Re: C++ may sometimes be *too* simple (to use) Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-28 11:13 +0300
Re: C++ may sometimes be *too* simple (to use) "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2021-05-03 10:28 +0200
Re: C++ may sometimes be *too* simple (to use) Juha Nieminen <nospam@thanks.invalid> - 2021-05-04 10:53 +0000
csiph-web