Live data from Hacker News

I only know PHP. How do I write a Web application in Python?

me.veekun.com

141–150 of 196 posts

Re: I only know PHP. How do I write a Web application in Python?

#141

Personally, I _like_ PHP because, at the core, it is a collection of utility functions to write webapps quickly. Here's a small set of those function that I would like to see somewhere else (like in Python for example): Save a file: file_put_contents() Load a file: file_get_contents() Trim whitespace: trim() Print a string (even numbers!): print $str Dump an array: print_r() Print the stack trace: print $e->getTraceA…

> Personally, I _like_ PHP because, at the core, it is a collection of utility functions to write webapps quickly. Here's a small set of those function that I would like to see somewhere else (like in Python for example):

As another commenter has already posted, these are pretty trivial in Ruby and Python(and plenty of other languages).

> Want to check for errors and improve the quality of the code? Go ahead! Use lower level functions like fwrite, fread, etc;

fwrite/fread improve quality of code? As opposed to what?

> The icing on the cake is that a huge part of the built-in functions wrap and extend existing C functions: strpos, strlen, so the language rarely gets in your way.

I don't see how your conclusion follows from your premise. How does a language using strlen equate to not getting in my way?

> from my experience, people who bash a language rarely know what they're talking about and it usually just boils down to personal preferences like braces vs no-braces.

None of the languages are perfect. Though a lot of people bash languages without knowing their shit, it doesn't mean all criticism is invalid. PHP has warts - warts that go beyond personal preferences.

Re: I only know PHP. How do I write a Web application in Python?

#142
post #126

Earlier quoted context omitted.

Let's look at the PHP version: Hello World! One line. I didn't have to worry about Linux/Windows, knowing HTTP headers or the fact that I need two CRLFs after the last header[1]. I just wanted a page that says "Hello World!" and that's what I got. Don't get me wrong, I would never choose to write a web app in PHP over python. But it is brain dead simple to go from nothing to something in a few keystrokes. Which is pr…

In the context of the parent comment I'd argue that the differences are insignificant. Xuzz argued that PHP is simpler because you don't need to know the ecosystem. Which I countered by showing a basic example of Python which doesn't depend on the ecosystem (like frameworks, package managers or version control). Besides that, I don't think knowing HTTP headers or understanding significance of trailing newlines is req…

But I never needed to worry about those three lines in PHP, to a new user that is important. To you and I they come naturally.

PHP "is especially suited for Web development and can be embedded into HTML" [1]. Python "lets you work more quickly and integrate your systems more effectively" [2]. They can both do the task of the other, but the upstart time for a developer to handle the task of making a web app is smaller for PHP.

I've never taken the non-framework approach with python for anything significant, but how does it handle cookies, GET and POST fields, sessions, and file uploads? In PHP you'd have $_COOKIE, $_GET, $_POST, $_SESSION, and $_FILES as built-in global variables.

Are these differences still insignificant?

[1] http://php.net/ [2] http://python.org/

Re: I only know PHP. How do I write a Web application in Python?

#143
post #123

Earlier quoted context omitted.

There is a language called 'Java' where every string is in unicode, and I do not remember ever running into an issue!

