Sign in to follow this  

C++ -- PHP

This topic is 3734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have currently started learning C++, because I want to become a game developer in the future. I have some knowledge of the basics, which I've learnt in 2 months. Now my boss wants me to learn PHP, which is quite needed when making website's he says. I'll have to let my C++ down for some time, to learn PHP. Although I heard then when you learn other languages before C++, C++ will beocme a lot easier. Is PHP counted as one of those languages? Is PHP a good first step to C++, with the unnatural syntax and so? Second, does anybody know a good place or book to learn PHP from. I'd like to learn it in 2 weeks at highest, I don't need to know it perfect, as long as I am al right in it and know the most important things of the language. I heard PHP is not a super big language, so I must be able to do it. I got 8 hours a day, 5 days a week. If it will take longer, please tell me so with it. Thanks! Marlon.

Share this post


Link to post
Share on other sites
Personally I wouldn't know if learning other languages would make C++ easier, but for me learning C++ made learning other languages easier.

C++ and PHP syntax are fairly close so all you'll need to do is figure out what does what in PHP.

I presume you know how to setup a web server with PHP support or already have one, if not you might want to look into that first. At least be able to run a web server on your local machine, makes testing a lot easier.

It took me about a week to learn the basics of PHP and a while longer to get good at it. I am still learning new things every day.

If your boss wants you to learn PHP he might also want you to integrate it with a database, a lot of people use MySQL, so you'll want to look into that as well.

I mostly learned from online tutorials, examples and references. The best site to begin for me was: Tizag

Hope this helps.

PS Later when you're good at PHP and MySQL and you want to have some more on your plate, look up SQL injection. But I'm getting ahead here, just leave it for later.

Share this post


Link to post
Share on other sites
The best place for PHP information is their own website, PHP.net (I recommend downloading the extended CHM help file).

The basic language is quite straightforwards (and "C-like" as far as curly-braces go), and there is an extensive library of built-in functions. Most functions have user-submitted notes with good examples and important caveats documented.

All I can recommend with PHP is to make sure that both register_globals and magic_quotes are disabled as these will do unexpected and awkward things with variables and data, the latter lulling people into a false sense of security as far as SQL injections and data escaping goes.

Share this post


Link to post
Share on other sites
Many people are telling me that learning C++ without having any programming experience is going to give you a hard time. Do you think the hard time will be less hard when you've learnt PHP before C++ ? If so I think I'm going to do that. I am someone with a lot of perseverance, but I don't want to take any risks. My dream is to become a game (or software) programmer in C++, and I will go for that. I just don't want to take any risks, security is important. I have 2 months of C++ programming experience, and it's going quite well. Haven't done anything of the syntax though, and that's what people are warning me about, because it's so unnatural. I'm going to get there, no matter what it takes. I just like security.

Share this post


Link to post
Share on other sites
In my oppinion, learning PHP would be very helpful.

Getting to know php is not very difficult, and as the previous poster said, the syntax is very familiar.
Get familiar with variables, functions, loops, arrays, etc..

Then the only real transition to c++ will be the variable 'type' and pointers.
Then again i read though the entire PHP documentation before learning c++, i can only speak of how my friends struggled with the types when learning ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by marius1930
In my oppinion, learning PHP would be very helpful.

Getting to know php is not very difficult, and as the previous poster said, the syntax is very familiar.
Get familiar with variables, functions, loops, arrays, etc..

Then the only real transition to c++ will be the variable 'type' and pointers.
Then again i read though the entire PHP documentation before learning c++, i can only speak of how my friends struggled with the types when learning ;)



Thanks for your reply! I like C++ a lot, and if I start PHP it will only be a step of my way to C++, because C++ is the language I want to program with in the end. I like PHP a lot too though, because you can make web site's with it that look really good. I'm someone that likes making website's, so if I can take my first step on the way to C++ (actually second, because I've been busy studying the C++ basics for 2 months now) while keeping myself busy with some of my hobby's that would be great. As long as it will help me getting closer to my future goal, programming with C++, I am going to do that. Can anyone assure me that?

Ok, before I reply, I got a question and something to say. I am someone that needs a very clear way to work myself to my goal, so if I'm going to learn PHP, I can't learn it from a web site, because that is like 'a little bit here, a little bit there'. I like to learn it in a good way, I like to have a clear plan, like a book or like a course. I hope you guys understand that, and hopefully someone can help me with that.

I'd like to be sure that if I start learning PHP it will be of good use for my future goal, programming in C++. So if someone can assure me that with a rather good explanation I would be very grateful, and otherwise I'm going to stick to C++.

