This is a discussion on Python as replacement for PHP? within the PHP Language forums, part of the PHP Programming Forums category; In article <403fa54b@news.zianet.com>, Erik Johnson <ej.at.wellkeeper@dot.com> wrote:...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
>>>>> "Simon" == simo <simoninusa2001@yahoo.co.uk> writes:
Simon> Here's how I see it (I'm a Web Developer by trade): PHP - Simon> excellent database integration, if you don't want to have Simon> to use a Java application server for database work, go with Simon> PHP. Also nice templating system which even the Dreamweaver So, how do Python's DB modules fall short of those of PHP? If they indeed do, what should module developers do to fix this gap? I'm so very tired of the argument that because language X specializes in doing Q, it must be better than language Y (which is not specialized for any particular task) for doing Q: "Perl is only good for doing regexps, therefore it must be better than Python for doing regexps" "PHP is only good for doing DB connectivity /Web templating, therefore it must be better than Python for doing them" That just isn't logical. Simon> Perl - bloody fast, if you're doing lots of text Simon> processing/regex (e.g. XML parsing) then Perl is it, Simon> probably best for sysadmin tasks too. We use this for large This is another argument I can't understand. If perl crunches your log file in 3 minutes and Python takes 4 (but the script remains readable and maintainable), Python would still be my choice. And regexps for XML parsing don't always work anyway. Simon> The moral of the story is don't get locked into one Simon> technology, use the best tools for the job - especially if Simon> you happen to know them all! ;o) Often Python is the best tool for all the jobs there is to do. People just fail to see that because, driven by prejudice, they opt for the tool that can *only* do whatever the job is at the moment. That might have been sensible 15 years ago, but the software landscape has changed since. -- Ville Vainio http://tinyurl.com/2prnb |
|
|||
|
Bart Nessux wrote:
> Erik Johnson wrote: > >> This is somewhat a NEWBIE question... >> >> My company maintains a small RDBS driven website. We currently >> generate >> HTML using PHP. I've hacked a bit in Python, and generally think it is a >> rather cool language. I've done Perl and like it, there are a few >> features >> of PHP I like but overall am not too excited about it. (snip) >> To those that have used PHP: what am I potentially >> losing >> that Python really can't replace? >> >> So, I'm hoping there are some people out there that actually have >> some >> expereience with both Python & PHP and can give me some solid, informed >> advice about PHP vs. Python, in general and particularly on the following >> points: (snip) > > When it comes to dynamic, DB driven sites, PHP is the only way to go. > Python is not even close to being suited for this task. (snip) > A serious business decision? PHP would be the only winner here. You > should not even be considering another language for this, it borders on > stupidity. (snip) Bart, could you please back your (strong) assertions with at least one argument ? AFAIK, there is a whole lot of python tools for web developpement, and I don't really see any evidence that one of the two languages is more or less suited to this kind of task. The only points I see in favor of PHP are : - it's a de facto standard, widely used, widely available, and well established - there may be some specific libs not (currently) available in Python. Bruno |
|
|||
|
> Bart, could you please back your (strong) assertions with at least one
> argument ? > > AFAIK, there is a whole lot of python tools for web developpement The OP was comparing Python to PHP, not ZOPE to PHP. PHP by itself is a natural Web programming language, Python is not. Google for dynamic DB driven programming tools... how may PHP returns vs Python returns are there? > The only points I see in favor of PHP are : > - it's a de facto standard, widely used, widely available, and well > established That's exactly right. That's my point. I meant nothing more. |
|
|||
|
Erik Johnson wrote:
> CAUTION: I'm replying as a non-Python programmer. > 1) I think Python is cool. > 2) We can do system administration type scripts (currently > implemented in Perl), web page generation (PHP), and (potentially) > client-side applications (including GUI's that make socket and/or external > HTTP requests) in one language. You can do client-side apps in PHP too. Pass the -q option to the CGI version or just use the CLI version. GUI - PHP-GTK Sockets - The socket extension or fsockopen() to treat it as a regular file. > 3) Python's interactive interpreter makes it easy to try things out. ? Like the -r option? > 4) PyUnit - we would like to develop a robust set of tests and be > able to do regression testing. I'm not aware of a JUnit/PyUnit analog in > PHP. Are you? > 5) Python has better code support for complex native data types > (e.g., tuples, dictionaries, sequences, etc. and being able to write these > directly in a hierarchical structure rather than building them up piecewise > with function calls and assignments as in PHP). In PHP, all these things are essentially arrays and that works fine. Even the PHP developers say that classes are just syntactic sugar for associative arrays (that'll change in PHP 5, though). So PHP is procedural; there's nothing wrong with that. > Not to sound like I hate everything which isn't PHP. It's just that PHP does have a wide range of functionality and is moving toward command-line/administration capabilities, and is quite easy to learn if you know other C-like languages. But if you think that Python better serves your purpose, then you should use it. Surely, it would be possible to write a strtotime() implementation in Python; someone may have already done so. |
|
|||
|
In article <du7n073muvy.fsf@amadeus.cc.tut.fi>,
Ville Vainio <ville@spammers.com> wrote: > > Often Python is the best tool for all the jobs there is to do. People > just fail to see that because, driven by prejudice, they opt for the > tool that can *only* do whatever the job is at the moment. That might > have been sensible 15 years ago, but the software landscape has > changed since. > and will change again before you're ready :-( Use whatever you are happy with that does the job, just do it so well that the next guy in your position isn't tempted to rewrite it in his favorite language... |
|
|||
|
CountScubula schrieb:
> You also need to look at what each language was desgined for, sure I can > write a dynamic web page in bash or korn, but why? Perl was written to do > large extraction and reporting of text files, Python was written as a server > language I don't think so. It seems Python was written as a rapid development language without a specific application range. That's an advantage because you can get a lot of different jobs done very well. That's a disadvantage because there's no no-brainer like "Python is for ...". A family of marketing phrases comes into mind: - Python is NOT for device drivers. - Writing a device driver? Beware of Python! - OS kernels? Don't even think of Python! .... :) Mit freundlichen Gruessen, Peter Maas -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24 Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas@mplusr.de ------------------------------------------------------------------- |
|
|||
|
Bart Nessux <bart_nessux@hotmail.com> wrote...
> When it comes to dynamic, DB driven sites, PHP is the only way to go. > Python is not even close to being suited for this task. PHP claims to be > a general-purpose language, but I do not know anyone who uses it for > anything other than dynamic Web programming. Like everyone else who has replied, I seriously question how much experience you have with the multitude of Python web environments available. As an objective, point-by-point look at your specific example of somewhere PHP is strong, here's my reply: [PS: I still use PHP regularly, albeit only for quick unimportant hacks that won't exist in 6 months] - Nearly all the PHP code I have seen (including various large web sites) fails to handle error conditions, and will run amok given a down DB server, bad filesystem permissions, or bad inputs. I have had personal experience, on more than one occasion, of an error condition in someone else's PHP code causing a large amount of damage to a dataset. - The equivalent Python code will almost never do that. Thanks to the religious throwing of exceptions, well written standard libraries, DB adaptors, and so on, the worst Python code has a MUCH better chance of getting stopped in it's tracks just as a fault occurs. py> open("/tmp/foo","w").write(123) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not int [22:15:14] [cape:4:dw]$ php4 <<e > <? fwrite(fopen('foo','w'), 123); ?> > e [22:15:16] [cape:5:dw]$ cat /tmp/foo [22:15:17] [cape:6:dw]$ Can you tell me exactly what the PHP fwrite function did when I passed it an integer? Can you tell me how many PHP programmers test "(strlen($to_write) == fwrite($fp, $to_write))"? - In the specific instance of database connectivity, Python is far superior, in terms of intuitiveness, security, safety, and so on. Python database APIs are built in a way that protects you by default. - PHP provides no intuitive default support for many common DB operations. Compare the following messes: py> l = MySQLdb.connect() py> c = l.cursor() py> user_input = "%t%" py> match_count = c.execute("SHOW DATABASES LIKE %s", ( user_input )) py> print match_count, "matches:", [ x for x, in c ] 1 matches: ['test'] <? $s = mysql_connect(); $user_input = "%t%"; $query_sql = sprintf("SHOW DATABASES LIKE \"%s\"", mysql_real_escape_string($user_input, $s)); $query = mysql_query($query_sql, $s); $matches = array(); while ($row = mysql_fetch_array($query, MYSQL_NUM)) $matches[]= $row[0]; echo sizeof($matches), " matches: ", var_export($matches, true); Tell me, of these two popular examples of bad code in both languages, which is the more intuitive to read, which is the more elegant to keep secure, and which would you prefer to be reading, and modifying in 18 months time? [In this case, which was the quicker to create? The Python example. The PHP counterpart has a syntax error somewhere, I care not where.] How many different ways can you dream up the same functionality in the PHP example? (mysql_escape_string, <random_db_api>, etc.) How likely is it that the developer you hire to take over development of either snippet of code will understand the concept behind it? I can't even think of another way of doing database query in Python, without using the low-level interfaces, which is just insane. We could bring the PHP ADODB, or many of the other numerous PHP APIs for DB connectivity into the picture, but which of these are the obvious choice, and officially endorsed? How easy is it to improve on both these examples to add proper error handling? Again, Python wins hands down for elegance, conciseness, and obviousness. - Python has a religious following of thousands, many of whom found freedom through it's restraint, unified path, and downright beauty. The result is a long tradition of structured, well written code. Python has roots in academia, and started life with a defined purpose, and a BDFL who knew what he was doing. - PHP, "the web designer's ideal first language", started out life as "a collection of perl scripts" (that says it all really), then ported to C, then hacked and added to until it was the great swiss army monolith that it is today. PHP has never had a clear, publically documented development path, or indeed any form of structure or organisation, past the menu system of PHP.net PHP developers tend to have started life using Dreamweaver, happy to accept the first solution to a problem that comes their way, and care little about technical merit. Every person (including at the time, myself) who I know that uses, or used PHP, did so because it allowed them to make things look beautiful and dynamic very quickly. - Python gurus, when asked how to make something work, will often appear nasty and horrible, telling you you're doing entirely the wrong thing and you should go back to the drawing board. Much like the hot sting from a smack of a father's hand, this is good, not bad. It is there to direct and discipline you, and improve the way you think. - PHP gurus tend to be experienced web developers, they'll be able to look flash and give you an answer on the spot, but that answer will only further lead to the demise of any structure your coding ever had. - Python tends to be slow, but slow compared to what? The laptop I type this message on has a 2ghz processor. It cost less than £1000. It is the cheapest laptop money can buy in the UK. I run Python scripts on multi-gigabyte datasets on a daily basis on this machine. I have never considered the scripts to be 'slow'. - PHP is very light on CPU, memory, and so on. I earn a modest amount for a 20 year old, even by Northern Ireland standards. I can't see how I would ever need to resort to PHP because I couldn't afford the hardware to run a complex Python-based site intended for viewing by thousands. Personally, I find the average PHP codebase to be akin to a television station such as MTV: well presented, streamlined, professional looking, but in terms of content, nothing but meaningless, mindless shite. On the other hand, reading certain Python code is more like reading a beautifully typeset hardback novel: black and white - ugly to some, but functional, educational, structured, meaningful, etc, etc. What interests you more - earning money through thoughtless, effortlessly produced rant-syntax that no-one will ever want to look at again, or the daily challenge to produce something that will perfectly fulfill it's intended function, at the cost of a little time, a little brainpower, and a little discipline. I could go on, but I think these points alone are the main reasons I use Python. At the cost only of speed, it protects me, teaches me, profits me, and inspires me to continue being the professional geek that I am. :) David. |
|
|||
|
"David M. Wilson" <dw-google.com@botanicus.net> wrote in message
news:99dce321.0403031518.56f61c7c@posting.google.c om... > Bart Nessux <bart_nessux@hotmail.com> wrote... > > > When it comes to dynamic, DB driven sites, PHP is the only way to go. > > Python is not even close to being suited for this task. PHP claims to be > > a general-purpose language, but I do not know anyone who uses it for > > anything other than dynamic Web programming. > > Like everyone else who has replied, I seriously question how much > experience you have with the multitude of Python web environments > available. As an objective, point-by-point look at your specific > example of somewhere PHP is strong, here's my reply: > > [PS: I still use PHP regularly, albeit only for quick unimportant > hacks that won't exist in 6 months] < a lot of brilliant points snipped /> ROFLMAO! Wohoo! Thisone is going to draw some heat, David! (Not that I don't agree with you, though... Python is probably the most beautiful scripting language I've ever used). -- Dag. |
|
|||
|
[Well, this time I have decided to troll -- all because of prolong
irritating ignorant posts/crossposts. And, this is intentional crosspost.] dw-google.com@botanicus.net (David M. Wilson) wrote in message news:<99dce321.0403031518.56f61c7c@posting.google. com>... > Bart Nessux <bart_nessux@hotmail.com> wrote... > > > When it comes to dynamic, DB driven sites, PHP is the only way to go. > > Python is not even close to being suited for this task. PHP claims to be > > a general-purpose language, but I do not know anyone who uses it for > > anything other than dynamic Web programming. > > Like everyone else who has replied, I seriously question how much > experience you have with the multitude of Python web environments > available. As an objective, point-by-point look at your specific > example of somewhere PHP is strong, here's my reply: > > [PS: I still use PHP regularly, albeit only for quick unimportant > hacks that won't exist in 6 months] So.. you don't have any important works :-/ > - Nearly all the PHP code I have seen (including various large web > sites) fails to handle error conditions, and will run amok given a > down DB server, bad filesystem permissions, or bad inputs. I have had > personal experience, on more than one occasion, of an error condition > in someone else's PHP code causing a large amount of damage to a > dataset. Good news. Well done PHP! > - The equivalent Python code will almost never do that. Thanks to the > religious throwing of exceptions, well written standard libraries, DB > adaptors, and so on, the worst Python code has a MUCH better chance of > getting stopped in it's tracks just as a fault occurs. > > py> open("/tmp/foo","w").write(123) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: argument 1 must be string or read-only character buffer, > not int > > > [22:15:14] [cape:4:dw]$ php4 <<e > > <? fwrite(fopen('foo','w'), 123); ?> > > e > [22:15:16] [cape:5:dw]$ cat /tmp/foo > [22:15:17] [cape:6:dw]$ > > Can you tell me exactly what the PHP fwrite function did when I passed > it an integer? Can you tell me how many PHP programmers test > "(strlen($to_write) == fwrite($fp, $to_write))"? Ok...understand. idiot-proof? > - In the specific instance of database connectivity, Python is far > superior, in terms of intuitiveness, security, safety, and so on. > Python database APIs are built in a way that protects you by default. Perhaps, idiots' own language? > - PHP provides no intuitive default support for many common DB > operations. Compare the following messes: > > py> l = MySQLdb.connect() > py> c = l.cursor() > py> user_input = "%t%" > py> match_count = c.execute("SHOW DATABASES LIKE %s", ( user_input > )) > py> print match_count, "matches:", [ x for x, in c ] > 1 matches: ['test'] > > > <? $s = mysql_connect(); > $user_input = "%t%"; > $query_sql = sprintf("SHOW DATABASES LIKE \"%s\"", > mysql_real_escape_string($user_input, $s)); > $query = mysql_query($query_sql, $s); > $matches = array(); > while ($row = mysql_fetch_array($query, MYSQL_NUM)) $matches[]= > $row[0]; > echo sizeof($matches), " matches: ", var_export($matches, true); > > > Tell me, of these two popular examples of bad code in both languages, > which is the more intuitive to read, which is the more elegant to keep > secure, and which would you prefer to be reading, and modifying in 18 > months time? [In this case, which was the quicker to create? The > Python example. The PHP counterpart has a syntax error somewhere, I > care not where.] > > How many different ways can you dream up the same functionality in the > PHP example? (mysql_escape_string, <random_db_api>, etc.) > > How likely is it that the developer you hire to take over development > of either snippet of code will understand the concept behind it? I > can't even think of another way of doing database query in Python, > without using the low-level interfaces, which is just insane. > > We could bring the PHP ADODB, or many of the other numerous PHP APIs > for DB connectivity into the picture, but which of these are the > obvious choice, and officially endorsed? > > How easy is it to improve on both these examples to add proper error > handling? Again, Python wins hands down for elegance, conciseness, and > obviousness. Yes, agreed. Idiots' language. > - Python has a religious following of thousands, many of whom found > freedom through it's restraint, unified path, and downright beauty. > The result is a long tradition of structured, well written code. > Python has roots in academia, and started life with a defined purpose, > and a BDFL who knew what he was doing. > > - PHP, "the web designer's ideal first language", started out life as > "a collection of perl scripts" (that says it all really), then ported > to C, then hacked and added to until it was the great swiss army > monolith that it is today. PHP has never had a clear, publically > documented development path, or indeed any form of structure or > organisation, past the menu system of PHP.net LOL! Joke of the millennium. > PHP developers tend to have started life using Dreamweaver, happy to > accept the first solution to a problem that comes their way, and care > little about technical merit. Every person (including at the time, > myself) who I know that uses, or used PHP, did so because it allowed > them to make things look beautiful and dynamic very quickly. Yet another good joke. > - Python gurus, when asked how to make something work, will often > appear nasty and horrible, telling you you're doing entirely the wrong > thing and you should go back to the drawing board. Much like the hot > sting from a smack of a father's hand, this is good, not bad. It is > there to direct and discipline you, and improve the way you think. > > - PHP gurus tend to be experienced web developers, they'll be able to > look flash and give you an answer on the spot, but that answer will > only further lead to the demise of any structure your coding ever had. Huh?? > - Python tends to be slow, but slow compared to what? The laptop I > type this message on has a 2ghz processor. It cost less than £1000. It > is the cheapest laptop money can buy in the UK. I run Python scripts > on multi-gigabyte datasets on a daily basis on this machine. I have > never considered the scripts to be 'slow'. > > - PHP is very light on CPU, memory, and so on. I earn a modest amount > for a 20 year old, even by Northern Ireland standards. I can't see how > I would ever need to resort to PHP because I couldn't afford the > hardware to run a complex Python-based site intended for viewing by > thousands. > > > Personally, I find the average PHP codebase to be akin to a television > station such as MTV: well presented, streamlined, professional > looking, but in terms of content, nothing but meaningless, mindless > shite. On the other hand, reading certain Python code is more like > reading a beautifully typeset hardback novel: black and white - ugly > to some, but functional, educational, structured, meaningful, etc, > etc. > > What interests you more - earning money through thoughtless, > effortlessly produced rant-syntax that no-one will ever want to look > at again, or the daily challenge to produce something that will > perfectly fulfill it's intended function, at the cost of a little > time, a little brainpower, and a little discipline. > > I could go on, but I think these points alone are the main reasons I > use Python. At the cost only of speed, it protects me, teaches me, > profits me, and inspires me to continue being the professional geek > that I am. :) comp.lang.php is not the right place for you to show your stupidity. You should consider stripping headers as many other PHP ignorants (<http://groups.google.com/groups?threadm=403fa54b%40news.zianet.com>) did before throwing your thoughts. HTH. HAND. -- From comp.lang.php "Success is not what you achieve, but it is what you die for" If you live in USA, please support John Edwards. Email: rrjanbiah-at-Y!com |