CppCast - CMake, Git and Functional Programming

Episode Date: March 19, 2015

Episode number 4 of CppCast with guest David Sankel recorded March 17, 2015 David Sankel is a professional software developer/architect based in the USA. His prolific software developments hav...e included CAD/CAM, computer graphics, visual programming languages, web applications, computer vision, and cryptography. He is a frequent speaker at the C++Now! conferences and is especially well known for his advanced functional programming in C++ talks. David's current research interests include dependently typed languages, semantic domains, EDSLs, and functional reactive programming. He currently works for the software firm, Stellar Science. News When CLion met biicode How much should you pay your engineers What are some everyday life things you use C++ for My favorite C++ 10 Liner David Sankel Paper: Modern Functional Programming in C++ Functional Programming in C++ The Intellectual Ascent to Agda Functional Reactive Programming - Cleanly Abstracted Interactivity Intro to Functional Programming in C++ Links Stellar Science C++Now!

Transcript
Discussion (0)
Starting point is 00:00:00 Episode number four of CppCast with guest David Senkel recorded March 17th, 2015. In this episode we talk about a few everyday life things you can use C++ for. Then I'll interview David Senkel about using CMake and Git in large projects. I'll also talk about David's experience in functional programming using C++, the only podcast for C++ developers by C++ developers. I'm your host, Rob Irving, and I want to start out this episode by thanking Ankit Asthana for being the guest for Episode 3. He had a lot of very interesting news to share from the Microsoft Visual C++ team, especially in the mobile development space. So if you hadn't had a chance to listen to that episode,
Starting point is 00:01:18 go back and listen to Episode 3. It was a good listen. I also want to read a piece of feedback that I got this week from Rami. Rami writes in, thank you so much for CBPCast. You can't imagine how much I am excited about it. Ever since I fell in love with C++ some time ago, I've been searching for a podcast dedicated to C++ to no avail. And I really feel the same way. And that's why I decided to start the show. So he says the search is over. It really makes his day coming back from work, seeing that I posted a new episode. And he says that he listened to a bunch of Hanselman's episode where they have a couple C++ episodes in there and he's listened to each one a handful of times.
Starting point is 00:01:58 So no longer does he have to scavenge for C++ material on podcasts. He goes on to say he's really enjoying the show, and I think you do an excellent job keeping the show interesting throughout. Thank you. It would be really interesting if you can get some experts to talk about C++ in the game dev industry, as well as in embedded applications, where performance is valued
Starting point is 00:02:18 overall. So I'm definitely going to take that advice. I'll be on the lookout for someone in the game dev and embedded application space who would be interested in coming on the show to talk about C++ and how it is such a valuable language in those spaces. So joining me tonight is David Sankel. How are you doing tonight, David?
Starting point is 00:02:41 Good. How are you? I'm doing great. David is a professional software developer architect based in the USA. Good, how are you? C++ Now conference and is especially well known for his advanced functional programming in C++ talks. David's current research interests include dependently typed languages, semantic domains, EDSLs, and functional reactive programming. He currently works for the software firm Stellar Science. That is quite a resume, David. So I have a couple news articles I want to talk about tonight before we get into the interview um the first was coming from the sea lion blog article titled when celia sea lion
Starting point is 00:03:35 met by code and this is pretty interesting uh we talked about by code in a previous episode and it looks like sea lion is now integrating with Bytecode for its dependency management. Have you had a chance to look at this article, David? I have. What do you think about it? Well, I think it's interesting that Bytecode is getting wider adoption, so we have CLion now. But I do have some concerns about Bytecode as a whole. And is this going to actually solve our dependency management problem in C++? Okay, yeah, I haven't had a chance to use it myself. It's something I really have been meaning to try out. Have you had much experience with by code? I've just read a bit about it. I haven't actually booted up and tried it myself. Okay,
Starting point is 00:04:23 yeah, I've been meaning to try it out. So I'll have to get C-Line installed and take a look at it with the BioCode integration. The next article is, it's kind of a long article, but I just wanted to highlight one part, and this is how much should you pay your engineers? And it goes through some salary statistics of different programming languages and how much engineers proficient in those languages are making. And it seems like the C++ engineers are actually on top. Did you take a look at this, David? I did. It's, of course, an interesting piece. Everybody wants to know how they stack up related to their peers.
Starting point is 00:05:03 Yeah, absolutely. So feel free to go take a look at that. It goes into a lot more than just that, you know, whether you can get better income as a freelancer versus working in an IT firm, specific types of engineering and how well they fare. But the very first graph is about the languages, and I just thought that part was interesting. The next article comes from Reddit, the CPP subreddit, and it was just titled, What are some everyday life things you use C++ for? And I thought this was pretty interesting because a lot of us might work with other languages too, Like I use some C sharp, some Ruby. And the person writing this, uh, Q and a basically said, you know, I like C plus plus, but it might not be my go-to language if I'm working on like a hobby project or a small tool for myself. And you wanted to know if there were other people who would use C++ for that sort of thing and what they may have built that they'd like to talk about.
Starting point is 00:06:08 And I saw STL from Microsoft, Stephen Lavavege, I believe is his name, and he says he wrote his own financial calculation application using C++, I think. And he actually, I believe, wrote his website using C++, I think. And he actually, I believe, wrote his website using C++ or some engine that converts Markdown into HTML using C++, something like that. But one of the really interesting things I found linked from this Reddit was this Channel 9 video from the Going Native conference two years ago with Herb Sutter talking about his favorite CPP 10 liner. And the video kind of then goes into this game framework called Cinder.
Starting point is 00:06:56 And apparently Herb challenged the audience of this conference to go try out Cinder and make their own little games. And some of the developers in the audience made some pretty cool things in under 200 lines of code. Did you have a chance to look at the video? I did, yes. Very interesting. Yeah, I did not hear about Cinder prior to watching this video, and it was pretty impressive what people were able to put together with only 150 to 200 lines of code.
Starting point is 00:07:26 Yeah. And that Reddit comment that you had mentioned earlier, that was really interesting because I think that most people don't use C++ for these small, medium-sized projects. Right. And it's a really interesting thing because a lot of the features that C++ has, such as the strong typing and things along those lines, those things don't really start coming into strong effect until you have a medium to large size projects that you're developing. So developing things in C++, you know, little tiny tools for this and that, it's more of, you know, just out of fun, but it might not necessarily be the right tool for the job unless you see this thing growing to be really huge.
Starting point is 00:08:07 Yeah, that's definitely true. But yeah, I would definitely recommend all the listeners go to that Reddit thread and read through it because there are a lot of interesting things coming up there. So the last thing I want to talk about before talking to David is I put up a poll on Twitter and Facebook earlier this week. And the poll I put on this time was, are you using CMake to manage your C++ projects? And the answers I put down were yes, and I love it. Yes, but it could be better. No, CMake doesn't work well with my project. Or no've never tried it you have any guess at what was the winning answer David? not the I use it and I like it thing it was actually
Starting point is 00:08:53 yes and I love it got 43% of the votes I'll be honest that I actually fall into the no I've never tried it category so you'll have to tell me a bit about CMake and what makes it special. Yeah. So you've given several talks at C++ now, usually focused on advanced functional programming concepts, which we mentioned in your bio. This year, though, you're going to be giving a session on CMake and Git. Can you tell me a bit about the talk you're preparing? Absolutely.
Starting point is 00:09:27 So first, I just want to mention that this talk was controversial. Really? Because, yes, because it's not directly related to C++. And I think that that is an ideal situation, right? As if we don't have to worry about these build tools and these version control systems, because they just kind of work in the background and that's fine. And we can just concentrate on C++. But I think that our current situation with C++ and our build systems is so bad that we need to address this as a community. For example, if you want to use boost, it uses B jam. Nobody uses B jam, but boost.
Starting point is 00:10:08 So you have to figure out a way to integrate this B jam system into your build system or use the binaries and deal with the hassle that that involves. If you're going to be able to use it in your system and people will go through this for boost. People will go through the process because boost is a well-known, great set of libraries. But what I really care about is Joe Schmoe's library, which is really fantastic. And I'd love to give it a try and to mess around with it a little bit, but I don't want to go through the hurdle of integrating with however he happens to build his system. So I think that as a community, we really need to standardize on something, something solid. And I think that Git and CMake are really the only contenders that are available right now that can be a standard for our community.
Starting point is 00:10:52 What is BGEM exactly? Someone on my team has been bringing in Boost libraries to our project, but I'm not familiar with what BGEM is. So there was a build system called Jam. It wasn't used very much. And then Boost adopted it and took the source code and expanded it, and they called it BJam. I think that now it's being called Boost Build. But it has a special syntax for the files,
Starting point is 00:11:22 which is kind of related to Makefiles, but it's really unusual syntax, and it just didn't get the adoption that probably the Boost people had really hoped for at that time. And Boost ends up being pretty much the only software toolkit out there that uses this build system. Okay, interesting. So what are some of the common issues that C++ developers can run into when using CMake and Git in a large code base? So if you look at CMake code, it kind of looks like a scripting language. It looks like shell script or something like that, mixed with maybe COBOL because you see a bunch of capitalized letters. And basically, if you need to get something done, you just add a little piece
Starting point is 00:12:03 to your script. And then if you need to add something done, you just add a little piece to your script. And then if you need to add something else, you add a little piece to your script. And what happens over time with large projects is that this little script turns into a gigantic behemoth that only like one or two developers can possibly understand or parse. And then when these error situations come into the picture, you can end up spending several days just diving into CMake code to try to figure out what went wrong or how to fix it. And this is generally due to the fact that we don't really treat our build system as software itself. We do this great software engineering with our C++ code. It's all well abstracted. But when we look at our CMake code, it's usually a huge mess. And so what I'm really interested in doing is try to figure out how we can get rid of the mess, how we can solve the common problems in a common way to where our build system code looks just as well,
Starting point is 00:12:57 just as nice as our C++ system code so it can scale properly. So what are some of the suggestions you're going to be making in this talk? So one of the suggestions I'm going to be making is the use of the find system. So right now there's a find system. It's built into, shoot, what are we talking about? CMake, sorry. So the find system is built into CMake. And what it does is it'll pull in binaries for common libraries like Zlib or something like that and then give you the ability to link with those. But if you're developing with a large system, you generally don't work with binaries. You want to have every single piece of source code editable so if a developer needs to fix something, he can jump in
Starting point is 00:13:41 there. So one of the things that I'm going to demonstrate is hijacking the spine system. So if I find package Zlib, then it's going to bring in the source code to Zlib into my project that wasn't there before. And it will use the source code and the targets that it generates so that I can use it in my code. But not only that, for third-party libraries, which find package Zlib, that they can get a consistent interface as well. So I don't need to modify third-party libraries just because I happen to be using not binaries with Zlib. So this is really one of the key aspects of the talk, which is how to tame this find system to work with a large project that has the source code open for everybody. Okay, interesting. I see that CMake can be used to create build files for
Starting point is 00:14:28 Unix, Windows via MSVC projects along with iOS and Android. Are you using CMake to target multiple platforms? Oh yeah, so for our projects we're targeting various Unix flavors, Linux and Windows development and one of our projects is targeting OSX as well. So we really need that cross-platform support. Does it do a pretty good job at targeting all the platforms? Because I think one complaint I saw was that it doesn't do as good a job with the Windows projects. Is that true? So my experience with the Windows projects is that it does okay, and it works.
Starting point is 00:15:04 So a lot of our Windows developers like to use Visual Studio as their development environment. So it does a good job to bring them up to speed and they can use it. The integration isn't perfect, but I don't really know of anything that's better at this point. But on the flip side of that, if you're willing to forego Visual Studio on Windows, you can generate stuff for Ninja, and you can run things more like on a Unix backend. And for really large projects like we deal with, that's almost a necessity
Starting point is 00:15:34 because Visual Studio does not handle projects as large as we have. It's a 32-bit application, and it just dies out. What types of project sizes are you talking about exactly? Like how large? So millions of lines of code, hundreds of third-party dependencies. Okay. Yeah, that's pretty big. Now what about Git? How does Git factor into this? Does it introduce its own unique problems with large C++ code bases compared to other version control systems? So Git, unlike CMake, seems very well placed to be used as a version control system,
Starting point is 00:16:16 especially when working with third-party libraries. So if I want to use a third-party library, Zlib as an example again, I can pull in its code right directly from Git and make it a submodule of my project and then use that code directly. So the Git submodule system works very well. Sometimes when you do your initial checkout, if it's a gigantic project, it's going to take a long time. But once it's downloaded and up and running, it seems to work pretty well once you realize just the little tricks that you need in order to make it work with a large system. Okay, interesting. In the past, I see you've given a bunch of talks on functional programming at C++ Now. This might be a difficult question to
Starting point is 00:16:56 answer in a short interview, but can you tell me a bit about your functional programming talks in C++? Yeah, absolutely. So I love functional programming. I've been functional programming since I think about 2003 when I started messing around with Haskell. But the thing that's really neat about functional programming is that if you look at really good quality C++ code, it is functional. It has the style of a functional programmer. So you have a function, for example, that has its inputs and its result type only depends on the inputs.
Starting point is 00:17:29 It doesn't depend on any global variables or any of these other type of things, which are already considered bad style. So if you take that to the extreme and you really jump into functional programming, what you find out is that what it's all about is making a mathematical model of the thing that you are trying to code.
Starting point is 00:17:44 So if I happen to realize that, oh, what I'm really doing here is I'm working with abstract 3D vectors or something like that, and then make your code match those semantics. So I know that I have addition in mathematical space. I know I have all these other operations. And don't allow anything to corrupt the semantics of your code. So I'm not going to add a name to my Vector 3 class that belongs somewhere else. So keep everything to a minimum. Do it in a mathematical way.
Starting point is 00:18:13 Come up with a mathematical semantics for it. And then you're going to end up coming up with code which is extremely reusable and will solve the problems that you have today as well as unforeseen problems in the future. So you contrast that with the way that a lot of software development is done these days where you make a class and oh you need a new feature so you add some more member functions and you end up with a 50-ton behemoth that isn't working well anymore. So functional programming is about finding that minimal clean set of functions that can be used as your basis and build everything on these tiny pieces and put it all together. And what you end up with is a really scalable system
Starting point is 00:18:52 that's highly generic. So that's basically the gist of what all the functional programming talks are about. And what are the sorts of applications where you find functional programming extremely applicable? I mean, can you apply those concepts to anything or are there specific fields using C++ where it might be more common to see? So in my experience, it applies very broadly. If you're working on very low level system code, though, and you really care about, you know, file IO and things like that, the paradigm, the appropriate paradigm paradigm for that level is imperative. But if you want to start moving up the levels of abstraction, no matter what the domain happens to be, functional programming is a huge bonus.
Starting point is 00:19:34 And this is especially true with simulation software and things where you really are explicitly dealing with the mathematical concepts. When you're dealing with just large systems, then you kind of got to figure out the mathematical concepts. It's a little bit more difficult, but once you do, you really can get some beautiful code. What about functional reactive programming? Can you tell me a bit about that? Yeah, absolutely.
Starting point is 00:19:58 So we talked a little bit about semantics and about finding a model for whatever it is that you're developing. Functional reactive programming developed a semantics and about finding a model for whatever it is that you're developing, functional reactive programming developed a semantics for interaction at a very generic level. What is an interactive program like? And basically the way that you develop your programs with functional reactive programming are functions of time. So your input to your function is going to be, you know, let's say you have a mouse movement. The input to your function is going to be a time function. So all the time from the moment that the program started up until the current, up until the
Starting point is 00:20:31 end of the program, that will be a function from time, which is like a real number to a 2D coordinate value. And the return value of your function is going to be another function of time. But this time it'll be a function from time to perhaps what you want to have displayed on the screen. So it's a completely radical, a completely different way of describing interactive applications. And people have been doing this in the functional programming community for several years. But with that C++ now talk, I showed that we can actually do this in C++ Now. And it solves many of the problems that they had in the functional programming community because they were stuck on Haskell.
Starting point is 00:21:11 So I'm very excited for this library and for the idea of getting this concept out there because it really can change the way that you program and it makes it much more concise and much more semantically easier to understand complex programs. So it can work with games, it can work with robotics, it can work with computer animation, all kinds of different things. Very interesting. You mentioned Haskell there for a moment. What are some of the other languages that are popular in the functional programming community? So generally you have a number of languages which come from ML, which is an old language that isn't used very much now, but the modern variants, you have OCaml and you have Haskell. You have Scala, which is kind of a hybrid language along with F sharp in that domain.
Starting point is 00:22:03 And then you have the modern functional programming researchy languages where are things like Agda, which Agda right now is kind of where Haskell was about 10 years ago in terms of like people knowing about it. But it really takes things to the next level. It's a very exciting functional programming language in my mind, but it's so theoretical that I don't think you can actually use it to program anything practical at all. Okay, interesting. You are a member of the C++ Now Program Committee, which is coming up this May in Aspen, Colorado. Are you expecting anything exciting at this year's conference? You know, every single one of these conferences is super exciting because you never know what you're going to get.
Starting point is 00:22:48 So unlike some of the other ones out there, this is a conference where they really concentrate on experts meeting experts. And things happen there to where a couple people will get together and they'll make something new which nobody had even thought of. So it's just a really great session where people are, it's a meeting of minds, basically. And we're trying to discover new things and present our research and understand other people's research and try to build on, you know, what we have. It's a very small conference, like maybe 100 to 200 attendees, I believe. Yeah, exactly. It's very small. So, you know, you will end up talking with the speaker that you find interesting or anybody else that you happen to see there. And that's another one of the wonderful things about this conference.
Starting point is 00:23:30 Although the bad part about that, the flip side, is that it's hard to get into. So registration has already expired. I think it's been sold out for the past several years. That's great, though. It's always wonderful to be able to have some one-on-one time with the speakers. Yeah, though. It's always wonderful to be able to have some one-on-one time with the speakers. Yeah, absolutely. So there's been a lot of changes in C++ over the last few years. What are some of the highlights from your perspective? What keeps you excited about C++? So I'm really excited about the things that have been happening with C++11 and C++14.
Starting point is 00:24:03 Right now, we're starting to see a rollout of some of these features in multiple compilers. So people like us with multi-platform needs, we can start using this stuff. And especially the threading stuff, I think is really exciting. Just being able to take a variable, a static variable, and say that this is going to be a per thread variable by putting that scoping parameter in there, that's wonderful. So it's opening up all kinds of possibilities for running multi-threaded code. And for what I'm working on right now, which are high performance web-based pieces of software, having this kind of a capability has just been wonderful.
Starting point is 00:24:41 That's great. Can you talk much about what you do at Stellar Science? So yeah, Stellar Science is a small software outfit headquartered here in Albuquerque. There's probably about 30 developers. We do department of defense work and we basically are concentrated on scientific computing.
Starting point is 00:25:01 So we ended up creating a lot of simulations and things like that for the government. And like I mentioned, we have very large-scale type problems to solve, so we have very big problems and big source code type issues to solve, and it's really just a wonderful place to work. Great. Well, anything else you want to share with the listeners tonight? Nope. Just, you know, if you can make it out to Aspen, not this year, but next year to come on out for this conference, because it's going to be great.
Starting point is 00:25:33 Great. And, you know, you're going to be talking about CMake and Git. But as you said, it is a pretty closed doors conference. Do you make any blog posts or anything about this subject by any chance? I've been meaning to get my blog site back up. I took it down a few months ago and have been working on the replacement, but hopefully it'll be up and running again by the time the conference comes around. Okay, great. And is there any way to find you online before you get your blog up? Do you have Twitter or anything like that? Nope, I'm pretty closed off from the internet right now. Okay, well, we look forward to your blog coming back online then. Well, thank you for your time, David.
Starting point is 00:26:12 Yeah, thank you. Thanks so much for listening as we chat about C++. I'd love to hear what you think of the podcast. Please let me know if we're discussing the stuff you're interested in, or if you have a suggestion for a topic, I'd love to hear that also. You can email all your thoughts to feedback at cppcast.com.
Starting point is 00:26:29 I'd also appreciate if you can follow CppCast on Twitter and like CppCast on Facebook. And of course, you can find all that info and the show notes on the podcast website at cppcast.com. Theme music for this episode is provided by podcastthemes.com.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.