Moving from Java to C++: An Interview with Rogers Cadenhead
Danny Kalev: For how long were you a Java programmer? Can you tell us a bit about the nature of the projects in which you took part at that time?
Rogers Cadenhead: I've been a Java programmer since the language was launched by Sun Microsystems in 1995. I was doing website development, and Java applets were the first available platform for creating interactive programs that ran in the browser. At the time the Java class library was so primitive it was the equivalent of making music by stretching animal hide over a barrel to make a drum. We even used it for dynamic site menus! I continue to use Java today, primarily for desktop software that consumes web services and mobile Android apps.
Danny: C++ has an image—justified or not—of an old and complex programming language. And yet many Java programmers eventually migrate to C++. Is this a phenomenon you have witnessed too? What may explain it?
Rogers: C++ is an old and complex programming language—Bjarne Stroustrup began work on it at Bell Labs in 1979, and the language has always been designed to favor programming power over ease of learning. But C++ is relevant and useful today. Writing Sams Teach Yourself C++ in 24 Hours with my coauthors really brought home for me how contemporary the language still is. That's pretty amazing for something as old as disco, Pet Rocks and Olympic swimmers with chest hair.
Danny: What brought you to C++?
Rogers: I undertook a project with a large and robust codebase that had been developed in Visual C++. I wanted to start over in Java, naturally, but I was mindful of something I learned from Joel Spolsky of Joel on Software fame: The worst strategic mistake a software company can make is to rewrite code from scratch. There's an unbelievable amount of learned experience reflected in any well-used and long-maintained code, no matter how cumbersome and kludgy you think it is. Start from scratch and you have to make a bunch of mistakes all over again.
Danny: What had been your worst fears about C++ before you started using it? In retrospect, did any of them materialize?
Rogers: I was afraid of pointers and memory leaks. Java reinforces the idea that without automatic garbage collection everything will be completely bonkers, the falcon can't hear the falconer and the center will not hold. James Gosling's impetus for creating Java in the first place was frustration with C++ on a project he was coding. His ire has been inherited by Java programmers and must be overridden when you learn C++.
Danny: Speaking of fears, which tactics do you use in your book to reduce C++
anxiety among readers?
Rogers: Because my book is part of the 24 Hours line, it's intended to be readable by a complete beginner without any programming experience. In the book I strove to introduce the features of the language in the simplest way possible and build on that, rather than to show all the different things you can do right away. C++ never dumbs down its functionality in the interest of reducing the ability of an inexperienced programmer to screw things up beyond recognition. This is a great thing when you've mastered the language because you can do amazing things with it in small blocks of code. But it can overwhelm even the most motivated beginner.
Danny: From your experience, what are the best tactics to learn C++? How are they reflected in your book?
Rogers: I'm tempted to recommend that people aspiring to learn C++ first delve into Java programming. But simple arithmetic shows that learning one language is easier than learning two. My advice for learning C++ is to take the features you understand and put them to use in working programs right away. If you can accomplish something with the parts of the language you've conquered, don't wait to master the rest before putting your skills to work. It's easy to fall into the trap of thinking that you don't know enough about C++ yet to get anything done with it. Nobody knows enough about C++.
Danny: Compared to Java, which C++ features impressed you most? Which Java features do you think are missing in C++?
Rogers: I love the ability in C++ to create objects that overload operators. When it makes logical sense that one object can be added to each other, using the plus sign (+) is far superior to Java's solution of calling one object's add() method with the other object as an argument. The two things that C++ could most use from Java are standard inline documentation (called Javadoc) and a class library as ambitious as Java's. The standard library for C++ is fairly limited in scope. The Java class library contains thousands of useful classes that provide a baseline of functionality for programmers to build on.
Danny: What's the best tip you can give to Java programmers who are making their first steps in C++?
Rogers: Don't go back to procedural programming even though C++ supports it. Object-oriented programming (OOP) is superior. You will design better programs that are easier to maintain and to extend, and you can spend your time learning all of the cool stuff you can do with objects in the language, like multiple inheritance and polymorphism, instead of relearning why OOP was created in the first place. C++ was designed as an extension of the C programming language, so it had to support procedural programming. You don't.
Danny: The C++ and Java communities seem worlds apart. Are the two languages really that different, or is it mostly political interests that keep the two communities and languages apart?
Rogers: At this point C++ and Java have coexisted for 15 years. Both are flourishing. They're assured of being widely implemented and broadly popular languages for decades to come. I think it's time for the devotees of these closely related object-oriented languages to band together against more trendy upstart languages and their programmers. Surely C++ and Java coders can find common ground in mocking the rock star vibe in the Ruby development community. Code doesn't run better because the programmer is cool.