Live data from Hacker News

Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

news.ycombinator.com

81–89 of 89 posts

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#81
post #9

Earlier quoted context omitted.

How do you relate "broken window theory" with the grammar of PHP?

Broken window theory, as it applies to code essentially says that sloppy code begets sloppy code. PHP itself has sloppy design, such as inconsistent argument order and naming conventions for built-in functions. Most of the complaints I can think of about PHP that are objectively demonstrable are outdated. The language now has namespaces, closures and the like. Most of the complaints I have left have to do with the fe…

And thus Zak withstood the zackattack...

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#82

Earlier quoted context omitted.

I'd have to disagree with you here. In fact, my experience is almost exactly the opposite. Django is incredibly easy to get going, and you can rewrite bits of it as you need to. It's reasonably easy to switch out the templating language if you need to, and I haven't had any problems like you describe with the ORM or admin app. For prototyping apps I wouldn't use anything else. I'm currently running with nginx/FastCGI…

> I basically couldn't populate databases from a unit test, then run a controller, then check the results, since SQLAlchemy would lose the connection after the controller. What you say makes no sense. SQLAlchemy just uses the usual adapter for whatever database you are using. What does "loses the connection" mean to you? SQLAlchemy, by default, uses a pool of connections. I suspect you tried it for an hour and gave u…

I think what he might be referring to is when you run an in-memory SQLite database in your unit tests (which is common practice, for speed and convenience). If the test server runs in a separate thread to the unit test, then they use two separate in-memory databases and you cannot populate the server database from your unit test setUp.

This however does work in Django - presumably by somehow passing the same DB connection to the test server.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#83

I have been writing serious, database backed, large dataset, etc etc web applications using Python for about 4 years. Although it may seem like bragging, I probably know the ins and outs and what-have-yous of the python web programming landscape as well as anyone. State of web programming in python: The frameworks: Django: More powerful? No. Faster, more seductive. In the long run you'll outgrow it, if you are any go…

I'm surprised how much I agree. Werkzeug, Jinja2, and SQLAlchemy are fantastic pieces of software and a great foundation for any web app.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#84
post #14
post #12

From my Quora post on PHP[1]: "PHP is just like every other language: it allows you to write horrible, insecure, stupid code. It also allows you to write clean code." Really, the language doesn't matter. Find people who write good code and give them the tools and atmosphere to do so, and your code will be good. Both are mature languages with plenty of time put into plugins, security, and documentation. Both can obvio…

Really, the language doesn't matter. I disagree. Python, by design, makes it hard to write bad code. PHP, by design, encourages bad code.

Agreed. Even if these two pieces of code might accomplish the same thing, at least the Python version doesn't make me want to stab myself in face whenever I write it:

Invoking an object callback in PHP:

    call_user_func_array(array($object,'method_name'),array($arg1,$arg2,$arg3)); 
Invoking an object callback in Python:

    object.method_name(arg1,arg2,arg3)

    (Python's *args and **kwargs are especially useful in these types of situations.)
Although PHP is slowly adding useful modern language features (lambdas, closures), some of the syntax really is terrible. I honestly can't imagine anyone preferring the former to the latter, at least in this example.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#85
post #38

Earlier quoted context omitted.

BS. Can PHP do this? http://www.joelonsoftware.com/items/2006/08/01.html (In fact the latest version of PHP (5.3) can, but for years PHP has been lacking this, so the point stands.) No amount of "good code design" can work around core features that are missing from a language. The argument that all languages are more or less equal is as nonsensical as saying all cars are more or less equal, or all guns are more or le…

> (In fact the latest version of PHP (5.3) can, but for years PHP has been lacking this, so the point stands.) Actually, it's been able to do that for a LONG time. Pretty sure (99.9% sure here) you could do that in PHP 4, and probably in PHP 3 as well (but really, it's been so long, forgive me for not remembering). Different syntax, of course, but yeah, you could do that. PHP 5.3 essentially just made it more explici…

Well, I guess I'm asking for trouble arguing against a language I have no development experience in.

A quick Google search shows that PHP 5.2 and earlier seem to support something like the anonymous functions required in the example I linked to above -- via the create_function method. But using it in practice appears to be full of ifs, buts and complexities: http://nz.php.net/manual/en/function.create-function.php#706...

But maybe one could get it work if used with care.

If I were ever chained to a desk and forced to work with a PHP framework like Drupal that does not yet support v5.3, I'd look in to this.

Otherwise I'd choose a language that cares more for concepts like readable code and deep modularity.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#86