Thanks for all your help though. The guy that helps me with this will get a 'extremely helpful and friendly' vote from me.

Thanks in advance!

Share this post


Link to post
Share on other sites
Hey Marly,

Quote:
Original post by Marly
Is PHP counted as one of those languages? Is PHP a good first step to C++, with the unnatural syntax and so?

I'm studying computer sience at the university and we are only tought Java. Java is an object-oriented lanquage and the professors expect us to, if we are able to do java, we can do any oo lanquage. I do think PHP is not really loved for the oo. More over it hasen't been (good) oo since PHP 5. Also, php is not really a programming language who is very strict about your syntax (wile Java and C++ are). Also you almost don't get very good introduced with types. Next to these points, php is a language for Web Aplications, while C++ is a programming language for all sorts of applications.

A better step up between PHP and C++ would be Java or C#. Java and C# are almost identically to each other in syntax, but Java is cross platform while C# is a .Net language.

--
GBS

[Edited by - GraphicsBas on September 20, 2007 1:39:11 PM]

Share this post


Link to post
Share on other sites
I would say learning several languages is not a problem at all. Infact you will probably be learning several languages sooner or later anyway.
The bottom line is of course to choose one language and stick to it until you are comfortable using it before starting another.
As someone said PHP is and is meant to be C like.
The idea with PHP always was that a C programmer should be able to jump right into it.
The difference between C and C++ is not the syntax, but rather how you organize your code, data and ideas. C++ has some new syntax/semantics to accomodate this that was not present in C. Commonly referred to as Object Oriented Programming (OOP)
After C++ and OOP became "the norm" PHP has picked up on that as well and now offer the same syntax/semantics needed to program in a object oriented way, so its all good =)

Personally, if I had 2 weeks to get familiar with a language I would consider buying a book from O'Reilly. Even if their books is not the best, they will get you wet and they are cheap and easy to follow.

Share this post


Link to post
Share on other sites
Don't learn PHP (I know you have to, but still ;-)!

