back to index

Bjarne Stroustrup: Learn More than One Programming Language


Whisper Transcript | Transcript Only Page

00:00:00.000 | You've said that it's good for any professional programmer to know at least five languages,
00:00:07.560 | speaking about a variety of languages that you've taken inspiration from.
00:00:13.640 | And you've listed yours as being, at least at the time, C++, obviously, Java, Python,
00:00:21.440 | Ruby, and JavaScript.
00:00:24.520 | Can you, first of all, update that list, modify it?
00:00:28.360 | You don't have to be constrained to just five, but can you describe what you picked up also
00:00:34.800 | from each of these languages?
00:00:37.840 | How you see them as inspirations for even you working with C++?
00:00:42.040 | This is a very hard question to answer.
00:00:46.280 | So about languages, you should know languages.
00:00:52.200 | I reckon I knew about 25 or thereabouts when I did C++.
00:00:57.180 | It was easier in those days because the languages were smaller and you didn't have to learn
00:01:02.960 | a whole programming environment and such to do it.
00:01:06.520 | You could learn the language quite easily.
00:01:09.200 | And it's good to learn so many languages.
00:01:12.320 | I imagine just like with natural language for communication, there's different paradigms
00:01:19.700 | that emerge in all of them.
00:01:22.120 | That there's commonalities and so on.
00:01:24.960 | So I picked five out of a hat.
00:01:27.360 | You picked five out of a hat.
00:01:29.360 | Obviously.
00:01:30.360 | The important thing that the number is not one.
00:01:33.880 | That's right.
00:01:35.360 | It's like, I don't like, I mean, if you're a monoglot, you are likely to think that your
00:01:40.160 | own culture is the only ones, periods, for everybody else's.
00:01:43.760 | A good learning of a foreign language and a foreign culture is important.
00:01:48.600 | It helps you think and be a better person.
00:01:51.640 | With programming languages, you become a better programmer, better designer with the second
00:01:57.120 | language.
00:01:58.120 | Now, once you've got two, the way to five is not that long.
00:02:02.900 | It's the second one that's most important.
00:02:06.620 | And then when I had to pick five, I sort of thinking what kinds of languages are there.
00:02:15.280 | Well, there's a really low level stuff.
00:02:17.700 | It's good.
00:02:18.700 | It's actually good to know machine code.
00:02:21.200 | Even still, sorry to interrupt.
00:02:22.560 | Even today.
00:02:23.560 | Even today.
00:02:24.560 | The C++ optimizers write better machine code than I do.
00:02:30.960 | But I don't think I could appreciate them if I actually didn't understand machine code
00:02:36.840 | and machine architecture.
00:02:38.480 | At least in my position, I have to understand a bit of it because you mess up the cache
00:02:45.200 | and you're off in performance by a factor of 100.
00:02:49.040 | Right?
00:02:50.040 | It shouldn't be that if you are interested in either performance or the size of the computer
00:02:55.480 | you have to deploy.
00:02:58.600 | So I would go as a simpler.
00:03:02.000 | I used to mention C, but these days going low level is not actually what gives you the
00:03:08.080 | performance.
00:03:09.080 | It is to express your ideas so cleanly that you can think about it and the optimizer can
00:03:15.040 | understand what you're up to.
00:03:17.260 | My favorite way of optimizing these days is throw out the clever bits and see if it still
00:03:23.720 | runs fast.
00:03:25.200 | And sometimes it runs faster.
00:03:28.620 | So I need the abstraction mechanisms or something like C++ to write compact high performance
00:03:34.820 | code.
00:03:35.820 | There was a beautiful keynote by Jason Turner at the CPP Con a couple of years ago where
00:03:42.160 | he decided he was going to program Pong on Motorola 6800 I think it was.
00:03:53.880 | And he says, well, this is relevant because it looks like a microcontroller.
00:03:58.640 | It has specialized hardware.
00:04:00.320 | It has not very much memory and it's relatively slow.
00:04:04.460 | And so he shows in real time how he writes Pong starting with fairly straightforward
00:04:12.000 | low level stuff, improving his abstractions.
00:04:15.600 | And what he's doing, he's writing C++ and it translates into 86 assembler, which you
00:04:25.880 | can do with Clang and you can see it in real time.
00:04:29.400 | It's the compiler explorer, which you can use on the web.
00:04:34.100 | And then he wrote a little program that translated 86 assembler into Motorola assembler.
00:04:41.860 | And so he types and you can see this thing in real time.
00:04:45.300 | You can see it in real time.
00:04:46.680 | And even if you can't read the assembly code, you can just see it.
00:04:51.080 | His code gets better.
00:04:52.580 | The code, the assembler gets smaller.
00:04:55.700 | He increases the abstraction level, uses C++ 11 as it were better.
00:05:02.680 | His code gets cleaner, it gets easier to maintain, the code shrinks and it keeps shrinking.
00:05:09.180 | And I could not in any reasonable amount of time, write that assembler as good as the
00:05:17.580 | compiler generated from really quite nice modern C++.
00:05:22.980 | And I'll go as far as to say that the thing that looked like C was significantly uglier
00:05:30.260 | and smaller when it became and larger when it became machine code.
00:05:38.340 | So the abstractions that can be optimized are important.
00:05:43.340 | I would love to see that kind of visualization in larger code bases.
00:05:46.620 | Yeah.
00:05:47.620 | That might be beautiful.
00:05:48.620 | But you can't show a larger code base in a one hour talk and have it fit on screen.
00:05:54.100 | Right.
00:05:55.100 | So that's C and C++.
00:05:56.340 | So my two languages would be machine code and C++.
00:06:00.820 | And then I think you can learn a lot from the functional languages.
00:06:05.100 | So PIC has GloyML.
00:06:08.100 | I don't care which.
00:06:09.380 | I think actually you learn the same lessons of expressing especially mathematical notions
00:06:17.720 | really clearly and having a type system that's really strict.
00:06:24.160 | And then you should probably have a language for sort of quickly churning out something.
00:06:31.420 | You could pick JavaScript.
00:06:32.700 | You could pick Python.
00:06:34.700 | You could pick Ruby.
00:06:35.780 | [BLANK_AUDIO]
00:06:45.780 | [BLANK_AUDIO]