Talk:Understanding C++

Initial thoughts and ideas
Writing a technical book is a little like writing a computer program of comparable length; while it is a given that the details must be present and correct, the key is in having a clear vision for the structure and spirit of the work.

It might be possible to enumerate certain properties of the style of writing planned for this book, beyond the regular standards for all Wikibooks. Some debate on this is likely, but consensus should be very possible.

Let's start the ball rolling:
 * The book has a target audience. The suggestion on the table is that this is people new to programming.
 * The book has an area of focus. This may be only standard C++, or may cover some other areas.  It will be helpful to at least include some basic material on how to compile simple programs, but that quickly turns into a large area to cover.  It may be appropriate to have one chapter (or even two smaller chapters), possibly as an appendix (or appendices) to cover issues of compiling and linking code in the most common development environments (Unix-like and Visual Studio, maybe).
 * We might cover the productivity/clarity/correctness benefits of using C++ as a high-level language while also covering its low-level features for completeness. Before writing starts in earnest, it would be good to have agreement on how to combine the two, and in particular on whether the early chapters should cover one or both approaches.
 * While a book on C++09 would be great, Wikibooks discourages documentation of moving targets, so our focus will be C++98 aka C++03.
 * This book may or may not choose to cover/use some of TR1; one issue is that good support is not widely available, which is a barrier to those learning it.
 * Some coding conventions would be useful for examples, just as for a software project. Many styles are in use, and many thousands of hours have been spent debating them.

(To be continued.)


 * Yes I agree the focus of this book is for C++03, when C++09 has become accepted as a standard (eg no longer a moving target), this book can be updated to reflect any changes to that standard. I think TR1, probably should be covered. IIRC TR1, only includes additional libraries, which could be covered in its own chapter or chapters.


 * The target audience includes not only people new to programming, but people who have some experience with whatever they are going to use to do the programming on. Such as experience using Windows, Linux, MacOS, the embedded environment of their choice, etc. The focus is on Standard C++ and common programming constructs like linked lists, hash tables, trees, etc which are always portable and which programmers are expected to know how to do. There is additionally a prerequisite that people have read a book or some other material on how to install a C++ compiler or IDE and have read how to use it. I was thinking of maybe including links to such material in /Further Reading. This may include links to other Wikibooks, which cover the subject. There are other books which also do not include information on compiling a C++ program, such as "The C++ Programming Language" by Bjarne Stroustrup. There are so many compilers and other tools that its a big enough subject to be its own book. I do know and understand that it can be a tricky dependency, but it has been pulled off before. My thoughts are, this book shouldn't focus on or concern itself with what environment the readers may be using. Part of my plan for the Introduction chapter was to include some information that answers the questions of what programs are needed to write and compile a C++ program, but without mentioning a specific compiler. Maybe could include a link to the further reading page with a suggestion to check that page out for a list of tools for various environments?


 * I'm not sure whether this book should require a specific coding convention. I can understand however requiring all examples use a monospace font though.


 * I was hoping that part of the goal of this book would be to teach Standard C++ without any bias or favoritism to certain aspects of C++ and in a simple manner. For example, I was thinking this book could avoid discussion of high-level vs low-level languages, because I don't think its needed in order to understand C++ and where exactly C++ or certain aspects of C++ fits into that, I think is a moving target. So the first thing I think thats needed is to provide some way to help writers to avoid thinking of C++ in that was, so this book isn't written in that way and help get writers thinking in the way that will be a benefit to this book. For example instead of thinking of and trying to answer "how do I separate variables from..." instead thinking of and answering "Whats all involved in using and manipulating variables and how can I explain most of it in one chapter". I was thinking of creating some type of "what you will learn" or "what you will know" template to include in all chapters to aid both readers and writers. I think instead of agreeing how to combine them, it would be far better to maybe agree to whats needed to cover for example variables completely, how much to cover in a single chapter and what to cover in more detail later on.


 * To get some of my ideas down:
 * variables - basic types, structs, classes, unions, new, delete. explaining the relationship between the basic types and creating more complex types using structs, classes and unions. explain pointers and references in terms of how they relate to any types. cover the operators using to change the value of variables. Maybe not explain every detail of structs, classes and unions in this chapter, just enough to grasp that more complex types can be created and how. Covering all the details in a later chapter. Use string and other types found in the standard library. This chapter would also cover type casting and type conversion.
 * program flow - explain, if, for, while, do, exceptions and goto. explain the basics of exceptions, how to catch them. save throwing exceptions for a later chapter.
 * functions - declaring, creating and calling them. talk about function overloading, mention member functions and the minor distinctions.
 * user defined types, cover all the details of unions, structs and classes thats not already been covered, including operator overloading, the relationship between new and the constructor, between delete and the destructor, inheritance and polymorphisms. This might also be the chapter to discuss, linked lists, trees and hash tables. This chapter will also explain how to provide custom type casting through operator overloading.
 * templates - explain what they are, how they can be used for generic programming, use types from the standard library that make use of templates, and discuss improving on the linked lists, trees and tables from the previous chapter so they can be used for all sorts of types through the use of templates.
 * optimization techniques - different ways to speed up a program, such as creating an object which allocates more memory then it needs at first. Keeping everything in the realm or portability, which means things readers can do by hand.
 * debugging techniques - different ways to debug a program by hand. also must remain portable.
 * the standard library - split up by types and/or other means to cover every detail of the library.
 * possibly other techniques may be covered.
 * limit discussion on how manipulating data is stored, as to avoid making assumptions. not all computers store data in memory, not all computers use binary, See Ternary logic and Ternary computer for examples. The only assumption that can be made is the right thing will get done according to what the rules of C++ say. IIRC even the C++ standard avoids making that assumption, so this book should avoid it as well.