I've been a web developer for about 10 years now and I've written my first line of PHP code probably around 1998. But, despite the fact that I've used PHP for a long time, I still think it's a terrible language (I actually like it to some degree, but I like it the way you like a car you've had for many years that constantly breaks down on the freeway).

Here's a couple of reasons why PHP is a bad language for you to learn:

- The syntax is a mixture of C, Perl and Java (and usually just the crappy parts of each of these languages)
- PHP doesn't have a namespacing system, yet it has > 2000 built-in functions (that all reside in the same global namespace)
- PHP's built-in functions don't share a common naming convention and parameter orders are more or less random
- Even if you decide not to use global variables, PHP will already have a whole bunch of those registered before you even write a single line of code (and I'm not talking about the register_globals kind of global variables)

The most important reason however is, that PHP promotes bad coding practices. Now you can't attribute that directly to the language, but if you haven't done much coding before, PHP can easily spoil you for life.

If you have a chance to learn something else, go for Ruby or Python.
I don't think PHP will help a lot with learning C++, but that's just my opinion.

Before this comes up: Why is PHP so popular if it's such a bad language? Because it's free, because it replaced Perl which was even worse, because it promotes sloppy coding and a lot of people know nothing else, because it has everything you'll ever need already built-in, ... lots of reasons ... but not because it's a particularly nice language.

Share this post


Link to post
Share on other sites
Quote:
Original post by Marly
Many people are telling me that learning C++ without having any programming experience is going to give you a hard time. Do you think the hard time will be less hard when you've learnt PHP before C++ ?

Somewhat.

If you learn PHP, you will have learned a lot of basics about programming and problem solving, as well as norms of C-like languages and imperative constructs. All of that will be reused in C++ (among many other languages).

Quote:
I am someone with a lot of perseverance, but I don't want to take any risks.

Then you're doomed to failure. Risk is a prerequisite of success. Besides, you're not going to be any kind of good programmer if you don't learn multiple languages. Knowing C++ is not enough. I've used C++, Perl, Python, VBScript, VBA, C#, VB6, C, JavaScript and declarative languages like XML/XSL/XSLT/XSD, CSS and HTML for work. When I worked in the game industry (not a programmer), the programmers at our shop used Java and Shockwave in addition to C++.

Quote:
I just like security.

So did C programmers of the 70s and early 80s. So did COBOL programmers of the 60s, 70s and 80s. So did Java programmers of the 90s. So do the current crop of .NET programmers. It's a false notion. Your tools will change if you stay in this business for over 5 years. Get comfortable with the notion.

Quote:
Original post by GraphicsBas
Java and C# are almost identically to each other in syntax, but Java is cross platform while C# is a .Net language.

That makes no sense. Java is a JVM/Java runtime language. The runtime/VM has been ported to several platforms, just as the .NET runtime has been ported to several platforms - Mono is an independent implementation for Linux, now with a formal cooperation agreement with Microsoft, and Microsoft itself provides a Shared Source implementation for BSD called Rotor.

So, really, there's no difference between Java and C# in terms of approach to platform support.

Quote:
Original post by pulpfist
The difference between C and C++ is not the syntax, but rather how you organize your code, data and ideas. C++ has some new syntax/semantics to accomodate this that was not present in C. Commonly referred to as Object Oriented Programming (OOP)

The differences between C and C++ extend far beyond object-oriented programming. There are differences in language spec guarantees as to defined behavior, differences in idioms, massive differences in standard library provisions, differences in support for programming paradigms (C++ provides some syntactic support for generic and functional programming in addition to object oriented, whereas C is fully capable of expressing all of them but requires you to author the mechanisms yourself), among others.

Quote:
Original post by Harry Hunt
[PHP] replaced Perl which was even worse...

Whoa, now! Perl has had a namespacing mechanism, for example, for years. Perl is better than PHP in every measurable way except immediate comprehensibility to beginners/unfamiliars. Once you understand how Perl works, you realize that it is an incredibly powerful, feature-rich language with an extensive collection of freely available extension modules (CPAN - all of which are organized in packages, which is Perl's namespacing mechanism, but also more than that: packages are lexical scope).

Yes, it's "ugly." But it can trivially do some things that would reduce your brain to gibbets.

Share this post


Link to post
Share on other sites
Quote:

The differences between C and C++ extend far beyond object-oriented programming. There are differences in language spec guarantees as to defined behavior, differences in idioms, massive differences in standard library provisions, differences in support for programming paradigms (C++ provides some syntactic support for generic and functional programming in addition to object oriented, whereas C is fully capable of expressing all of them but requires you to author the mechanisms yourself), among others.

True, but hardly covered in a 2 weeks course

Share this post


Link to post
Share on other sites
When I said Perl is even worse, I didn't mean that it was less capable than PHP. Also, to some degree it's actually nicer than PHP because unlike PHP it grew in a kind of controlled fashion whereas PHP just grew and became this frankenstein's monster of very loosely combined features. However, as you said Perl can very easily become very difficult to read which is less true for PHP.
I dunno, maybe Perl isn't actually worse but the way it's commonly used definitely is.

Share this post


Link to post
Share on other sites
Let me just say this from my own experience. I'm programming now around 20 years, every day (except when I'm sick or on vacation). In those years I've been through several languages - starting out with BASIC, going through Pascal, sniffing assembly etc etc.. However I've settled on C and sometimes C++ (mixing two of those here and there).

After a while I was practically forced into PHP for web development (business choice I really had no plan to do), but it turned out great. The result now is that I'm almost always starting out projects in PHP (I'm not talking about web based stuff). Let me explain. I'm prototyping algorithms and frameworks in PHP since it's like C Light, you don't have to care which variable is what type, you don't have to be extra careful about how you pass stuff around etc. It is really great for prototyping - start early, test often! Then when you know what you want to do, get inside C or C++ and code the monster away. Also, I've been using PHP as a script tool on my linux machine, as well as windows machine - it almost always works great.

I wanted to give Python a serious try, but without { } I simply can't do it. I feel opressed by syntax. Maybe I should give it another go - but maybe I won't since I'm quite happy with the tools I use.

Share this post


Link to post
Share on other sites
Quote:
Original post by pulpfist
True, but hardly covered in a 2 weeks course

Nothing useful about C or C++ can be covered in a 2-week course. If you're going to present didactic information, do it right, for the sake of the learner. Not everyone (forget the OP; other people learn from threads they never participate in) is going to come back and read your correction/refinement/admission.

Quote:
Original post by Harry Hunt
When I said Perl is even worse, I didn't mean that it was less capable than PHP.

...

I dunno, maybe Perl isn't actually worse but the way it's commonly used definitely is.

Caveat: the way C++ is abused (as C-with-classes) is even worse than Perl.

Share this post


Link to post
Share on other sites
Quote:

Nothing useful about C or C++ can be covered in a 2-week course. If you're going to present didactic information, do it right, for the sake of the learner. Not everyone (forget the OP; other people learn from threads they never participate in) is going to come back and read your correction/refinement/admission.

There was nothing wrong with my initial reply. Maybe I was missing a "among other things" somewhere in there. Thats about it.

PS. I got a lot of positive feedback from people I have replied to here on GD. Not many negative. I'm sure you have more important things to do than bashing on my reply sir.

Share this post


Link to post
Share on other sites
Thanks for the replies!

I talked about it with my boss, and said that it wouldn't be great to learn PHP for my C++ future. He said he really wanted me to learn PHP. Do you think that will be a problem? Will I get into trouble with C++ later if I learn PHP now? I'm very motivated and have a lot of perseverance, keep that in mind. Learning C++ is my first goal in life, together with getting a good life with my girl and children!

Share this post


Link to post
Share on other sites
Quote:
Original post by Marly
I talked about it with my boss, and said that it wouldn't be great to learn PHP for my C++ future.

Rubbish.

Quote:
He said he really wanted me to learn PHP. Do you think that will be a problem?

No.

Quote:
Will I get into trouble with C++ later if I learn PHP now?

No.

Quote:
Learning C++ is my first goal in life...

Frankly, that's disgusting. I know you mean to say you're motivated, passionate and enthusiastic, but "first goal in life" is unnecessarily hyperbolic.

Share this post


Link to post
Share on other sites
I am at my girlfriend, I didn't think I would have a chance to get behind the computer, but I had. You're right, first goal in life is a bit too much, but I mean it's my goal in life (when looking at work) to become a game programmer. Is that better?

Ok, does anybody have any suggestions on a good way to learn PHP ?

Thanks in advance!

Marlon.

Share this post


Link to post
Share on other sites
Quote:
Original post by Marly
...I mean it's my goal in life (when looking at work) to become a game programmer. Is that better?

Much better, though still a bit off. See, professional goals change, so don't affix "in life" to them. It's a job, dude. You can become a game programmer as a hobby and have all the fulfillment of achievement that way, while spending your days as a stockbroker or something equally soul-crushing. That's life.

Quote:
Ok, does anybody have any suggestions on a good way to learn PHP ?

You've been given several. To recap: download PHP from the website, PHP.net (it's an interpreter, so you can run it from the command line). Download the manual, too. Configure it to work with your web server on your local machine (Apache or IIS, doesn't matter). Write pages and try stuff out. Google for a tutorial and work your way through it.

Happy hacking!

Share this post


Link to post
Share on other sites
Do you think that I will know PHP when I have readed through all the pages in the manual of PHP? If so that would be great and I'm going to start on it at monday.

Thanks for your time anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Marly
Do you think that I will know PHP when I have readed through all the pages in the manual of PHP? If so that would be great and I'm going to start on it at monday.


That's not really how you learn a language (by reading through its manual), but yeah the manual is actually a good place to start. However, you'll have to do a whole lot of coding yourself to fully understand how things work.

Share this post


Link to post
Share on other sites
An important thing that has been hinted at so far but deserves being said out loud is the fact that knowing a language (that is, being able to read code and understand what it does, or knowing which function will solve what problem) is a very different think from knowing how to use a language.

The latter involves knowing how to write code that does what you want (often foiled by forgetfulness, little annoying details, and slight overlooks), knowing what you want (this is more difficult, you have to be able to separate 'what the code should do in the use cases I've come up with' and 'this is a complete description of what should be possible and what shouldn't', as only the latter is of any use), knowing what will be easy to change later on (as code that cannot be changed easily is code which will invariably be thrown away and rewritten), knowing what is repeated and what is relevant and how to factor this out (typically transforming identical code into a for-each and an array), and generally being able to find out the easiest feature to implement without having to actually implement it to find out.

PHP creates a large advantage, because it's more flexible and forgiving than C++, so you can make mistakes that are much more obvious and apply much more elegant refactorings than you could in C++. And, once you'll be back in C++, you'll factor out those details much more easily.


Quote:
http://c2.com/cgi/wiki?OnceAndOnlyOnce
I recall once seeing Beck look at two loops that were quite dissimilar: they had different for structures, and different contents, which is pretty much nothing duplicated except the word "for", and the fact that they were looping - differently - over the same collection.

He changed the second loop to loop the same way the first one did. This required changing the body of the loop to skip over the items toward the end of the collection, since the previous version only did the front of the collection.

Now the for statements were the same. "Well, gotta eliminate that duplication, he said, and moved the second body into the first loop and deleted the second loop entirely.

Now he had two kinds of similar processing going on in the one loop. He found some kind of duplication in there, extracted a method, did a couple of other things, and voila! the code was much better.

That first step - creating duplication - was startling.


Quote:
Original post by Oluseyi
You can become a game programmer as a hobby and have all the fulfillment of achievement that way, while spending your days as a stockbroker or something equally soul-crushing.


Oh, come on, we both know very well that those people don't have souls to begin with.

Share this post


Link to post
Share on other sites

This topic is 3734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this