TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
View Poll Results: Which language do you think would hold the future?
PHP 24 70.59%
Python 1 2.94%
Perl 1 2.94%
ASP 1 2.94%
Java 1 2.94%
Ruby 2 5.88%
Lisp 1 2.94%
Other 3 8.82%
Voters: 34. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-18-2008, 12:03 PM   #1 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default PHP compared to other languages...

I love coding in PHP, but, I read a lot of articles that deplore PHP for a variety of reasons. I am sick and tired of hearing that my favorite language for web programming sucks! Here are a few articles that I would like some of the advanced users here at TalkPHP to comment upon:
???? blog Ruby vs PHP performance
PythonVsPhp - PythonInfo Wiki

I have heard a lot of good things about Python (namspaces,OO, et al). As I am still young is it worthwhile to get acquainted with say, Python?

Another question, what is this obsession with OOP? People talk a lot about inheritance and namespaces being primary reason to use OOP, but, most of the classes that I had come across (at say phpclasses.org) could be implemented with just plain functions. Is there a price in performance that one has to pay if one chose to use a class instead of a function? Can someone point me to an example where using a class is better than using a function. Some smart Programmers like Paul Graham say they never had use for OOP (he along with a few others built Viaweb, a shopping portal, which I think later got converted into Yahoo Stores, so it was definitely a big project that he had coded for)
cosmok is offline  
Reply With Quote
Old 01-18-2008, 12:41 PM   #2 (permalink)
The Visitor
 
Join Date: Jan 2008
Posts: 2
Thanks: 0
FooBarWidget is on a distinguished road
Default

Why did you make a poll? This is talkphp.com, does it surprise you that everybody will vote for PHP?

Quote:
I have heard a lot of good things about Python (namspaces,OO, et al). As I am still young is it worthwhile to get acquainted with say, Python?
Yes it is. You should be acquainted with more than one language, or you will forever be a PHPer and will never be able be able to think outside the PHP mindset. I learned Ruby on Rails 2 years ago, and the RoR mindset of thinking has had effect on my PHP code as well - for the better.

That said, Python *is* a good language. The language fundamentals are much more solid than PHP's. PHP is more or less hacked together.

Quote:
Another question, what is this obsession with OOP?
Because it's the only way to write maintainable code in large projects.

Quote:
but, most of the classes that I had come across (at say phpclasses.org) could be implemented with just plain functions.
It's not about doing new things that you were not able to do before. Alan Turing has proven that any turing-equivalent machine can emulate another. PHP, Ruby, Python or whatever, and even C and assembly, are all turing-complete languages. There's nothing that you cannot do in one that you can in another, as far as computational theory is concerned.

OOP is important because it increases code maintainability. Writing hundreds of functions is cute, and it works, but when you look at your code again after a year, you might ask yourself what function is supposed to do what, and how everything is supposed to fit together in the big picture. What if you need to extend your application beyond its original intended purpose? If it consists of a bunch of loose functions, you'll be in maintenance hell.

OOP allows you to model real-world entities in terms of classes. This allows your code to reflect the real world instead of exposing implementation details all over the place. It allows you to split your code into multiple smaller, simple subsystems, rather than lumping everything together in a big spaghetti boil. As someone who has programmed for almost 10 years, I'd have to say OOP is an invaluable tool for any serious developer.
FooBarWidget is offline  
Reply With Quote
The Following User Says Thank You to FooBarWidget For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 12:47 PM   #3 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Just ignore them. Believe me, if you don't stick around and support "your language" even when it's decried, you won't be considered worth helping out. PHP is just fine and dandy, and PHP6 is going to make it much better. At a certain point, when the market requires a change of you, comply---otherwise, commit and stick to your guns.

And I have to say I highly agree with FooBarWidget: branch out and learn other languages. But don't abandon the ones you say are your favorites.


Python is very unfriendly to any version changes, between major versions painfully so. (Big discussion of this at RGRD.)

PHP6 will have full support for namespaces, and by proxy modules. The core is rather compact as it is though most don't distinguish between core functions and add-on extensions that ship with PHP. The naming of all these functions is very disparate though, so the comment on that is quite true. PHP5 is a part of the transition of PHP from a procedural, object orientation hackneyed, language to something with more true object orientation. Multiple inheritance, though powerful, can decrease orthogonality and obfuscate the object's reusability. As to OO file handling ... whee, I wrote my own classes for this in fifteen minutes.