Thats all I can think of for now. --dark lama  13:45, 6 May 2007 (UTC)


 * In my opinion, ducking the high vs low-level issue is impossible. The first way people see to store a string value in a variable is going to have to make one choice or the other.  We can try to present all approaches in parallel, but that just makes for a confusing multiplicity of complex choices for beginners.  Maybe it's the terminology that's a problem.  Should we show people the short (programmer-time efficient) ways, the built-in (less programmer-efficient but more basic/primitive) ways, both?  There are so many choices in C++ programming, that to avoid "bias" is to avoid providing useful information.  As I mentioned before... I also think it's not possible even if we tried. -- James Dennett 22:07, 6 May 2007 (UTC)


 * I'm suggesting explaining both in the same chapter, but not in parallel. Using a top-down approach, a summary of all possible approaches followed by each individual approach in detail may be possible. Bias can also prevent providing useful information or cause information to be provided incorrectly. By bias I'm thinking of things which I think are covered by NPOV to avoid anyways. I use to read some C++ newsgroups (and C ones for that mater). There were often inexperienced people who seemed to have been easily influenced by opinions that were passed off as facts in bad books. I would like to have readers come away from this book, well informed and able to make their own opinions. For example a common occurrence was the opinion that if it works in the compiler they are using it should work in any compiler and if it doesn't, must mean something is broken with the compiler and not their programming. Another common one involved goto being slower or that goto should be avoided. --dark lama  00:57, 7 May 2007 (UTC)


 * Just a simple thing: I think we might be in agreement that both primitive and higher-level approaches should be presented rather than presenting an incomplete view. The more interesting questions are about emphasis and order of presentation.  A chapter which shows how to implement (say) string handling could start from std::string, and then derive a "String" class from the ground up, but doing so would require teaching use of classes, pointers, memory management, RAII, operator overloading and more.  Which is all very well -- but puts a lot of "details" up front rather than looking earlier at achieving results in the problem domains rather than the solution domain (C++).  I'd like a reader who's familiar with the whole book to be able to write a String class, but I'd hate for them to have to understand how to do that before they can write a simple, robust program to ask for a user's name and write  .  In a nutshell, the "high-level or low-level first" amounts to "focus on the problem domain or the solution domain" question.  The more you focus on one, the less you focus on the other.  There's no "neutral" position, no objective choice of where on the continuum to stand.  Many positions are defensible.  -- James Dennett 01:54, 7 May 2007 (UTC)


 * If i may interject, there is a difference between simply presenting the C++ language, and making your target audience "understand" it. Since the title of this book is "Understanding C++", it seems to me that the focus should be on the latter. We should strive to present all information in multiple ways, to help all audiences understand it, and to reinforce that understanding. Instead of selecting which way to present the material, we really need to look for a standardized way to present all methods of presentation. --Whiteknight (talk) 01:13, 7 May 2007 (UTC)


 * Can you give an example of what you mean? I'm not understanding what your trying to suggest/propose. --dark lama  01:21, 7 May 2007 (UTC)

Coding Conventions
I don't suggest that the book should try to promote a coding style to its readers, only that the style of any examples should be consistent. It's very jarring/distracting to readers to have to read code in different styles, just as it is suboptimal when a C++ project of significant size uses too much of a mix of styles. My personal preference might be to blend in with the standard library, though one might find merit in doing the exact opposite! -- James Dennett 21:57, 6 May 2007 (UTC)


 * For clarity, are you saying all examples used in this book should use a consistent style, or that the style used within one example should be consistent? --dark lama  22:09, 6 May 2007 (UTC)


 * I'm advocating that all examples in the book should be written in the same style. That's certainly the case for all printed C++ books I've seen.  Not sure I'd go as far as van der Linden in using names of fruits for all variables, but consistency here avoids distraction and confusion, IMO.  To be clearer: the "style" should apply only to trivial matters of convention such as layout and naming, I'm certainly not saying that only one "paradigm" should be presented.  Keeping the naming and layout the same allows the more interesting elements of the code to stand out. -- James Dennett 00:19, 7 May 2007 (UTC)


 * I would not have a problem with that, but I think it may become unrealistic when more people are contributing to the book, as people will generally prefer to use the style that they are most use to. I also believe readers might benefit some from seeing different coding styles. I was going to cover that some in the instruction chapter too. Comparing coding styles to writing styles. I'm indifferent to whether or not to stick to only one style or to allow multiple styles to be used, my only preference is sticking to a single style within an example. --dark lama  01:12, 7 May 2007 (UTC)

C++ Compilers/IDEs
My suggestion to include an appendix on using simple tools is based on the fact that this seems to be the single biggest sticking point for those trying to learn C++ from online resources (I've been reading the newsgroups for longer than I care to remember). I agree that it's good to keep the focus of the book away from platform-specific issues, but this is one place I'd make an exception. Obviously I'd be willing to do much of the work of writing a suitable appendix. While no book is an island, it's preferable for a Wikibook to be reasonably self-contained. (We can debate the "reasonably" there ad infinitum.) -- James Dennett 21:57, 6 May 2007 (UTC)