Should I learn C & C++ before learning PHP?

I think most of the Php Programmers didnt know C/C++…

I learned C++ before I learned PHP. (I didnt plan it that way) But it was really easier to learn PHP and C++ is quite easy to learn. And you arent limited to console programs with C++, like the new guy said!

PHP is a good prog language, i think PHP is enough to solve ur proglramming needs. C/C++ is a powerful language, robust. but its hard to code. PHP rules! hehe

What I’m doing at the moment, I’ve been developing with php for a couple of years, to expand my mind and because I love learning I’m learning c++ at the moment.

I haven’t programmed in C/C++ for years (used DOS based compiler :slight_smile: ). But I think that it is not necessary. Sure it makes it easier to learn other languages, but PHP is not C++ like in syntax for the most part and aside from using classes and a few syntactical expressions, there is not much in common.

In actuality, PHP is more like Basic in it’s free form flow.

I already know PHP, and I’m looking to learn C or C++. Where should I start, so I don’t have to go through all the boring basics I already know?

Who the hell wants to learn C/C++?? Do you plan to re-write DirectX or so? You’ll never need these languages. Go for C#/Java/Ruby/Python/other language. Why learn a low-level-language? Low-level-languages are only good for speed, and who needs speed these days? Sure, big 3d games need speed. So if you don’t plan on writing these, choose a high-level-language. I’m sure that if you write a C/C++ program you could do it twice as fast in Ruby.

Please compare:

C++ (is the syntax correct?, compare this to the readable Ruby code)
for(int i = 0; i < 5; i++)
print “hi”;

Ruby (even my mum could understand this):
5.times { print “hi” }

This thing will run 0.01 sec faster in C++. Who cares?

A friend wanted to learn a programming language. I gave him this loop in PHP and Ruby. What did he say? “I want to learn PHP, Ruby is too easy, nobody will be impressed when I write Ruby code because they’ll understand it.”

I don’t want to learn ruby. My desire rests solely in C and/or C++. The entire reason I want to use these languages is speed. I’ve used programs written in higher-level languages, and they run like garbage. The programs I plan to design, which extensively use loops, are slow, cpu-intensive, and unstable. Please don’t try to persuade me to learn another language, because I have my reasons for learning C versus learning something else.

I already know PHP, and I absolutely love it. The syntax is in NO way an issue, I’m fully comfortable with programming syntaxes. PHP is sometimes too slow, and too difficult to give to other people, and use in places there’s no internet. I want to use C/C++ to gain speed and versatility.

I apoligize if this response seems like an attack, but that response was completely against what I was asking.

Now, not to be rude or anything, but does anyone actually feel like answering my question? Thanks.

C++ isn’t a low-level language. Assembler is a low level language. If you’re going to write audio or video processing algorithms from scratch and make them fast (not to mention 3d games), you’ll need some assembler (and some intimate knowledge of processor architecture). Other than that, C++ is a good all round programming language, and you don’t need to know about the processor it’s running on.

Well, we need more categories to adequately label the different languages.
When people talk about a “high level language”, they are referring to the amount of abstraction provided.

Assembler-dialects are basically not abstracted at all, they are the lowest form of (human-readable) programming languages.

Then comes languages like C/C++, which are more abstracted but are still quite close to the hardware (if you want them to be). You manage memory manually (much like you do in ASM although C/C++ simplifies the process), and you can even write Assembler directly into the C/C++ code should you feel like it.

Up the ladder we have languages like C#/Java and Ruby/Python/Perl, which run in Virtual Machines or interpreters. They are substantially more abstracted than C/C++ are, and can quite accurately be described as high level languages.

So if we want to use the high/low labels, you could say that Assembler is Low, C/C++ are Medium-High and C#/Java/Ruby/Python/Perl are High.

Maybe we should start an effort to ditch the “Low/High Level”-labels and use a numeric scale to measure the amount of abstraction, where ASM is 0? That way we would get less posts (not just on SitePoint but everywhere) where people are having pointless (both are right, both are wrong) discussions about the level of C/C++.

Now, to a more on-topic note: Girard747, I suggest you pick up a copy of the Practical C++ Programming book by O’Reilly. It does provide an overview of the basics (to freshen up your memory and to make sure you’re on the up-and-up with C++ specifics) and then dives in to showing you Real World™ code and explaining all the parts of C++ in a good way.

If you want to learn C, the only real book to choose is the C Programming Language, 2nd Ed by Kernighan and Ritchie. It describes all the pieces of the ANSI C standard (not the absolute latest standard is covered in the book, but instead you can be sure that code you learn in that book will run under any future standard) and it really is the best book on the topic. Especially if you already know how to program.

Also, if you want to decide between C and C++, I can tell you that the C book is 272 pages long, and that includes a full summary of the ANSI C Standard Library. The C++ book on the other hand is 549 pages long.

While it’s highly unscientific, the difference in page numbers do describe the difference in complexity between the two languages. Although it should be noted that those 549 pages also cover the basics of C++, which are pretty much the same as the basics of C (I.E some of what’s covered in the 272 pages of the C-book).

