MyBB Community Forums

Full Version: Learning C++ after learning PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
so i'm pretty ok with PHP and i now want to make the jump to QT so i have to learn C++

so i'm going through the online docs and i am finding a lot of similarities Big Grin


anyone have any experience and wanna share their experiences
"Good luck" Toungue
Both have quite similarities, yes. But before starting C++ I recommend you to learn the frameworks of PHP so that you could make dynamic web applications using different PHP flavors.
Pointers are probably one of the harder things for people to get, but if you think of them as $$var it's not that hard. Memory management also trips up a lot of people because you have to remember to delete everything you allocate. The last thing is there's a lot you can do by default in PHP that you have to code yourself (or download a library) in C++.

OTOH there are things that are very easy in C++, such as direct manipulation of data on a byte level (i.e. bitwise-XOR a float with 0x80000000 to flip it's sign, set the 425th integer index in a binary stream to 0x31415926, etc.).
(2012-03-14, 10:11 AM)Yaldaram Wrote: [ -> ]Both have quite similarities, yes. But before starting C++ I recommend you to learn the frameworks of PHP so that you could make dynamic web applications using different PHP flavors.

I am pretty good with Codeigniter so PHp wise i am ok

(2012-03-14, 04:08 PM)Firestryke31 Wrote: [ -> ](i.e. bitwise-XOR a float with 0x80000000 to flip it's sign, set the 425th integer index in a binary stream to 0x31415926, etc.).

That made a lot of sense 0.o
Well the first one's more of an advanced trick for people that don't want the performance hit of dealing with that kind of thing the normal way. The second one is for things like reading/writing a binary file, which is something a lot of programs do. As a hobbyist game developer I tend to use these things a lot (float-interpreting tricks not so much, but it's not unheard of to use bizarre binary maths to screw with floats really quickly (there's a bad word in there so watch out). Let's see someone do that easily in PHP).

C++ is easy if you take it a little at a time. Ignore these bit-twiddling hacks until you understand the long way of doing things, then learn why they do it this way instead.

My only serious must follow suggestion is to never blindly copy-paste code you find on the internet until you understand why they've written it that way. Not following this will lead to bugs you'll never be able to fix because this copy-pasted code doesn't work with that copy-pasted code but you don't know this since you don't know what exactly the code is doing.
If you thoroughly understand one language, another one using similar paradigms should be easy (as in this case).

(2012-03-14, 04:08 PM)Firestryke31 Wrote: [ -> ]OTOH there are things that are very easy in C++, such as direct manipulation of data on a byte level (i.e. bitwise-XOR a float with 0x80000000 to flip it's sign, set the 425th integer index in a binary stream to 0x31415926, etc.).
You can do bitwise operations in PHP too.
I'm also wary of hacks like XORing with 0x80000000 - I'm sure this wouldn't be portable across platforms (but perhaps not an issue in your case). I don't do much FPU work, but on all the int CPUs I know, flipping a sign is a one opcode operation, and I would imagine this should be the same for fpmath. Even if not, an optimising compiler/assembler should pick something like that up, and a programmer shouldn't need to worry about it.
Okay, I get it that you're just giving an example, but I would try to shy away from these hacks in general.


You can easily change single bytes in a PHP string, though multi-byte operation not so easily as you can with C/C++.
Mostly I was trying to give an example of how you can bit twiddle data without having to go through a bunch of fun trying to convert what the data is treated as without actually changing the data. I personally don't use those kinds of hacks yet since I've never gotten to the point where I need to do things like Carmack's Inverse Square Root, it's just fun knowing they're out there.

If you're trying to learn C++, I would not advise making a game as your first project unless it's a very simple guess-the-number game (which is probably going to be one of your first C++ projects anyway).
I learned C first, then I began with PHP about an year ago. Having the syntax similarities to some extent in PHP with C made my complications comparatively less.
yeah Qt is pretty much kicking my behind right now ....

I dunno but from what i read Qt and C++ are (or should be) the same thing

yet the more i read the more different they look

at least from the Qt creator anyway

Pages: 1 2