back to index

Bjarne Stroustrup: Recognizing Beautiful Code


Whisper Transcript | Transcript Only Page

00:00:00.000 | So, how do you inspire or ensure that the Einstein level of simplification is reached?
00:00:12.000 | So, can you do code review?
00:00:14.800 | Can you look at code?
00:00:17.800 | If I gave you the code for the Ford F-150 and said, "Here, is this a mess or is this
00:00:26.040 | okay?"
00:00:27.440 | Is it possible to tell?
00:00:28.720 | Is it possible to regulate?
00:00:31.780 | An experienced developer can look at code and see if it smells.
00:00:38.800 | Mixed metaphors deliberately.
00:00:42.960 | The point is that it is hard to generate something that is really obviously clean and can be
00:00:55.880 | appreciated.
00:00:57.760 | But you can usually recognize when you haven't reached that point.
00:01:02.680 | And so, I've never looked at the F-150 code, so I wouldn't know.
00:01:12.320 | But I know what I ought to be looking for.
00:01:14.320 | I'll be looking for some tricks that correlate with bugs and elsewhere.
00:01:21.240 | I have tried to formulate rules for what good code looks like.
00:01:28.120 | And the current version of that is called the C++ core guidelines.
00:01:36.280 | One thing people should remember is there's what you can do in a language and what you
00:01:42.160 | should do.
00:01:43.160 | In a language, you have lots of things that is necessary in some context, but not in others.
00:01:50.640 | There's things that exist just because there's 30-year-old code out there and you can't get
00:01:55.880 | rid of it.
00:01:57.360 | But you can't have rules that says, "When you create it, try and follow these rules."
00:02:03.400 | This does not create good programs by themselves, but it limits the damage for mistakes.
00:02:12.280 | It limits the possibilities of mistakes.
00:02:15.500 | And basically, we are trying to say, "What is it that a good programmer does?"
00:02:21.480 | At the fairly simple level of where you use the language and how you use it.
00:02:26.400 | Now, I can put all the rules for chiseling and marble.
00:02:32.280 | It doesn't mean that somebody who follows all of those rules can do a masterpiece by
00:02:37.640 | Michelangelo.
00:02:40.500 | That is, there's something else to write a good program, just as there's something else
00:02:46.420 | to create an important work of art.
00:02:50.600 | That is, there's some kind of inspiration, understanding, gift.
00:02:57.600 | But we can approach the sort of technical, the craftsmanship level of it.
00:03:08.800 | The famous painters, the famous sculptors was among other things, superb craftsmen.
00:03:16.400 | They could express their ideas using their tools very well.
00:03:22.840 | And so, these days, I think what I'm doing, what a lot of people are doing, we are still
00:03:28.380 | trying to figure out how it is to use our tools very well.
00:03:33.440 | For a really good piece of code, you need a spark of inspiration.
00:03:39.640 | And you can't, I think, regulate that.
00:03:42.600 | You cannot say that, "I'll take a picture only, I'll buy your picture only if you're
00:03:50.240 | at least Van Gogh."
00:03:51.240 | There are other things you can regulate, but not the inspiration.
00:03:58.920 | I think that's quite beautifully put.
00:04:01.480 | It is true that there is, as an experienced programmer, when you see code that's inspired,
00:04:10.160 | that's like Michelangelo, you know it when you see it.
00:04:16.880 | And the opposite of that is code that is messy, code that smells, you know when you see it.
00:04:23.640 | And I'm not sure you can describe it in words, except vaguely through guidelines and so on.
00:04:29.120 | Yes, it's easier to recognize ugly than to recognize beauty in code.
00:04:36.000 | And for the reason is that sometimes beauty comes from something that's innovative and
00:04:41.120 | unusual.
00:04:42.760 | And you have to sometimes think reasonably hard to appreciate that.
00:04:47.600 | On the other hand, the messes have things in common.
00:05:08.300 | [BLANK_AUDIO]