Worse, the whole document is a paragon of arrogance. Comments like this disqualify 98% of their view in my opinion:
Quote:
[Python has]
  • excellent introspection
    • Retort: PHP 5 Reflection
      • Counter-retort: We said excellent introspection
  • lambdas and other builtin functional programming constructs
    • Retort: php.net/create_function
      • Counter-retort: create_function() is a crock; what it produces is not the True Lambda
  • maturity, stability and upward-compatibility
    • Retort: PHP is stable, mature and up/backward-compatible
      • Counter-retort: in general PHP applications must be ported between PHP 4, PHP 5 and future PHP 6 with Unicode
      • Counter-retort: As for maturity... "Age is not an accomplishment"
How nice. The porting required between versions is rather minimal, especially compared to Python. And create_function, while it isn't a "true" lambda, provides the exact same functionality! Whoopie, gonna strangle me some Python-fanatics. The attitude of "our way or the highway", they do claim to have only ONE way to do things, is duly unimpressive.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
The Following User Says Thank You to RobertK For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 01:02 PM   #4 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,042
Thanks: 193
Orc is on a distinguished road
Default

You can embed Python Code in PHP. That is all.
Orc is offline  
Reply With Quote
Old 01-18-2008, 01:02 PM   #5 (permalink)
The Visitor
 
Join Date: Jan 2008
Posts: 2
Thanks: 0
FooBarWidget is on a distinguished road
Default

Quote:
Worse, the whole document is a paragon of arrogance. Comments like this disqualify 98% of their view in my opinion:
But you can't say they are totally wrong, can you?
- I have no experience with PHP introspection so I won't comment on that.

- Lambda function: create_function() *is* a joke. It is essentially a code evaluator. PHP cannot check the syntax during parse time - it performs checking only when the function is created. Furthermore, it makes it hard to bind local variables to the function. In contrast, lambda functions in Python are almost-first-class citizens (I say 'almost' because the Python syntax does not allow one to define multi-line lambda-expressions, but that can be worked around with anonymous function objects instead).
Perl has true support for lambda functions (anonymous subroutines). Ruby has it as well (Proc objects). Heck, even C# has it (anonymous delegates aka closures). PHP's seems to be hacked together.

- Maturity/stability/compatibility: They are right. PHP 4 and 5 changed some pretty large things compared to previous versions, and many apps required porting. So far I've seen less Python programs that break between Python releases than PHP programs that break between PHP releases.


Quote:
You can embed Python Code in PHP. That is all.
Not that that has a lot of practical use.
FooBarWidget is offline  
Reply With Quote
The Following User Says Thank You to FooBarWidget For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 01:13 PM   #6 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

I'm not saying those parts aren't hacked together, they most certainly are! Despite being hacked together, they still retain some usefulness and purpose though. But it's use isn't primarily a lambda anyway, just a callback generated anonymously.

They are right, and they are wrong. I should say the arrogance costs them any respect I had for their view. PHP 4 and 5 changed a good bit, sure. But in the end they were doing us a favor, if only our web hosts would implement the new versions more quickly. I can't claim to have used Python, because I don't use it. But I've seen a good many people complain of its major version breakages, and even minor version breakages. By and large, I don't hear this with PHP nearly so often.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-18-2008, 01:42 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

Speaking from a general point of view, everything in life has its problems because everybody, or supposedly everybody, is different. The best path you can take is to choose yourself a language - in this case you've chosen PHP, and stick with it. Granted it has its problems, I vehemently dislike the create_function function. I think it's truly appalling. I much prefer Javascript's implementation of it - and as Ruby is more like Javascript in its syntactical implementation, I do like Ruby, but I wouldn't take it up as my primary language for the very reason that I could be learning new programming languages constantly in my life - making me a Jack of all languages, master of none.

With that said, PHP 5.3 and PHP 6 really will bring a lot more to the table. However, although they're implementing namespaces amongst other exciting features, they're not fixing their inconsistencies in the function naming. I personally feel PHP should place all the global functions into namespaces, such as String and Math. Can I see that happening? Honestly? No, I can't.

However, I know I will be sticking with PHP, but I won't be sticking with PHP because of any blinkered ignorance, but rather because, although it has flaws and downsides, as other languages inevitably do because of my original point, with well thought out organisation via implementing various design patterns, with a flexible and logical hierarchical directory structure, it really does shine - as does every other language, and thus the conclusion we can reach from this is that it's really down to personal preference.

The lesson to be learnt? Take others opinions on-board, but don't let them hijack and divert you from your own path their discouragement. After all, we all have the ability to make up our own minds and act on those accordingly.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 01:46 PM   #8 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default

