hq12
12-29-2009, 10:02 PM
Hey guys, for quite some time I have been learning php/mysql. Although, I know the basics of it; I was wondering if I should change to python given that it seems that it is being used more widely. what do you think?
![]() | View Full Version : php vs. python hq12 12-29-2009, 10:02 PM Hey guys, for quite some time I have been learning php/mysql. Although, I know the basics of it; I was wondering if I should change to python given that it seems that it is being used more widely. what do you think? Crothers 12-29-2009, 10:39 PM I made the switch to Python a while ago, I would consider my PHP comprehension to be between extremely high and mastered. When I switched to Python it literally took me weeks to get the syntax right when I'm punching through code. However I feel that I'm a better developer because of this change. Python is a far more capable language than PHP can ever hope to be in my opinion. tl;dr: Python is a big switch, its far more powerful. You'll thank yourself for learning Python. However it will take longer to learn the syntax and learn to properly read the manual then it did to learn PHP. jjk2 12-29-2009, 11:40 PM what do you want to achieve ? python is more powerful but relatively more difficult to learn than php. if you are just building frontend web properties, php is good enough. of course you can do it in python but why ? always choose the path of lowest resistance. mwatkins 12-29-2009, 11:57 PM Python the language is actually quite small and concise. Learning the language generally doesn't take all that long; learning the standard library (of any language) is usually where you spend more time in the long run. PHP is a web-focussed language; Python is a general purpose language which happens to have quite a few well-supported web framework communities. In order to compare web development in PHP vs same in Python you'll need to select one or more Python web frameworks - try out their tutorials - and see which fits your brain best. Perhaps one of them will appeal to you more than PHP, perhaps not. If you have control over the execution environment (web hosting) for your web apps, I'd have no hesitation in recommending you have a close look at Python - perhaps check out Django or TurboGears2 web frameworks - each has a simple tutorial that will get you going. These frameworks usually deliver quite a bit more than a templating system - often you get a testing environment, boilerplate code generation (a project skeleton quick start), some helpful separation of logic, models and views, a library of web app "helpers" and such. Of course you can get the same from a PHP framework as well. I would disagree with comments that suggest Python is somehow harder than PHP; in my experience it is quite the opposite - doing hard things is easier in Python and often far less verbose. I often post code snippets here showing just that. What is harder, especially for those who have only experienced the PHP style of code in HTML development it makes so easy, is choosing a web app execution environment. You get that for free in PHP, and virtually all web hosts support default PHP web app hosting (whether it is secure or not is another matter depending on the host). For Python and other general purpose languages, the interface between web server and app needs to be put in place. Run of the mill web hosts rarely have a good solution for this. Better hosts do. addcomex 12-30-2009, 05:35 AM The difference between PHP and Python Posting in the full realization of the futility of doing so, there’s some PHP bashing (as usual) happening on reddit at the moment: PHP vs Python – the real difference, brought on by this mildly amusing image. While I can accept the points – technically it’s actually much harder in handle errors uniformly in PHP and the community is less rich in computer scientists than Python – the corresponding flame war on reddit manages to miss a different point, which is easiest expressed in code. What’s the most significant difference between these two scripts? 1 <?php 2 $hits = 0; 3 printf ("Hits: %s\n", $hits); 4 $hits++; view plain | print <?php $hits = 0; printf ("Hits: %s\n", $hits); $hits++; And a web.py controller (absolutely no criticism intended – picked it because I like it – discussion applies to pretty much anything non-CGI and, in fact, this is really nothing specific to Python either)… 1 #!/usr/bin/env python 2 import web 3 4 urls = ( '/.*', 'counter' ) 5 hits = 0 6 7 class counter: 8 def GET(self): 9 global hits 10 print "hits %s" % hits 11 hits += 1 12 13 if __name__ == "__main__": web.run(urls, globals()) view plain | print #!/usr/bin/env python import web urls = ( '/.*', 'counter' ) hits = 0 class counter: def GET(self): global hits print "hits %s" % hits hits += 1 if __name__ == "__main__": web.run(urls, globals()) Depending on how you deploy the latter (i.e. not as a CGI), it will actually count – i.e. state can persist between requests. While that enables this feature, it’s also a potential source for very-painful-shooting-of-self-in-foot. There’s heavy feeling in the gut when you start wondering whether weak references might help fix memory leaks somewhere in your large code base. That curry may have tasted good but wait until the morning after… Remember those JScript memory leaks – do you really want the same fun server-side? “But yes of course Sir. Of course you’re smarter than that. No, one singleton can’t hurt can it? You’d never make that silly mistake. No never. Not even on your dullest of days” ;) How does this relate to errors and this image? Because PHP “resets” after each request ( see here or for much more detail here ) it’s actually not always necessary to handle errors explicitly – assuming there’s not something fundamentally “broke” about your code and it’s some kind of runtime error (e.g. db is down), it’s often enough to just ignore the problem and wait for the system to “right itself” – nothing is going to leave PHP in a state it can’t recover from. It’s a rationale that Damien Katz does so much better in Error codes or Exceptions? Why is Reliable Software so Hard? – read it – read it all. Anyway – apologies to Python / web.py again – just following the reddit thread – could equally have been Rails, Catalyst or otherwise. <<signatures to be set up in your profile>> hq12 12-30-2009, 10:27 PM Hey guys thank you very much for the advice. I appreciate it! for those who have experience both langugages, do not hesitate to comment! ;) Simfan147 12-31-2009, 11:26 AM I know Python for simple scripting. I tried using Django. A couple things stopped. You have to use a Linux or Mac OS to develop it. You cannot do it on a Windows machine. Configuring URLs was a pain so I just quit it and went back to ASP.NET. I would go with PHP. FreeKill 12-31-2009, 02:35 PM I've used both quite a bit. In 99.99999% of cases, choosing a language is pure preference. Most people aren't pushing languages to the maximum, so deciding on whether to use PHP or Python really comes down to which one you prefer. The only caveat I would point out is that if you choose Python, it is much less broadly adopted by web hosting providers, so your choices are more limited in where you can host your site or move your site to down the road... |