I have never programmed in C++, but am going to be taking a class that involves programming in C++ in January. I want to be able to excel in the class, and looking for advice, as I come from a PHP background. How can I best prepare myself for success?

Do you need to write C++ for your job? Or is this just something you want to learn on the side?
–
Stephen GrossDec 8 '11 at 21:46

1

@Ryan Did you read the title of the question? is not a very constructive comment. Of course, what you're saying is correct, the title says you want to prepare for a course. But how you say it is also important. Same for the question itself, what kind of course, what are your specific skills and experience? I come from a PHP background. ranges from script kiddies that picked up PHP a week ago to seasoned PHP developers. I picked up PHP a couple of months after the release of 3.0 and it's been my primary development language since then, would be an example of what more you can tell us...
–
Yannis♦Dec 8 '11 at 22:04

2

University course or professional continuing education? Is it a beginner level course? Do you already know object-oriented programming, or do you mostly use PHP procedurally? What worries you about the class? Does the class presume you already know C++ and is just incidentally using it to teach other concepts like algorithms, or is the purpose of the class to teach you C++ itself?
–
Karl BielefeldtDec 8 '11 at 22:07

2

Or you could revise it to address the issues addressed in the comments. The motivation is not to close it, but for you to get a helpful answer. But why would anyone bother if you don't really care enough to improve the question? - Since you're kinda new here, closed doesn't mean deleted. Even if it gets closed you can still edit it and improve it, and it can get re-opened. And keep in mind that my close vote alone doesn't matter - still need four more...
–
Yannis♦Dec 8 '11 at 22:11

1

+1 for editing effort. Have to admit, first version text looked like a real disaster to me
–
gnatDec 8 '11 at 22:30

8 Answers
8

Your question is like asking, 'How can a baseball player prepare for a basketball match?'. Once a programmer learns a language, usually he/she has no problem learning a new language; same as a baseball player adapting to a basketball game.

The sportsman is fit, and the programmer has a basic understanding of language syntax and structure.

You will find several difference between C++ and PHP, yet a lot of time you will be thinking on how C++ is like PHP.

PHP is less strict than C++; C++ is what is considered a general-purpose programming language while PHP is a scripting language aimed at web development.

C++ process is different, a c++ program is converted into binary code, then loaded into memory and run directly.

If you really want to excel, then in my book you have to actually learn it on your own. I excelled in programming courses, because I knew most of the course beforehand. I see the best and most passionate programmers learning the language on their own.

If there is a book included with the course try to get your hands on it, and read it before the start of the course at least get ahead. Most of us don't have photographic memory and we can only learn by hearing something over and over again.

Learn it on your own and the course lecture would be the review. Warning: Following this advice might cause you to fall asleep in lectures.

Again start reading tutorials and books, start building things and you won't have problem excelling in your C++ class.

I find that proficiency at a given programming language is much like proficiency at any skill. While a good deal of study can help mitigate difficulties, the real "trick" is to practice1. And yes, some languages will be closer than others, just like certain disciplines will be easier to transfer than others — it is harder for a guitar player to learn viola than it is for a violinist to learn viola. The best thing you can do, then, is to focus on the major differences. And you'll definitely notice several major paradigm shifts between the two languages.

Here are some recommendations to help bridge that gap:

At a bare minimum, the idea of the PHP reference is very different from the C++ pointer. Considering its importance, you might want to consider studying that first.

After that, I would recommend learning first how to compile something larger than one or two files. While your at it, make sure you know the difference between #import <lib>; and #import "lib";

Learn the importance (and the difference) between .h and .cpp files.

Pre-processor directives/macros. Learn them and be able to write them.

1. How do you get to Carnegie Hall? Put this into Google Maps: 881 7th Ave. New York, New York.

I don't think it's important for a beginner to learn preprocessor macros as generally they are a "code smell" in c++. Certainly it's useful to be aware of them for things like header guards but otherwise I don't think a beginner would have the knowledge neccecary know when it's ok to use them.
–
Jake WoodsDec 9 '11 at 3:34

They are something which have thrown a wrench into debugging in the past.
–
cwallenpooleDec 9 '11 at 3:38

Yeah but everything in C++ is something that has thrown a wrench into debugging in the past. Attention is precious and I don't think a beginner would recieve gain attention vs. reward from being able to write in depth macros. I agree that an understanding of the basic mechanism is important but I don't think much time should be devoted to them.
–
Jake WoodsDec 9 '11 at 3:49

@cwallenpoole "PHP reference is very different from the PHP" looks like a typo, did you mean C++ reference is very different from the PHP?
–
gnatDec 9 '11 at 6:16

The best thing to do is to forget everything you know about PHP. It will only serve to hold you back in the C++ world. Many things which appear similar are in fact not similar at all, and it's best to just not try to apply your PHP knowledge.

Data Types: PHP is a dynamically typed language, while C++ is statically typed. So, you have to mention and keep track of data type explicitly everywhere.

Declaration: You have to declare a variable with it's type before using.

Array: The concept of an array is very much different in C++ compared to PHP. In C++, only numbers can be used as array indices. Like other variables, the array has to be declared with specific size which cannot be changed later. The index is 0-based.

String Handling: In C++(and C), strings are related with arrays and are manipulated differently.

Pay attention to C++ specific OO features, some C features like pointers and it's libraries. Good luck.

I took a series of Java programming classes a few years ago after working mostly with PHP for five years. In my case, I attended a community college.

The best advice I have is to stick with it. The first few weeks will undoubtedly be a little boring, but if you are inattentive, you may miss important key concepts. Don't be afraid to ask you instructor if you don't understand something and be careful not to rely too much on prior knowledge if you are unclear on what is being taught. That being said you are likely to find instruction on basic syntax redundant.

If you want to excel, read a chapter or two ahead before going to lecture and come to class armed with a question or two. A good attitude will help you learn. Also, speak with the instructor about your PHP knowledge before the class starts or after the first lecture. If enough people in your class are already programmers, your instructor may pace the class differently than if everyone is new to coding.

That's a good topic. But I keep wondering why other programmers feel offended anytime the issue of PHP comes up? Looking around the web, PHP is clearly the winner - l don't even know the importance of all these other languages, when almost 70% of the web is in the hand of PHP. You don't need to abandon your PHP background, a good programmer be it in PHP, Java or any other language can pick up any other language easily, just study the syntax and you are good to go. As a PHP programmer, it never took me long to start piloting java, but not much use.Rick Rhodes, l like your answer.

Other languages are important for many many reasons. Also be very careful spreading the common misnomer that moving from any language to another is nothing more than a study of the syntax, this belief bites many imperative programmers the first time they stumble across a functional language, and all the PHP in the world won't generally prepare someone for bit twiddling pointer math in a systems language.
–
Jimmy HoffaNov 2 '12 at 23:14