Text broadcast of CppCast 293: One Lone Coder
- Microsoft open-source calculator
- CMake 3.20.0 available for download
- Why C++?
- Robots, robots are everywhere...
- Neuromorphic engineering
- OneLoneCoder YouTube channel
On this episode, Rob Irving and Jason Turner are joined by David Barr. First, they discuss Microsoft open-source calculator and an update to CMake. Then they talk about David's YouTube channel – One Lone Coder, what inspired him to start it, and PixelGameEngine – the 2D game engine he works on with the One Lone Coder community.
This episode is sponsored by C++ Builder, a full-featured C++ IDE for building Windows apps. The idea of choice is to build Windows applications five times faster while writing less code. It supports you through the full development life cycle to deliver a single source code base. The key value is C++ Builder's frameworks, powerful libraries that do more than other C++ tools. This includes the award-winning VCL framework for high-performance native windows apps and the powerful FireMonkey framework for cross-platform iOS. Test-drive latest version at embarcadero.com.
David Barr is a professional programmer and hardware engineer for 16 years in various guises related to robotics and neuromorphic engineering. By night he runs the One Lone Coder YouTube channel and supports the surrounding community. David has programmed in all sorts of fields ranging from computer games, neuroscience, and image processing to physics simulations, conceptual computing, and robotics. He started to make videos about the core algorithms involved and how they form the building blocks to solving many other problems. His predominantly C++ YouTube channel has gained 250K subscribers, many of whom are using his olc::PixelGameEngine header file and videos to have fun, learning about C++ programming in an accessible way, and creating their own awesome games and products.
As usual, we're going to start with some news.
Microsoft open-source calculator
Rob: Microsoft's calc.exe is going open source. You can go and look at the GitHub page where they have the open-source code for the Windows Calculator. I took a quick look at the code, and it does look like they're using some modern C++. If you're interested in seeing how you can use XAML and C++ in a real application, there are examples for how to do that.
David Barr: I have to smile at that one because I did look at the code. It's a calculator! Why are there 50 individual C++ files and over 80 total files for the whole thing? The source files tell you that right now there's a big problem in C++ and graphical user interfaces in general. Look how complicated it is. And some people think that Microsoft would be dominant in this field. I looked at the code and thought that it was frightening. Just how verbose it is to be a calculator. :)
Jason: I think it's worth pointing out that this article is two years old, but if you go back and look at the GitHub history, you'll see its continued development. Looks like a 35-40-year-old program or something like that. Often people ask me, how to learn C++ better. I always suggest that they should start with a project that sounds interesting to you. I think that even if something sounds extremely simple, like a graphical calculator, you might be able to work on refining that for the next 35 years.
CMake 3.20.0 available for download
Jason: To be honest, I didn't find something interesting in CMake 3.20.0. There are lots of little things that people might like. For example, if you do target_include_headers, you can say target_include_headers after if you need to place the header in a certain order, you might be able to tweak that setting. There's a bunch of little changes, but nothing that really jumped out at me personally.
David Barr: I must confess, I'm not really a CMake user. I did use it back in about 2006 and I enjoyed it. It was useful. I was using it to make a compiler emulator at the time, I wanted it to run on Linux and Windows specifically. But then I fell out of love with it because CMake got more and more complicated. At least I felt that it did.
Jason: It's like C++, right? We've added a lot to the language in the last nine years. Right now, in C++20 you could do a lot of things much more simply and cleanly than you could have in 2006. CMake is the same way, you have to go and look for the modern CMake examples. Otherwise, you're just going to be doing bad stuff.
David Barr: CMake is a very popular tool certainly on my Discord. It's mentioned over two and a half thousand times. Usually, people ask how to set it up for various projects. I don't know if there are enough resources being put out there to how to make your projects cross-platform. It's easy for us as accomplished engineers to just run away with doing it. But if you are starting out now, where do you go for your first modern introduction to these things? The resources aren't as obvious as you might think, at least I think so.
Jason: Yeah. It's totally true.
Rob: Well, David, do you want to tell us more about how you got started in C++ and maybe what you're up to these days professionally?
David Barr: I started C++ because of finding Java rather boring. I started with Turbo C. I remember saving up my pocket money. I was a teenager at the time, and I treated myself to Visual Studio 6 on CD. And that came with a C++ compiler and a book. The book was full of MFC, Microsoft Foundation Classes stuff. I was trying my best to work out how to make this all work. And it wasn't happening. I had no sort of formal training in how to do software engineering. Classes and object-oriented programming weren't something I was familiar with. I've worked with Pascal, BASIC, and Assembly language. And then in the university, we got introduced to actual software engineering, and they taught us Java.
I thought Java was the bee's knees until I needed some performance out of it. I wanted to do games programming, and Java was awful for games programming. It's not so bad now, but then it was. We're talking around 2001-2002. So, I went back to this book I had for C++. And I understood members, inheritance, polymorphism because I've been taught all these things, and it looked like a completely different world to me. MFC was still awful, but I could now build the things that I wanted to build. And I've never looked back. C++ is for absolutely everything.
I think people who claim that you can't do a complex large project in C++ just aren't doing it right. It's a brilliant language for beginners. My team at work and I find C++ very productive to use.
Robots, robots are everywhere...
David Barr: I work for a company now that builds robotics for heavy industry. We look for hazardous environments. If you need to have a look at something in these hazardous environments with a special payload of transducers or probes, you send in one of our robots. We call them scanners. They're not sort of like humanoid things, walking into lava pits. It's far simpler than that, but it's fairly critical stuff. They're inspecting power plant facilities, and sometimes we're expecting aircraft parts. It's got to be reliable, particularly in the radioactive environments. It must do a good job, working out what's going on and being safe. You don't want your robot being the problem in a nuclear environment.
Jason: Was it the kind of thing that you worked on that would have been examining Fukushima after the tsunami?
David Barr: Yes. Ideally, we would be looking at examining it before Fukushima happened. I mean, the primary purpose of our gear is to say, hang on, something's about to go wrong here before it happens. But we have worked to sought out Fukushima after the terrible events happened. Nuclear industry is big for us too. Nuclear, oil and gas, and aerospace are the big three that we're targeting.
Jason: I'm curious, is your hardware hardened to prevent memory errors from radiation?
David Barr: Yes, it's a hybrid tactic. It depends on the environment. Some of the environments we're going into, you can put all about harding in the world – it's not going to make a difference. It's so radioactive. If you can get 10 minutes out of your system, that's great. Most of the time we're taking physical measures. If we think we're going into a nasty environment, we'll package it in a special material before it goes down there. If it goes down there and gets contaminated, it isn't coming back. They just stay there. You don't want it back.
Jason: That's interesting. We've never talked about this stuff on the show before.
Jason: David, you've been working in neuroscience. I'm curious about neuromorphic program engineering. That sounds very science fiction-y to me.
David Barr: It was in the late 2010s. I was doing my PhD at the time. We were looking at how we take neuroanatomical structures and how the brain solves problems. We were replicating those in custom hardware and software with FPGAs that we were designing. There's a small but dedicated niche called neuromorphic engineers. They love that name. This group sort of fostered the precursor to machine learning and deep learning that we know today. We just didn't have the computational resources back then, but the algorithms are the same.
It's an interesting field where I found my niche. It was about applying C++ to solving lots of academic problems in a world where they don't typically go to C++ to solve those problems. They use slower libraries, MATLAB, and those fantastic tools, but they don't get any performance. That's neuromorphic engineering. They need it to be as fast as possible, huge data sets, lots of processing.
Jason: You said some of that was done in FPGA as well.
David Barr: Back then, the FPGA technology was the sort of most advanced you could get at the time. So, we would try and emulate how the neurons work at various levels of abstraction.
If you've got many millions of them that need emulating, if you're really interested in the biochemistry of the neurons, you want to get stuck into the very sort of deep protein levels. So, we were interested in how to distribute this information around because it turns out simulating the neurons is simple. But transmitting that information between neurons is hard. And nobody's really solved that problem yet. The deep learning and machine learning, things that are going on now, still blur that out. They don't treat them as individual neurons. They treat them as clusters of neurons, and you can get a lot of abstraction that way.
Jason: Are there still people that are continuing biology road of trying to model how an actual brain works as opposed to the computer science definition of it?
David Barr: Usually, people are interested in the real biochemistry, what sort of drugs and how the brain is responding to therapeutic or remedies. I was particularly interested in the visual cortex process.
The chips that we were building in the laboratory were basically artificial retinas, that could see the image and process it on the focal plane and deliver that to an upstream, a higher-level system of abstraction. Our chip had 65,000 cores back then. And they were analog cores, not digital.
OneLoneCoder YouTube channel
Jason: You have 250k subscribers on YouTube. That's a lot! Was it a specific video that really accelerated your channel's growth or does it just kind of slowly grew over time?
David Barr: I'm not a social media person in the slightest. I never did social media before this and I still don't consider it social media, but there we go. I'm pleased that it's took off. I'm glad people like it.
I started it about four years ago. Probably a specific series helped it kickoff. I did a series about 3D graphics from scratch, which seemed to resonate with a lot of people. I kept pulling out interesting series and the silly videos, some of the comedy videos seem to go down quite well.
Rob: What prompted you to start a YouTube channel?
David Barr: I was working at the university after I finished my degree and then went on to do my postgrad and then postdoc. I was working a lot with the students. Year-on-year I noticed a decline in the ability of students to do basic programming. At first, I thought this was the university's fault, but it wasn't. I knew the teachers, the quality of the materials. It seemed as if there was a lack of interesting resources for students, resources, which can capture the imagination of a generation of people who just stare at their phones.
So, I decided to have a look at what resources are out there. I looked at the type of videos and noticed two categories. The first is the excellent videos. Things like the GDC talks, the highbrow stuff that people would happily debate the minutia of a particular template style. Brilliant stuff, but totally inaccessible for those who is just starting.
And there's the complete and utter dross. That's the rest of it though. There's nothing in-between. It sounds offensive, but it's true. There's just thousands and thousands of terrible programming videos out there. And they all do the same thing. They're all: at first, we're going to include standard IO, and then we're going to output "Hello, world", then we're going to create something that displays the Fibonacci sequence. Who cares about the Fibonacci sequence?
If you're trying to get involved in programming, I think this is ridiculous. There was a lack of resources for people who know how variables and loops work. That's something that they can go and find out quickly, but once these people have developed these basic skills, there's nothing there. They don't know how to apply it to solving problems. I decided to have a go at trying to create a channel where we look at solving problems.
I like C++, I think C++ is great for beginners. I know that not everybody thinks that, but I do. Let's create some interesting daft, silly applications. Keep it fun. Keep it silly. Get people doing stuff that they enjoy. When you start programming, I'm willing you to just switch your computer on, sit down and start coding straight away.
Now, it's difficult to get programming. There are thousands of resources, millions of languages, and lots of books. It's too much, it's overwhelming. It's difficult to find the quality stuff but now it's also difficult to get started. You need toolchains, developments, environments, manuals. You need to understand lots of different complex patterns in designing software before you can even get going. I wanted to try and do something about that and that's why I started my channel.
Rob: What projects that you put together on the YouTube channel are this good kind of products that you think are good for a first-time programmer?
David Barr: In my first video, I was doing a first-person shooter-style game in the Windows command prompt. I want people to have a go at this. I don't want them to have to download libraries and tools and things. If they've got Windows (sorry Linux guys, I moved to Linux later...) and Visual Studio, then how do they do this? Everybody's got a command prompt on Windows. With a little bit of code, you can turn that command prompt into a graphic surface. That, I think, caught people's imagination.
People can take exactly the principles from this first-person shooter and implement them on any other platform they want. Then message me to get me to show it. I like to show other people's projects. They get some exposure, which they wouldn't normally get.
I also had video about Tetris in the command line. Again, very simple stuff. But leveraging this command prompt as a user interface makes it very easy for people to just get started. It looks silly, but it's much better than "Hello, world" and stupid Fibonacci sequence. I hate that sequence.
Jason: Is there any mathematical sequence that you do like to demonstrate?
David Barr: I'm not going to answer that one. :D
Rob: We've mentioned in your bio this olc::PixelGameEngine. Is that the command line prompt-based game engine?
David Barr: Once I realized that I'm spending too much time in each video saying about how we do things in a command prompt and not the algorithms in general. That's when the PixelGameEngine was born. That became the tool of choice that I use now to make visualizations for my videos. Then it just so happens that people realize they can make games with it too.
Click here to watch the full video.
PixelGameEngine is a single file, header-include tool. It works on Linux, Mac, and Windows. It's been parted to a Nintendo Switch and on PlayStation Portable. We've had it running on Raspberry Pi and ChromeOS. It presents a very simple user interface. You just want to start your C++ application and draw lines, circles, and images, without having to worry about memory buffers, allocations, or popping up the window.
The community is now involved in PixelGameEngine's development. They've been developing all these additional things for it. We've got extensions with joypads, gamepads, sound effects, different types of rendering. It has become a powerful little tool.
Jason: Is PixelGameEngine a very large single header?
David Barr: No, it's 5,000 lines-ish. It tries to leverage all the operating system specific functions that are available. You don't have to download many supporting libraries or tools to get it to work. There's a whole bunch of different files, which you can include and give it this additional functionality.
Rob: I think you mentioned that there were some kids within the community. I have a twelve and a nine-year-olds. They're both into Minecraft and sometimes watching YouTube videos about Minecraft. I could totally see them being into this type of content. I'm wondering how many kids you're aware of within the community of PixelGameEngine developers?
David Barr: Now my YouTube channel tends to appeal to 25- to 35-year-olds, which I thought was a bit older than I was expected. However, on Discord it appeals slightly more to the younger, I would say we're looking at 15 to 25 as the dominant age.
The capabilities of the young people are frightening. They're writing code, which I have to take a second look at and wonder how it works. It's so advanced. It's great to see them come, putting the projects together. Particularly cool when they've joined the server with basically no skills, and then they're putting together their first applications completely independently.
Certainly, the PixelGameEngine has helped. I know it's being used in quite a lot of schools and universities now as a teaching aid. Whenever it's deadline day, I get hundreds and hundreds of messages saying, how do I do this in the PixelGameEngine? :)
Jason: I know there are some people who think that single header libraries are like a code smell. Do you have any comments on that?
David Barr: I won't argue with the fact that it's not a great way to do things. I have to maintain this bloody great big file. But if I went back, I could break it up into one header and one cpp. and release it that way. I chose not to because I liked this idea that you just have this one file, put this at the top of your program, don't ask any questions.
My entire mission is about reducing that barrier to entry C++ because I think it's brilliant. I like the fact that now Visual Studio is a tool. It is a really good tool. It's still a bit big to download, but it's got lots of useful features for beginners.
Rob: How often do you release videos then?
David Barr: Up until now, it's every two weeks. The first year it was every week. That almost killed me. It takes about 30 hours to make a video. It's usually about 20 hours to do the code and then 10 hours to film and edit the final result. I decided I've got to slow it down a bit. This year it's been every two to three weeks, but I've started doing some live streaming again on Twitch. It is a slightly different way of doing things.
Rob: Is there anywhere online where people can go and see some of the games that are created with PixelGameEngine?
David Barr: That's something that we're in the middle of doing, we're making a showcase gallery. Right now, the only place to see it would be the community showcase videos that are on my chart. I've collected some of the best ones. On our Discord server, we have a forum called Show Your Stuff, which is not exclusively PixelGameEngine, but there's a lot of PixelGameEngine applications that get posted there. I've started collecting them because I'm hoping we can stick them all and host them all on the onelonecoder.com website.
Thanks so much for reading the discussion. Rob and Jason would love to hear what you think of the podcast. Please let them know if they're discussing the stuff, you're interested in. If you have a suggestion for a topic, they'd love to hear about that too. You can email all your thoughts to email@example.com, like CppCast on Facebook, and follow CppCast on Twitter. You can also follow Rob at @robwirving and Jason at @lefticus on Twitter. And don't forget to leave a review on iTunes or subscribe on YouTube.
The hosts also like to thank all their patrons who help support the show through Patreon. If you'd like to support CppCast on Patreon, you can do so at patreon.com/CppCast. And of course, you can find all that info in the show notes on the podcast website at cppcast.com. Theme music for this episode was provided by podcastthemes.com.