Quote:
Originally Posted by FooBarWidget View Post
Why did you make a poll? This is talkphp.com, does it surprise you that everybody will vote for PHP?
Not 'Everyone' voted for PHP, apparently


Quote:
Originally Posted by FooBarWidget View Post
Yes it is. You should be acquainted with more than one language, or you will forever be a PHPer and will never be able be able to think outside the PHP mindset. I learned Ruby on Rails 2 years ago, and the RoR mindset of thinking has had effect on my PHP code as well - for the better.
Are you suggesting that I should get acquainted with ROR?



Quote:
Originally Posted by FooBarWidget View Post
Because it's the only way to write maintainable code in large projects.
I hear that point often being made in favor of OOP, but, a clear example would make it easier for someone like me to be convinced of the necessity of OOP.

Quote:
Originally Posted by RobertK View Post
Worse, the whole document is a paragon of arrogance. Comments like this disqualify 98% of their view in my opinion:
LOL...I agree with u!

What do you guys think of the second article: ???? blog Ruby vs PHP performance
With processor speeds getting better, would you prefer one language over the other (I am referring to interpreted languages), just because it is quicker in processing data?
cosmok is offline  
Reply With Quote
The Following User Says Thank You to cosmok For This Useful Post:
Enfernikus (08-18-2008)
Old 01-18-2008, 01:56 PM   #9 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 440
Thanks: 3
xenon is on a distinguished road
Default

My sincere opinion is that there is no perfect programming language, and most of all, there's not only one single language that "would hold the future". PHP will have a long life from now on in web development, I believe, for the simple fact that it's made for this purpose. Of course, there is also C#, Java and others, but they are not made for "web use only", their creators had other things in mind, too, when creating them (like desktop applications and such). Ruby code looks like junk to me, personally, and their web server (webricks or such) acts like crap when dealing with alot of traffic, from what I've heard. Java is another language that will live many many years from now on, and so is C/C++ (although my preference is Java over C++). So, I'll go for PHP and Java. Oh, and also the markup languages (like HTML, XML) and SQL (ppl will always need databases and internet websites).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 02:01 PM   #10 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

i hated ruby when i first tried it, and i still do loathe it, dont ask y i just hate it.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-18-2008, 02:05 PM   #11 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Coming from a compiled code background, I've always known that PHP has a certain level of inefficiency. In this case it certainly appears that Ruby is the faster, doesn't it? But hey, maybe it's just that spot.

PHP is way more prevalent, and cheap, than RoR so I don't think we're threatened all that much. YET.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-18-2008, 02:08 PM   #12 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 59
Thanks: 10
flyingbuddha is on a distinguished road
Default

Hi cosmok,

I've just joined this site, it looks like it's pretty lively so thought I'd roll with you lot :)

I've been using php since version 3, I think, like yourself, it's a lot of fun, heck' I even use it for a living nowadays.

FooBarWidget kind of said the important stuff but I thought I could expand a little on a couple more points.

Php can be cool and easy to get into, but also difficult at times as there isn't any real standard in the core, more explicitly, function names such as those with underscore separation, and other's without.

There's also a big difference between 4 and 5 if you're an oop programmer, php6 is going further away from 4 as well (and that's the version a LOT of web hosts use on their shared servers), so if you're currently using 4, you're gonna have to do a lot of catching up if you ever want to get into a more recent version of php.

Oop is great, my impression is that oop can be overkill for small sites, but for big sites with/without multiple coders, it's such a useful way of working. Once you've coded your gazillionth site, it gets a bit less fun recoding a page to output news, etc. Code reusability is a core part of the oop mindset. Of course, you make a great point, you could have a script full of your most used functions, but that doesn't scale well. Over time, you'll have functions to do everything, and loading in that whale of a script is going to nail your loading times of a page.

An example of a good use of oop is a database util class. In the first example, you could just have your functions class that connects and queries a mysql db. Great. Now, if you want to connect to a Sqlite / postgre / oracle db, what do you do?
With oop, you could have a factory script, a sort of shell, that can extend one other script of your choosing. You know that you just need to call open_db() (or of that ilk), and whichever type of data storage you have, you'll be getting the same result. Without oop, you'll be writing functions like open_db_mysql(), open_db_postgre(), open_db_sqlite(), and so forth, then if you moved datasource at any time, you'll be recoding all calls throughout the site to the new function. "Portability" is the take-home message ;)

I think from a new person's perspective, oop can seem too overkill because that person looks at framework's such as zend, pear, etc. Those guys pack everything and the kitchen sink into their packages, so from an outsiders perspective who just needs an email validation function (e.g.), oop seems like this unwieldy beast.

As for other languages, I've never come across a problem that I couldn't solve with php, apart from recently! Ever done a file upload with a progress bar in pure php? You can't, it doesn't have the stuff out of the box to do it. You can extend the core with additional dll's/so's, or talk to an outside script such as perl/python using ajax, but out of the box, php can be limiting. That said, with the right extensions, php can solve anything :)
flyingbuddha is offline  
Reply With Quote
The Following User Says Thank You to flyingbuddha For This Useful Post:
cosmok (01-18-2008)
Old 01-18-2008, 02:27 PM   #13 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default

