What's better C++ or PHP?

What's better C++ or PHP?

Page 1 of 1

11 Replies - 11791 Views - Last Post: 31 March 2010 - 10:07 PM Rate Topic: -----

#1 chrisdegrote  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-November 08

What's better C++ or PHP?

Posted 31 March 2010 - 03:45 AM

Dear all,

I've got a question concerning the two program languages. I've read an article about the lack of efficiency in the serverpark of Facebook. As a prograamer (I think) claims the serverpark could be reduced by 75% if they switched the source code to C++ instead of PHP. Hopefully somebody could tell me what's fact on this matter and what kind of code works more efficient on a large scale. For the article look here http://www.treehugge...their-code.php.
With kind regards
Chris

Is This A Good Question/Topic? 0
  • +

Replies To: What's better C++ or PHP?

#2 kingfeanor  Icon User is offline

  • D.I.C Head

Reputation: 44
  • View blog
  • Posts: 60
  • Joined: 18-April 09

Re: What's better C++ or PHP?

Posted 31 March 2010 - 04:40 AM

*
POPULAR

PHP is an interpreted language where C++ is a compiled language which becomes native code. Languages which are interpreted (PHP, Python, Ruby, Perl, etc) are slower then compiled languages (Java, .Net which use a virtual machine) which are a bit slower then compiled languages which become native code (C++, C).

So the article you site is no real surprise. By taking PHP and converting it to C++ and then compiling to native code, I would expect a performance gain. The actual % gain would depend on the particulars of the conversion, compiler settings, content of the code, etc.

People choose to write in PHP (Python, Ruby, Perl, etc) because of the ease of use of the language (minus Perl) and the libraries available. I have heard that one can write a web app in Ruby on Rails in half the time it takes to build a Java EE site. But in the end, the Ruby site will have more trouble scaling by a factor of 100 than the Java based site would. So for companies and developers there is a trade off. Do we get the site up quick? Or do we build a site that will scale? For Facebook, they used PHP to get the site and its features going quickly and when they got popular started worrying about speed and scalability. They took the path of making PHP faster through creating a PHP->C++ converter instead of relying on the Zend interpreter.
Was This Post Helpful? 7
  • +
  • -

#3 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

Re: What's better C++ or PHP?

Posted 31 March 2010 - 04:47 AM

any time i see a 'is x better than y' topic i usually think it should be written as 'is x better than y for z'
so is c++ better than php for serverpark (sic) mgt? i'd vote php
Was This Post Helpful? 1
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: What's better C++ or PHP?

Posted 31 March 2010 - 05:25 AM

For most sites, if speed is really an issue then it's likely that the code could use some optimizing. Many php coders are frequently doing things like:

$somevar = $_GET['somevalue'];
if($somevar == "something") { ...

and
function myfunction($x)
{
//code
}

that would be faster this way:
if( $_GET['somevalue'] == "something") { ...

and
function myfunction(&$x)
{
//code
}


Because it's interpreted these little things can add up to larger drags on the system than if you did the same thing in a compiled language.

This post has been edited by CTphpnwb: 31 March 2010 - 05:26 AM

Was This Post Helpful? 1
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2246
  • View blog
  • Posts: 9,236
  • Joined: 18-February 07

Re: What's better C++ or PHP?

Posted 31 March 2010 - 09:54 AM

*
POPULAR

In general C++ is not a good language for web development. It is ok for little CGI script with a dedicated purpose put for the day-to-day running of a large website with heavy traffic it is really pretty impractical on the surface.

To make C++ a viable contender you would need to design a whole multi-threaded application server in C++ which (in the end) means that you basically end up re-writing PHP...

To begin to see what I am talking about lets look at some of the downsides for C++ in web development and then look at solutions:

#1. Generally a CGI request will launch a new instance of the program -- this takes time and can eat away at resources. -- Solution have one process that "dispatches" requests to different pooled threads of the same app...

#2. Generally Web sites are very dynamic, changing all the time. C++ is NOT a rapid development environment. It takes time and care to maintain a clean code base. Not only that but classically web "designers" are not hard-core developers and like to work in HTML-like environments where the details of database connections and resource pools etc. are hidden away. -- Solution, use a nice HTML-comptatible scripting language that can be compiled into byte code to be executed by our "dispatcher" from #1...

Well in 2 steps we have already pretty much re-invented PHP...

Perhaps ASP or JavaEE would be a better environment than PHP, but to talk about replacing PHP with C++ sounds like maddness to me (and this is what I do for a living).

So while C++ is great for some aspects of web development (like image/video processing), it just sucks at the whole dynamic web development part...
Was This Post Helpful? 8
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2246
  • View blog
  • Posts: 9,236
  • Joined: 18-February 07

Re: What's better C++ or PHP?

Posted 31 March 2010 - 10:20 AM

If you think about it, the cost alone would be prohibitive... Time and money. Generally PHP developers are FAR easier to train and unfortunaly generally get paid less, and then there is the fact that PHP is a pretty quick development environment and C++ is NOT... so you would spend more time at a higher rate (and probably more developers).
Was This Post Helpful? 1
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: What's better C++ or PHP?

Posted 31 March 2010 - 12:21 PM

I would actually count much of PHP's easy/quick development as a negative. Easily training some one to use it doesn't mean they'll write quality code, and the costs associated with modifying or fixing their sloppy, procedural code later on probably undoes most of PHP's speedy development advantages.

I do like PHP better than C though, because I don't like having to declare so many things. For example, if a function is void I believe I shouldn't need to say so. The compiler should recognize that it is void without my help by examining what it returns. For the same reason I shouldn't have to declare the function outside of its definition, which shouldn't need the type spelled out. If it returns an int, it's int, and if it returns nothing, then it's void, etc. But that's just my opinion.

This post has been edited by CTphpnwb: 31 March 2010 - 12:22 PM

Was This Post Helpful? 1
  • +
  • -

#8 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2246
  • View blog
  • Posts: 9,236
  • Joined: 18-February 07

Re: What's better C++ or PHP?

Posted 31 March 2010 - 12:35 PM

Let me say that I am not saying that PHP is better than C++ or visa versa because I feel such statements are pretty useless. I am saying that for the purpose of writing web applications C++ is a poor choice.

as for this:

Quote

I would actually count much of PHP's easy/quick development as a negative. Easily training some one to use it doesn't mean they'll write quality code, and the costs associated with modifying or fixing their sloppy, procedural code later on probably undoes most of PHP's speedy development advantages.
This is a management problem not a development one. If you hire sketchy developers then no matter what language you are in you will get crappy code... there are PLENTY of crappy C++ "gurus" out there who can f*&#-up your code base just as fast a CS graduate working with PHP at their first job.

Bad programmers are bad programmers and they exist in every language and at every level of experience. Bad code in PHP is generally FAR easier to fix that bad code in C++.

All I was really saying is that the learning curve for PHP is no where near as steep
Was This Post Helpful? 1
  • +
  • -

#9 chrisdegrote  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-November 08

Re: What's better C++ or PHP?

Posted 31 March 2010 - 01:50 PM

First off, thank you all for commenting on my question :bigsmile: . I do understand the complexity of my question and I've just watched a video presentation of Jeff Rothschild here http://video-jsoe.uc...ildFacebook.asx . He's one of the tech guy's at Facebook. His message is in my opinion crystal clear about the problem with PHP on a very large scale with lots of code.

The reason I've posted this question is to find out how to optimize a system that's easy to scale up in the most efficient working manner. Facebook has to optimize their code now in order to match the rising demand. Like Facebook I'm interested how to get it from day one right and be efficient on a long term basis (5 years).
Sorry for the hassle
Was This Post Helpful? 1
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: What's better C++ or PHP?

Posted 31 March 2010 - 04:26 PM

View PostNickDMax, on 31 March 2010 - 02:35 PM, said:

This is a management problem not a development one. If you hire sketchy developers then no matter what language you are in you will get crappy code... there are PLENTY of crappy C++ "gurus" out there who can f*&#-up your code base just as fast a CS graduate working with PHP at their first job.
...
All I was really saying is that the learning curve for PHP is no where near as steep

True, but then management is more responsible for the messed up economy we're living in than the government is!

My point was that being easier, php is going to have more people who think they can do it. Since many of those people will be graphic designers who can claim some number of years "experience" with php, even if it was mainly dealing with using echo to output data, and management typically hires based on experience, many more poor coders will be using it.

I definitely agree with your basic premise though. The key is having not only the right tool (language) for the job, but the right programmer. My advice there is to keep management/HR out of the loop until that decision has been made. ;)
Was This Post Helpful? 1
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2246
  • View blog
  • Posts: 9,236
  • Joined: 18-February 07

Re: What's better C++ or PHP?

Posted 31 March 2010 - 08:12 PM

View Postchrisdegrote, on 31 March 2010 - 03:50 PM, said:

First off, thank you all for commenting on my question :bigsmile: . I do understand the complexity of my question and I've just watched a video presentation of Jeff Rothschild here http://video-jsoe.uc...ildFacebook.asx . He's one of the tech guy's at Facebook. His message is in my opinion crystal clear about the problem with PHP on a very large scale with lots of code.

The reason I've posted this question is to find out how to optimize a system that's easy to scale up in the most efficient working manner. Facebook has to optimize their code now in order to match the rising demand. Like Facebook I'm interested how to get it from day one right and be efficient on a long term basis (5 years).
Sorry for the hassle


So your question is basically: how do you manage scalability? Well at work we do it with JavaEE but for the PHP/MySQL side I recommend starting with this slideshow and I recommend the O'Reilly book "Building Scalable Websites" (its at the end of that slide show).

The most important thing is to go into the design with scalability in mind.
Was This Post Helpful? 1
  • +
  • -

#12 elgose  Icon User is offline

  • D.I.C Head

Reputation: 102
  • View blog
  • Posts: 228
  • Joined: 03-December 09

Re: What's better C++ or PHP?

Posted 31 March 2010 - 10:07 PM

Reminds me of a post regarding HipHop in the industry news section, which converts PHP to C++ (and is Facebook's project).

This post has been edited by elgose: 31 March 2010 - 10:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1