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?
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.
Extra: THe New Boston - C++
C++ and PHP are worlds apart in terms of applications and usage patterns. Your PHP knowledge will help you by giving you a head start on basic programming concepts such as
- Conditional Statements (If/Else)
As well as any program designing experience you may have picked up while developing PHP applications.
If you want to get the leg up in your course the best way is to start by ignoring your PHP background beyond the things outlined above and focus on some of the following:
- Memory Management (Pointers, new/delete, Constructors/Destructors, RAII)
- Differences between the PHP object model and the C++ object model
- Basic Datastructures (Arrays, Trees, Linked Lists)
- Basic Algorithms (Sorting, Searching and being able to determine the best algorithm for the job)
Another good resource is your teacher for the course. I'm sure if you send them an email they will be able to give you some resources to get started.
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.
My two cents-
- 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.
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
- Learn the importance (and the difference) between
- 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.
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.