Except that Java strings aren't in Unicode. They're in UTF-16, which is the worst-of-all-worlds encoding. (It's big and heavy, and it still has multibyte sequences. They're just rare enough that you're likely to forget about them during testing.)

UTF-16 is most certainly Unicode, even if it isn't the preferred flavor.

Re: I only know PHP. How do I write a Web application in Python?

#144
post #83
post #61

Earlier quoted context omitted.

I wanted to do that now but did some lego with my kid instead, will keep you 3 informed when done.

It seems an article on Ars Technica has already compiled some defect of MySQL: http://arstechnica.com/civis/viewtopic.php?f=20&t=92525 Another thing that reminds of PHP, the list of commands: mysql mysql_client_test_embedded mysql_find_rows mysqlrepair mysql_tzinfo_to_sql mysqlaccess mysql_config mysql_fix_extensions mysqlreport mysql_upgrade mysqladmin mysql_convert_table_format mysql_fix_privilege_tables mysql_secu…

In case anybody was wondering: mysqldumpslow is for dumping MySQL's slow query log.

Re: I only know PHP. How do I write a Web application in Python?

#145
post #128

Earlier quoted context omitted.

I'm not sure I really get what you are trying to say. I know what a transaction is, and I know it wasn't the fault of transactions. It was the fault of our poor use of transactions, in the same monolithic transaction pattern that the OP appears to be advocating.

transaction-per-request is by far the best default pattern to use. If some particular methods have special needs, like needing to break up the operations into multiple transactions to deal with third-party communication, those are the exceptions. The alternatives to transaction-per-request are autocommit, or explicit transactions required at all times. Autocommit is a terrible choice because now you've lost all atomi…

Why not the third (and in my experience most common) alternative? Autocommit but if you explicitly start a transaction then automcommit is turned off until that transaction has been committed.

Re: I only know PHP. How do I write a Web application in Python?

#146
post #134

Earlier quoted context omitted.

In Ruby: # Save a file f.write(str) # Read a file f.read # Trim whitespace " foo ".strip # Print anything puts 1 # even numbers! puts File.open("foo", "w+") # even file handles! puts [1, 2, 3, 4] # even arrays! puts [].class # even classes! puts [].method(:size) # even functions! # Dump an array (see above) Python is similarly clear: # Save a file f.write(str) # Read a file f.read() # Trim whitespace " foo ".strip()…

Not sure about the Python ones, but the Ruby read/write file examples aren't quite fully done/correct here: # Equivalent of file_put_contents() in PHP # This could also be used for appending if the correct mode is specified. File.open("filename", "w") { |f| f.write("some data") } # Equivalent of file_get_contents() in PHP some_var = File.read("filename")

Ruby 1.9.3 added File.write("filename", "some data").

Re: I only know PHP. How do I write a Web application in Python?

#147
post #143

Earlier quoted context omitted.

Except that Java strings aren't in Unicode. They're in UTF-16, which is the worst-of-all-worlds encoding. (It's big and heavy, and it still has multibyte sequences. They're just rare enough that you're likely to forget about them during testing.)

UTF-16 is most certainly Unicode, even if it isn't the preferred flavor.

"UCS-2 (2-byte Universal Character Set) is a character encoding that was superseded by UTF-16 in version 2.0 of the Unicode standard in July 1996". Java adopted UCS-2 which was later supplemented with UTF-16 support.

There are at least a few languages in this world which do not use roman letters and are better represented as multibyte sequences :). That is why Java added support for supplementary UTF-16 characters over and above UCS-2. That said, use of UTF-8 would have been optimal for western languages, but sub optimal for several other languages.

Re: I only know PHP. How do I write a Web application in Python?

#148
Great article! For those of you who say how easy PHP is, it's because you don't remember the early days when you had to compile php to run on your box, only to watch it fail after an hour of compilation :) history aside, these are just tools. For many site, perhaps for majority of tasks, PHP might be the best tool for the job. Once you start doing more complex stuff that will require additional libraries and modules then you need to look into other languages.

I used servlets from very early days, just because I could never understand another man's perl code and I thought the architecture was better. However J2EE got so big and academic that took all the fun out of coding. I've recently started to do some stuff in python and the fun is back again. I love all the NLP libs that are available for python in addition to vast support and ease of coding. Not to mention, I like the python community more than ruby (rails really). It just seems like python guys come from a stronger CS background and are not some over-night rail guys who want to push their faith down your throat.

Re: I only know PHP. How do I write a Web application in Python?

#149
Great article! For those of you who say how easy PHP is, it's because you don't remember the early days when you had to compile php to run on your box, only to watch it fail after an hour of compilation :) history aside, these are just tools. For many site, perhaps for majority of tasks, PHP might be the best tool for the job. Once you start doing more complex stuff that will require additional libraries and modules then you need to look into other languages.

I used servlets from very early days, just because I could never understand another man's perl code and I thought the architecture was better. However J2EE got so big and academic that took all the fun out of coding. I've recently started to do some stuff in python and the fun is back again. I love all the NLP libs that are available for python in addition to vast support and ease of coding. Not to mention, I like the python community more than ruby (rails really). It just seems like python guys come from a stronger CS background and are not some over-night rail guys who want to push their faith down your throat.

Re: I only know PHP. How do I write a Web application in Python?

#150
post #55

Earlier quoted context omitted.

What frameworks and platforms would you recommend for web development with java? I am writing my senior project at college in java (mainly because of the wide amount of image processing libraries available) and would love to add web capabilities.

Wicket, a thousand times wicket. It's so good it makes programming in java worthwhile. Its templating, if you can even call it that, is a quantum leap ahead of everything else: it's actually object oriented, you can write self-contained reusable components in the way you expect, and you get the full benefits of strong typing at every point. I really wish there was something like it for python, but everyone seems to t…

What about something like Flask-HTMLBuilder?

http://majorz.github.com/flask-htmlbuilder/

Post reply on HN