Code::Blocks on the Mac

A lot of Mac users have written to complain about the stability of Code::Blocks 8.02 on the Mac. This is the version used for the 2nd Edition of C++ All-in-One for Dummies. My first recommendation is that you obtain a copy of C++ All-In-One for Dummies, 3rd Edition if at all possible. This edition of the book contains additional installation details, updated examples, and all sorts of extras that will make your C++ learning experience so much better. Of course, not everyone will want to make the upgrade, but I stick by previous posts saying that some examples won’t work as well as they might if you use a different version of Code::Blocks than specified in the books. However, I also feel your pain. I personally didn’t experience stability problems with the 8.02 release and I’m sure others didn’t either, but enough people have complained that I feel obliged to discuss the issue in a post.

The Code::Blocks 13.12 version used for the 3rd Edition book is considerably more stable than the 8.02 version used for the 2nd edition book. If you really must continue using the 2nd edition book with your Mac, I suggest that you update to Code::Blocks 13.12 if you find that the 8.02 version causes you problems. If you go this route, please be sure to read the Using Code::Blocks 13.12 with C++ All-in-One for Dummies post. It provides you with information you absolutely must have in order to use the updated version successfully.

I always want to hear your book-specific input at John@JohnMuellerBooks.com. Your input helps me create better books and it also allows me to provide posts like this one that help readers work around potential issues. Thank you for your continued support of my books!

 

C++ Data Type Usage

The Going Overboard section on page 43 of C++ All-In-One for Dummies, 3rd Edition talks about the problems that can occur when you try to stuff a number that’s too large into a specific data type. The problem with the example shown:

    cout << 8762547892451 * 10 / 2 * 3 + 25 << endl;

is that it doesn’t actually result in an error. C++ accepts the large number by using a data type that can hold it automatically, rather than using a default data type of long as would have happened in the past. It’s nice that C++ automatically fixes ambiguous code for you, but it also means that the example doesn’t work as described in the book. In order to see the example as originally intended, you need to change the code to read:

    long MyLong = 8762547892451 * 10 / 2 * 3 + 25;
    cout << MyLong << endl;

The code will now produce an error, just as described in the book, because the data type isn’t ambiguous any longer. The error message does differ slightly. What you’ll see is an error message of:

warning: overflow in implicit constant conversion [-Woverflow]

Except for having to make the code less ambiguous, the section should continue to work as it did before. Please let me know if you have any questions or concerns about this example at John@JohnMuellerBooks.com.

 

C++ Switch Statement Using Strings

Readers sometimes ask me the same question often enough that I feel compelled to provide the answer on my blog so that everyone has the benefit of seeing it. C++ does have a switch statement, but you need to use a numeric value with it as described in my book, C++ All-In-One for Dummies, 3rd Edition (see page 233 for details). A number of C# developers who are also learning to use C++ have asked me about using strings in the switch statement, which is clearly impossible without some fancy programming technique.

Fortunately, I have found a method for implementing switches using strings on CodeGuru. As the author states, it’s not a perfect solution and you may not find it works for you, but it is an ingenious coding technique and you should at least look at it. It’s better than saying the goal isn’t achievable using any means. To get a better idea of the methods other coders have used to overcome this problem, check out online discussions, such as Why switch statement cannot be applied on strings?.

Of course, I’m always on the lookout for other good solutions to reader problems. If you have a solution to this issue of using strings with the C++ switch statement, please contact me at John@JohnMuellerBooks.com. I always want to keep the door open to an even more innovative solutions. In the meantime, keep those e-mails coming!

 

C++ All-in-One for Dummies, 3rd Edition, Error

It seems to be my week for reporting errors! Just yesterday I reported one in Beginning Programming with Python For Dummies. Today I’m reporting an error in C++ All-In-One for Dummies, 3rd Edition. If you look in Book I Chapter 3 on page 67, you see Listing 3-6. The listing title tells you that this example uses brackets to access an individual character in a string, which is precisely what it does. However, what the example is supposed to do is show you how to create the string in the first place. Look at Listing 3-7 on page 68 and you see an example that performs this task. The two listings are switched. As you go through the book, please use Listing 3-7 first and Listing 3-6 second. I’m sorry about any confusion caused by the error. Please contact me at John@JohnMuellerBooks.com if you have any questions about this or any other error in the book. I’ll be only too happy to help.

 

Understanding the Continuing Need for C++

I maintain statistics on all my books, including C++ All-In-One for Dummies, 3rd Edition. These statistics are based on reader e-mail and other sources of input that I get. I even take the comments on Amazon.com into account. One of the most common C++ questions I get (not the most common, but it’s up there) is why someone would want to use the language in the first place. It’s true, C++ isn’t the language to use if you’re creating a database application. However, it is the language to use if you’re writing low-level code that has to run fast. C++ also sees use in a vast number of libraries because library code has to be fast. For example, check out the Python libraries at some point and you’ll find C++ staring back at you. In fact, part of the Python documentation discusses how to use C++ to create extensions.

I decided to look through some of my past notes to see if there was some succinct discussion of just why C++ is a useful language for the average developer to know. That’s when I ran across an InfoWorld article entitled, “Stroustrup: Why the 35-year-old C++ still dominates ‘real’ dev.” Given that the guy being interviewed is Bjarne Stroustrup, the inventor of C++, it’s a great source of information. The interview is revealing because it’s obvious that Bjarne is taking a measured view of C++ and not simply telling everyone to use it for every occasion (quite the contrary, in fact).

The bottom line in C++ development is speed. Along with speed, you also get flexibility and great access to the hardware. As with anything, you pay a price for getting these features. In the case of C++, you’ll experience increased development time, greater complexity, and more difficulty in locating bugs. Some people are taking a new route to C++ speed though and that’s to write their code in one language and move it to C++ from there. For example, some Python developers are now cross-compiling their code into C++ to gain a speed advantage. You can read about it in the InfoWorld article entitled, “Python-to-C++ compiler promises speedier execution.”

A lot of readers will close a message to me asking whether there is a single language they can learn to do everything well. Unfortunately, there isn’t any such language and given the nature of computer languages, I doubt there ever will be. Every language has a niche for which it’s indispensable. The smart developer has a toolbox full of languages suited for every job the developer intends to tackle.

Do you find that you really don’t understand how the languages in my books can help you? Let me know your book-specific language questions at John@JohnMuellerBooks.com. It’s always my goal that you understand how the material you’ve learned while reading one of my books will eventually help you in the long run. After all, what’s the point of reading a book that doesn’t help you in some material way? Thanks, as always, for your staunch support of my writing efforts!