Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Fundamental Differences between PHP & C/C++
Old 09-14-2009, 08:21 PM Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
What are the fundamental differences between coding PHP and coding both C and C++ ?

what are the similarities between the languages?
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-15-2009, 01:06 AM Re: Fundamental Differences between PHP & C/C++
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
A lot of the syntax of PHP is borrowed from C/C++. A lot of the language features, however, are completely different. I'll do my best to write a non-comprehensive breakdown of some of the more important differences:

Type Safety
If you write code in C/C++ you'll have to constantly be aware of the datatypes you're dealing with. PHP, however, for the most part does not care about datatypes. You can assign any variable any value with out declaring a type and then reassign it a value of another type.

For example, none of the PHP code below will generate an error:
PHP Code:
$x 2;
$x 'hello';

function 
foo($input)
{
     echo 
"Your input was: $input";
}

foo(5);
foo('my string'); 
In C++:
Code:
int x = 5;
x = 'hello'; //x is an int, can't give it a string value

void foo(int input)
{
     cout << "Your input was: " << input << endl;
}

foo(5); //works
foo('my string'); //won't work, foo expects an int as input
The same thing applies to arrays. In C++ when you create an array it is of a fixed size and can only hold data of one type. Arrays in PHP (which aren't actually arrays at all) do not have a fixed size and can hold data of any type.

Compiled vs. Interpreted
C++ must be compiled prior to running your program. This means that your C++ code is turned into machine code. PHP code on the other hand is interpreted at runtime, meaning that your code is converted to machine code on the fly during execution.

Typically compiled languages tend to be faster than interpreted languages, however interpreted languages are more portable.

Garbage Collection
In PHP you don't have to worry about things like memory leaks. This is because of a program called a garbage collector that automatically deallocates any memory that is no longer needed. In C++ you have to tell the compiler explicitly when you are done with an object and it can be deleted.

Really I'm just scratching the surface here.

Edit:
1000th post
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-15-2009, 02:37 AM Re: Fundamental Differences between PHP & C/C++
wayfarer07's Avatar
Poo on You

Latest Blog Post:
jQuery Mapbox Updated
Posts: 4,040
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Edit:
1000th post
Lol. You should just stop right there. You don't want to turn out like me.... Probably you'll just forget and post again though...
__________________
Software engineer at
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-15-2009, 09:11 AM Re: Fundamental Differences between PHP & C/C++
chrishirst's Avatar
Defies a Status

Posts: 43,972
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
Lol. You should just stop right there. You don't want to turn out like me.... Probably you'll just forget and post again though...
And again .... and again .... and again ....
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-16-2009, 07:05 AM Re: Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Thank you NullPointer, that was an awesome explanation.

From what I understand, PHP has been described as a more forgiving programming language... as in, not so strict, like your C examples show.


I have also heard PHP being explained as a gateway language to other languages, as in, it's great to learn from before moving on to something else (like C/C++)... which tends to be less forgiving.

Although, some people prefer to stick with PHP, make a decent living with such and have no desire to learn any other languages.


Reason i'm asking these questions is I was finding recently some of the ideas I had for programming are foreign to PHP/MySQL (or just straight up impossible), whereas they're Absolutely Possible with a language like C++


[talkupation added by the way]
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-16-2009, 11:34 AM Re: Fundamental Differences between PHP & C/C++
wayfarer07's Avatar
Poo on You

Latest Blog Post:
jQuery Mapbox Updated
Posts: 4,040
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by Lashtal View Post
I have also heard PHP being explained as a gateway language to other languages, as in, it's great to learn from before moving on to something else (like C/C++)... which tends to be less forgiving.
I'd say that is a fairly common situation, but it's generally held that it's not the ideal way to learn. Because PHP is a forgiving language, it is easy to develop bad habits which make bridging the gap to C++ or Java difficult. It is generally held that learning a strict type-safe language first will make coding habits better once PHP is learned. I studied Pascal a long time ago, which is a structured language. Although I didn't learn any OOP pricipals at the time, it definitely helped me, especially since my only prior experience had been in BASIC, which relies (in the form I used it) heavily on the GOTO statement.

Compared to BASIC, PHP is also a structured language, but it's not in comparison to Java or C++. Whatever you do, if this is the path for you, learn languages. Learn several of them.
__________________
Software engineer at
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 09-16-2009 at 11:36 AM..
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-19-2009, 12:32 AM Re: Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Why do you recommend learning several languages as opposed to studying just one?
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-19-2009, 12:59 AM Re: Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
this guy: http://www.artima.com/weblogs/viewpo...?thread=259358

says, "...knowing more than one programming language vastly improves your programming skills."

I imagine this is a reason why you are inclined to agree. Any other reasons aside from this?
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-19-2009, 05:54 AM Re: Fundamental Differences between PHP & C/C++
chrishirst's Avatar
Defies a Status

Posts: 43,972
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's sort of true but it depends on where you start from.

Starting off with a weakly typed language such as Visual Basic or VBScript can(will) get you into bad habits when defining and/or casting variables.

I can write code in several different languages such as Pascal, Basic, VB, Javascript, VBScript with a bit of C/C++ thrown in amongst others.
One problem is you sometimes forget what you are coding in and mix up the syntax.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-19-2009, 11:16 AM Re: Fundamental Differences between PHP & C/C++
wayfarer07's Avatar
Poo on You

Latest Blog Post:
jQuery Mapbox Updated
Posts: 4,040
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I haven't coded in Basic or Pascal for a long time, but I'm fluent in JavaScript and PHP. I'm studying Python, and know smatterings of other languages like C and Java. Each language requires you to "think in the language" in order to get good at it.

My Spanish teacher always told us we had to learn to think in Spanish if we were ever going to be able to really learn Spanish. It is the same with programming languages. Although I've had much better luck with PHP than I did with Spanish, I understand now what she was talking about. I think learning different languages and thinking in each language helps us develop a better understanding of programming concepts, since although each language is its own discipline, they all share many of the same concepts.

Each language promotes its own best practices, and thus its own strengths. Those strengths can still apply to other languages. This is especially true when applying those strengths to loose languages like JavaScript. Often JavaScript developers, coming from other disciplines, will apply language constructs similar to the Java programming language, which will make the structure of the code stronger. C++ and Java Programmers also make good PHP programmers, because they already have a strongly reinforced sense of type and structure, which PHP doesn't naturally promote.
__________________
Software engineer at
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-19-2009, 06:16 PM Re: Fundamental Differences between PHP & C/C++
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
Based on my experience, the more your first language lets you get away with the harder it will be to understand a stricter language. For example, when I started college all of the CS students learned Java. After a few quarters of programming concepts and data structures taught in Java I had no problem with OOP and type safety.

One thing you don't learn with Java, however, is managing memory, namespaces, and pointers. All of these things made C++ a bit difficult by comparison. PHP on the other hand was a breeze.

This does not however make PHP an ideal language to learn first. Most likely it will make learning other languages an uphill battle. In addition to this many of the concepts you'll be forced to learn in some languages will help you in PHP.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-20-2009, 10:40 AM Re: Fundamental Differences between PHP & C/C++
wayfarer07's Avatar
Poo on You

Latest Blog Post:
jQuery Mapbox Updated
Posts: 4,040
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by NullPointer View Post
This does not however make PHP an ideal language to learn first. Most likely it will make learning other languages an uphill battle.
Yes, but I'd say any programming experience will help more than no programming experience at all. Starting from scratch it is difficult to understand even simple logical expressions, much less the stricter parts of the language, which form the whole.
__________________
Software engineer at
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-21-2009, 07:39 AM Re: Fundamental Differences between PHP & C/C++
helloworlder's Avatar
Novice Talker

Posts: 10
Trades: 0
I think it's important to learn as many programming languages as possible. The problem with just knowing 1 or 2 languages is that you're stuck with a specific paradigm meaning you're stuck with a single way of solving problems. I think learning multiple languages helps you think outside the box, and also means that when the time comes to work on a project you know which language is most suitable rather than picking the tool that doesn't do the job well.

Take for example first class functions. Not all languages support this. Programming languages that support first class functions enable you to treat functions as first class objects meaning you can assign them to variables and pass them as arguments etc. Otherwise if you're programming in C++ you'll have to resort to function pointers.

In C++ you have operator overloading. You can't do that in Java.

Also, languages such as Smalltalk and Ruby are true OO languages, meaning that everything is an object. Nothing is a primitive. This means you can do something like 10.times { print "hi there" }
__________________

Please login or register to view this content. Registration is FREE
- Learn Chinese through bite sized blocks

Please login or register to view this content. Registration is FREE
- Land the Plane

Please login or register to view this content. Registration is FREE
- Blog

Last edited by helloworlder; 09-21-2009 at 07:43 AM..
helloworlder is offline
Reply With Quote
View Public Profile
 
Old 09-22-2009, 12:07 AM Re: Fundamental Differences between PHP & C/C++
johniman7's Avatar
President, JLI Media

Posts: 965
Name: John Irving
Trades: 0
Great post, null pointer.

I took C++ in high school, it is extremely helpful to learning PHP, a lot of similarities.

When I reach 1000 posts, I want another Tshirt! lol ;D
__________________
Cheers, John Irving: My Blog
JLI Media:
Please login or register to view this content. Registration is FREE
| Website Development (Link Coming Soon!)
johniman7 is offline
Reply With Quote
View Public Profile Visit johniman7's homepage!
 
Old 09-23-2009, 08:56 PM Re: Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
I'll say this...

after about a year, i'm starting to get the hang of PHP.


i've been watching some C++ tutorials for myself just to see what's going on here and MAN, definitely stricter than PHP... more things to remember and keep track of, so am anticipating more trouble in regards to understanding this language (higher learning curve- but nothng some drive, patience and persistence can't overcome), and definitely want to mod some video games, so imagine i'll step into C++ after I learn enough about PHP to start making some full-time money with it. Then I plan on stepping into C++ and modding games for hobby


What do you guys know about making money as a freelancer for PHP v.s. C++?

there seems to be more of a market for PHP coders in general, while C++ jobs tend to pay higher (correct me if i'm wrong)


I'm having fun learning how to code, and eventually want to make a living doing it, but not really sure at this point how to transfer those skills into $$$

unless you're...

a) creating your own software and selling it

b) making bids on elance/scriptlance/getafreelancer.com

or

c) finding popular software online with an already estalblished audience that you can create mods and charge people money for.