I hope that was of some help to you. If you want more help/resources on C-related programming, you can go to the forum.

I learnt PHP then C. Apart from a few memory issues I didn’t have any problems. Knowing how to program is more than important than how to do something specific in a particular language.

Where should I start in order to design GUI-based applications?

Well, certainly not with C/C++.

You’ll need 100 lines to do a basic window. In C# that’s only 6 or so, 15 in Java and in Ruby 3 lines. Java and Ruby have the advantage of being cross-platform.

In Ruby:

require 'tk' { text 'GUI Application' }

Just search google for “windows #{language}”

Not to be rude or anything, but seriously… SHUT THE **** UP.

I want to learn C++. You’re like the annoying sales person in Best Buy telling me to buy a computer that I don’t want, when I have something specific in mind. You can’t persuade me otherwise. I don’t care about the length or difficulty of the code, I care about the way the program runs once it’s finished. Furthermore, speed is one of my major concerns once it’s compiled, and C++ is the language I intend to use for that purpose.

Now, please stop trying to change my mind. Are you a Ruby spokesperson or something? Honestly, it’s as if that was the only language you’ve ever heard of.

I feel so rude with these posts, and I don’t think it’s the way to address it, but I’m fairly annoyed. If this is too harsh, please tell me.

Well, it’s slightly harsh. Anyway, I took 4 years of CS classes that were all in C++. I don’t think Fenrir2 is seriously off base when he suggested C#. As a matter of fact, I think the .NET languages are pretty good. Especially if you’re looking to build a GUI application. I think what the former post was saying that you can program in C++ with more code, but it’s not going to be more efficient or noticeably faster than C#. Anyway, you have made it clear that C++ is the way to go. I personally would buy this book:
It focuses on abstract data types, OOP methodologies, and software engineering. I think this is the direction you need to go. The book is basically the equivalent of a Junior level C++ programming course. Then you can move on to advanced data structures, which would be like a senior level class. If you master C++ data structures, you can do whatever you please. I haven’t looked into qt deeply, but it’s a c++ gui:

Sorry, didn’t see you were the one in need of speed.


It’s a tutorial for Win32 api in C++, looks like a good one.

Are you a Ruby spokesperson or something? Honestly, it’s as if that was the only language you’ve ever heard of.
No, not at all. I’ve tried C, Java, PHP, C#, but I like Ruby so much because it is efficient. And I just don’t understand why people write 100 lines of code when the same thing can be done in 3 lines. The tradeoff is speed, but 99.9% of all applications can be done in Ruby without becoming too slow. But Photoshop, for example, is in the other 0.1%. So when you need speed, go for C/C++/Assembly. You could also do the expensive loops in C, and the GUI code in C#.

Okay. Now that you’re not trying to persuade me to try another language, I’d like to say thanks. Anyways, I think I’ll take a look at those suggested books. I’ve been meaning to get around to learning one of the C’s for a while now, but I just haven’t gotten around to it, because all of the tutorials I’ve seen are too basic, and I usually quickly get distracted. As long as I find something that’s relatively challenging, and my mind is set on finishing it, it’ll keep my attention all day and night long. I hope this helps me find a good place to begin learning. Thanks for everyone’s help, except for Fenrir2 trying to persuade me otherwise :wink:

I apoligize for being so rude, but I don’t like it when people try to change my mind from something I’m set on. Sorry. <- This is a very good introduction to Win32 API programming.

Actually, you’d be surprised. As part of my PhD I taught myself C++ and I translated some code from S (so another low-level language, bit like Matlab) into C++, and when you’re doing seriously intensive iterative processes (nothing like the example you have above) then the difference was beyond noticeable. I went from running 8 iterations in 16 hours to over 10,000 iterations in under a minute. I translated the code to Fortran as well and it wasn’t as efficient. So yeh, some people care.

(actually, see here: for a similar discussion).

To whoever asked about learning C++, I’ve got a few books here, but TBH I found trial and error and the cplusplus forums to be about the best way. I like the Bloodshed C++ compiler which is free and easy to get going with. Good luck getting to grips with memory allocation and pointers. :slight_smile:

Sorry, I just read this post and, first of all, I want to let you know that I never used Ruby.

I think that when you are talking about efficiency, you are only taking into consideration only the time that the programmer needs to write a particular routine or function (like creating a GUI Application). I think that the goal, when you build a complex application, is not to save you time in your programming (a nice thing, though) but to take maximum advantage of the resources in the computer so that it runs faster. Sometimes it means that you have to write more code to that effect. So, not only is important to think about the amount of code you need to write, but how the memory is handled as well.

I am assuming, since you say that Ruby is crossplatform with Java, that Ruby does have good memory handling methods and that it is efficient there, too. But it does make me think that, most of the GUI application (specially for windows) have libraries programmed with c/c++ and a visual interface created with visual basic or something similar (not very efficient language but easy to work with for visual interfaces)

On the other hand, since all OS are programmed with c/c++, I think that knowing those languages is useful.

But, hey, this is only my reflexion. It has been at least 10 years since I read anything about c/c++, so I may be completely wrong.