Six Questions for Ivan Čukić, author of Functional Programming in C++
Ivan Čukić has been coding since 1998, and is now a core developer in C++ at KDE. He teaches modern C++ and functional programming at the Faculty of Mathematics at the University of Belgrade.
Jump into any page of the book from the table of contents on liveBook!
|C++ is an older language. Who is using it these days, and what are they doing with it?|
|It is true that C++ was created a long time ago, but it has been evolving in recent years so much that it “feels like a new language,” to quote Bjarne Stroustrup, the creator of C++. It appears in most places where people care about efficiency. From embedded systems, through normal software like games, photo manipulation software, office suites, web browsers, to web services in big companies like Google, Facebook or Yandex. One of my small pleasures is to see software I worked on show up in photographs from historical events, like the discovery of the Higgs boson at CERN; and more recently, NASA’s Mars InSight landing. So, C++ was there as well.|
|What is the intersection of C++ and Functional Programming?|
|While languages like C++ are not traditionally considered to be FP, most of them do provide us with features which allow us to express functional idioms. C++ possibly even more so, because it stopped being just OOP-focused quite early on. When C++ first became an ISO standard, it included a standard library that was everything but object-oriented. It used a novel paradigm created by Alexander Stepanov that he dubbed ‘generic programming. ’ Incidentally, this is what made FP get its foot into the world of C++. The generic programming idioms Alex created used many concepts derived from FP, tailored to fit the programming model of C++.|
|You’ve written: “The main philosophy of functional programming is that you shouldn’t concern yourself with the way something should work, but rather with what it should do.” Explain.|
|A long time ago, all software was written in some assembly language. Then people realized that thinking in terms of jumps (gotos and alike) leads to errors. Nowadays most software is written in higher-level languages that raise the level of abstraction from jumps into loops, branches and function calls. These abstractions model common patterns that people had in their assembly code. And this is good. But it is not as good as it can be. All these are still overly general and low-level, and it is easy to again recognize patterns in how people use them.
Common usage patterns can again be used to design higher-level abstractions, like all the things in the <algorithm> header of the standard library of C++. Just as with abandoning explicit jumps, using these higher-level abstractions removes a lot of places where we can make mistakes. The abstractions like those from <algorithm> are now tailored at achieving a specific task, and they communicate that clearly with their names. If we see something named find_if, it takes less than a second to figure out what it does from its name alone. Abstractions like these are used to design programs in the terms of “what it should do” They allow us to write more expressive code, more terse code, and thus more correct code.
|What does it mean to think functionally?|
|FP is about thinking in transformations that need to be performed on the data, using the previously mentioned abstractions instead of thinking about the algorithm steps that need to be performed to achieve the result.|
|In what ways does it help a C++ programmer to learn to think—and program—functionally?|
|FP can help any programmer (not only C++) to write safer code. Being able to express ideas on a higher level of abstraction removes many places in which we might make errors if we were to manually translate those ideas to a low-level programming language.|
|What can you tell me about the artwork you have up at Deviant Art? Do you have any formal training?|
|I have to say I didn’t expect this question. Although I like making art (drawing and music mainly), I have never studied it. I have an unorthodox (and I guess completely wrong) view on art: I don’t want to be taught ‘the right way’ to do it; I just want to do what I like. Most of my artwork nowadays is digital. Almost everything I do is done in programs for vector graphics like Inkscape.|