I guess those options are enough for most people, but if you know a little bit more about these concepts than I do, could you go a little more into them and "drop some knowledge" on me?

Thanks,
Lashtal
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-23-2009, 09:36 PM Re: Fundamental Differences between PHP & C/C++
wayfarer07's Avatar
Poo on You

Latest Blog Post:
jQuery Mapbox Updated
Posts: 4,040
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
There's a lot more freelance jobs for PHP, because the nature of the development makes it easier to have a remote team that is not all in the same office. Also, C++ development is on the decline, and many of its practitioners are moving to other languages. There is a surplus of qualified developers relative to the demand. Or so I've been told.

C++ will be around for a long, long time, despite its decline. It will continue to be the language of choice for chess engines, games, etc.

I assume C++ jobs pay more, since more knowledge is required to do the job well.
__________________
Software engineer at
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-23-2009, 09:59 PM Re: Fundamental Differences between PHP & C/C++
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post

C++ will be around for a long, long time, despite its decline. It will continue to be the language of choice for chess engines, games, etc.
Right on.


Quote:
Originally Posted by wayfarer07 View Post

I assume C++ jobs pay more, since more knowledge is required to do the job well.
I did a search on this a few days ago, and basically the median annual salary for a PHP developer is somewhere between 45-50k (depending on what your source you're getting this information from), and 60-80k median annual salary for C++


Now, the more interesting debate (for me at least) is the whole school v.s. non-school debate.

I've read in several places quite a few thoughts on this.

Some sources claim that you can still get hired without attending a 4 year university, just the people who hire you want to make sure you know your sh*t; and even then, they will try to give you a 10-25k annual paycut "because you didn't attend school", etc. And use that as an excuse to pay you less.

While there are also stories of people, without formal education of any sort, that get recruited or hired on and paid fairly based simply on knowledge. With or without a formal education (i.e. degree)
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-24-2009, 02:31 PM Re: Fundamental Differences between PHP & C/C++
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
With regard to salary, while it is true that C++ jobs tend to pay more, I don't think that it is because C++ requires more knowledge than [insert lanaguage here]. The reason may be more related to the direction the industry is going in. C++ while still popular is being replaced by more modern languages. Currently you can get a degree in computer science without ever having to write a line of C++ (and I would have had I not gone out of my way to take a C++ course).

Because of this C++ skill tend to be more rare and C++ programers tend to be older (ie more experience) which mandates a higher salary.

The same concept applies to cobol programmers. Mainstream programmers would probably give you strange looks if you told them you were learning cobol, but there is still lots of cobol code out there that needs to be maintained, and people with the skills to do so are few and far between.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Fundamental Differences between PHP & C/C++
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53998 seconds with 11 queries