Quote:
Originally Posted by flyingbuddha View Post
I've just joined this site, it looks like it's pretty lively so thought I'd roll with you lot :)
I am glad you did!

Quote:
Originally Posted by flyingbuddha View Post
An example of a good use of oop is a database util class. In the first example, you could just have your functions class that connects and queries a mysql db. Great. Now, if you want to connect to a Sqlite / postgre / oracle db, what do you do?
With oop, you could have a factory script, a sort of shell, that can extend one other script of your choosing. You know that you just need to call open_db() (or of that ilk), and whichever type of data storage you have, you'll be getting the same result. Without oop, you'll be writing functions like open_db_mysql(), open_db_postgre(), open_db_sqlite(), and so forth, then if you moved datasource at any time, you'll be recoding all calls throughout the site to the new function. "Portability" is the take-home message ;)
I am kinda getting your point, but, would you mind showing some code here?that should definitely drive it down my head.
cosmok is offline  
Reply With Quote
Old 01-18-2008, 02:32 PM   #14 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default

Quote:
Originally Posted by RobertK View Post
Coming from a compiled code background, I've always known that PHP has a certain level of inefficiency. In this case it certainly appears that Ruby is the faster, doesn't it? But hey, maybe it's just that spot.
But what about the comparison between PHP, Perl and Python?(PHP is the slowest according to the data provided by the author). Would you prefer one over another for a particular app.
cosmok is offline  
Reply With Quote
Old 01-18-2008, 02:33 PM   #15 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Cosmok, take a look at TlcAndres' database stuff that he's posted; it's the same principle.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-18-2008, 02:35 PM   #16 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Quote:
Originally Posted by cosmok View Post
But what about the comparison between PHP, Perl and Python?(PHP is the slowest according to the data provided by the author). Would you prefer one over another for a particular app.
If you will be mergesorting, yes. Otherwise, no. Every language has a weak point, or a series of them. PHP has its strong points, and just because it is slower, on average, doesn't perturb me.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-18-2008, 02:45 PM   #17 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default

Quote:
Originally Posted by RobertK View Post
If you will be mergesorting, yes. Otherwise, no. Every language has a weak point, or a series of them. PHP has its strong points, and just because it is slower, on average, doesn't perturb me.
fair enough.
cosmok is offline  
Reply With Quote
Old 01-18-2008, 02:45 PM   #18 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

As RobertK said, my DB class script is an example of OOP, I'd recommend looking at the first version since it's easier to read. the second version (last post) is slightly more complicated an abstracted.
TlcAndres is offline  
Reply With Quote
Old 01-18-2008, 02:47 PM   #19 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 59
Thanks: 10
flyingbuddha is on a distinguished road
Default

Quote:
Originally Posted by RobertK View Post
If you will be mergesorting, yes. Otherwise, no. Every language has a weak point, or a series of them. PHP has its strong points, and just because it is slower, on average, doesn't perturb me.
You've got to remember as well that in computational terms, we're normally talking of microseconds to tiny seconds here, people don't generally care about these fractions of time (as long as it's not their first visit to a site), users are more forgiving too if they have actioned the load time, i.e. they've clicked a button somewhere along the line.
flyingbuddha is offline  
Reply With Quote
Old 01-18-2008, 03:09 PM   #20 (permalink)
The Contributor
 
Join Date: Jan 2008
Posts: 25
Thanks: 8
cosmok is on a distinguished road
Default

Quote:
Originally Posted by TlcAndres View Post
As RobertK said, my DB class script is an example of OOP, I'd recommend looking at the first version since it's easier to read. the second version (last post) is slightly more complicated an abstracted.
I will be looking at that, thanks!
cosmok is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


All times are GMT. The time now is 01:35 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design