I have been writing serious, database backed, large dataset, etc etc web applications using Python for about 4 years. Although it may seem like bragging, I probably know the ins and outs and what-have-yous of the python web programming landscape as well as anyone. State of web programming in python: The frameworks: Django: More powerful? No. Faster, more seductive. In the long run you'll outgrow it, if you are any go…

I'm looking into Tornado + MongoDB for a REST API. Many reads, some writes, eventual consistency is fine. Anyone got first-hand experience with that?

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#87

Earlier quoted context omitted.

I'd have to disagree with you here. In fact, my experience is almost exactly the opposite. Django is incredibly easy to get going, and you can rewrite bits of it as you need to. It's reasonably easy to switch out the templating language if you need to, and I haven't had any problems like you describe with the ORM or admin app. For prototyping apps I wouldn't use anything else. I'm currently running with nginx/FastCGI…

> I basically couldn't populate databases from a unit test, then run a controller, then check the results, since SQLAlchemy would lose the connection after the controller. What you say makes no sense. SQLAlchemy just uses the usual adapter for whatever database you are using. What does "loses the connection" mean to you? SQLAlchemy, by default, uses a pool of connections. I suspect you tried it for an hour and gave u…

From memory, committing to the database involves both saving and closing the connection. So when you get back to the unit test, there's no database connection.

Maybe there's a way to do it properly within SQLAlchemy, but if so it's completely non-obvious from a few days of searching the web, Pylons documentation, Pylons book, mailing list, etc.. I wasn't trying to do anything fancy, just set up a very basic unit test.

Here's one of my old comments with some more detail: http://news.ycombinator.com/item?id=1176948 "Instance is not bound to a Session" was the error that I was getting.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#88

Earlier quoted context omitted.

> I basically couldn't populate databases from a unit test, then run a controller, then check the results, since SQLAlchemy would lose the connection after the controller. What you say makes no sense. SQLAlchemy just uses the usual adapter for whatever database you are using. What does "loses the connection" mean to you? SQLAlchemy, by default, uses a pool of connections. I suspect you tried it for an hour and gave u…

From memory, committing to the database involves both saving and closing the connection. So when you get back to the unit test, there's no database connection. Maybe there's a way to do it properly within SQLAlchemy, but if so it's completely non-obvious from a few days of searching the web, Pylons documentation, Pylons book, mailing list, etc.. I wasn't trying to do anything fancy, just set up a very basic unit test…

http://www.sqlalchemy.org/docs/session.html?highlight=expung...

The following is more of a screed than a personal response to your post, so please don't take it personally.

This is something I run into quite a bit more than you might expect. Partly it is because I used to spend a lot of time in #sqlalchemy, #pylons, #pocoo, #python, and #postgresql on freenode (I'm 'ltbarcly' on freenode, feel free to msg me HNers!). For some reason it is common to believe that you can sit down and write applications that use an ORM and relational database without knowing both the ORM and relational databases.

If you are going to use relational databases, you should be prepared to become an expert in SQL, Database drivers, unicode (and why utf-8 or any other encoding isn't the same as unicode, in the same way that jpg or gif isn't the same as image data), indexing, data types, normalization tradeoffs, transaction isolation levels, locking semantics, ACID tradeoffs, how to read and understand query planner output, and much more. This is a lot to know, but if it were a college class it would be less than a semester long.

If you are going to use an ORM you have to know everything you would need when you use a relational database, and in addition how and when the ORM performs queries, how it maps to the database, what queries it will produce and when for any given action or attribute access, how db transactions map into the orm operations, how to perform common SQL operations via the orm (rather than loading more data than you need and filtering or joining via the application).

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#89

I'm happy that I'm developing my web apps with Python. I have used almost all Python web frameworks out there. So let me explain my experience. Django - Until 1.2 Django was a total headache but with 1.2 it really is a great tool to develop web applications. No reason not to use it unless you feel something's missing. Django has an amazing community with very helpful people. web2py - web2py lets you create apps very…

"however i am not using werkzeug anymore as i don't like the way people act in #pocoo on freenode. this is the only reason i am not using werkzeug. they are ignorant and i don't like it." Would be nice to know if this is a general thing or if we did something in particular wrong. Because if that is what you remember of this channel we should really improve our behaviour then. So it would be nice if you could elaborat…

i'm sorry, it's my wrong choice of word. it's not ignorant but smart ass. i don't like that. nobody is pushing anyone for answering questions. if you don't feel like you're doing something you're happy with, then don't do it. i'm also sorry for making a generalization as i know some people on pocoo very helpful and friendly. i remember you, and daslch answering my questions that way.

and let me note that werkzeug is a framework that i'd like to see at the top and people know its value.

Post reply on HN