News for hackers. Stuff that matters.
Re:Python alternatives for PHP functions by dsl on Tuesday December 25, 2012 @02:21AM (#4965379)
As someone who doesn't know much in the way of Python, it seems odd to me that many of the examples are blocks of code vs one line replacements for PHP functions. Is Python just more verbose?
Re:Python alternatives for PHP functions by nikcub on Tuesday December 25, 2012 @04:38AM (#4965607)
I know both languages well. Python is much more succinct than PHP because of array literals, list comprehensions, lambda's and better native data types with ways to navigate them (all the functional methods are there). Only PHP 5.4 with a literal array syntax is beginning to approach some of the things you can do in Python.

You think PHP is short because you have functions like xmlrpc_encode_request and the equivalent in Python is 20 lines. What you don't see if that xmlrpc_encode_request is pages and pages of C code and PHP macro's behind the scenes. That function should be in a library, not in a programming language, which is why PHP is more comparable to other web frameworks, not to other programming languages.

Re:Python alternatives for PHP functions by Firehed on Tuesday December 25, 2012 @01:40PM (#4966683)
It IS a PHP library - just one written in C rather than in user-land PHP code. Why is this a problem? The XML-RPC extension isn't even enabled by default.
Re:Python alternatives for PHP functions by emidln on Tuesday December 25, 2012 @10:29AM (#4966169)
xmlrpc_encode_request on this site should probably be fixed to use xmlrpclib.dumps (or loads if you need the other direction). This has existed in Python since version 2.2.

I realize this is beside the point, but I'm willing to fix it myself.

Re:Python alternatives for PHP functions by buster on Tuesday December 25, 2012 @03:37AM (#4965498)
There is xmlrpclib inlcuded per default and it does all the XML stuff, so i think you can easily get away far more readable then what is shown in the python reimplementation of the PHP function. http://docs.python.org/2/library/xmlrpclib.html#example-of-c...

It just doesn't have xmlrpc_encode_request() with the exact method signature.

P.S.: I am wondering if it is normal to have functions marked as EXPERIMENTAL with a biiiig warning sign for 11 years in the language? That really scares me. This function has been introduced in PHP 4.1.0 which was releases in 10-Dec-2001... That's just...

edit: removed rant about xmlrpc_encode_request being built-in. It's a non-default extension, apparently..

Re:Python alternatives for PHP functions by scott_w on Tuesday December 25, 2012 @07:31AM (#4965851)
No it's not.

The reason the examples appear longer is because the website is documenting how to implement PHP functions in Python. Since Python is not PHP, it won't implement line-for-line replacement functions.

Re:Python alternatives for PHP functions by smsm42 on Wednesday December 26, 2012 @02:01AM (#4968468)
No, just PHP has a tradition of implementing frequently used code in C. This means PHP has tons of functions that serve specific use case, while Python has less of them, at least in standard package (of course you can have a module that does the same and then you'd have one-liners too). So you're not comparing the same thing here.
Re:Python alternatives for PHP functions by yareally on Tuesday December 25, 2012 @04:18PM (#4967128)
Using both PHP5 in the past and Python more recently, I find that most things in Python need far less code to write than PHP.

The examples here are kind of disingenuous to that, but if you start writing code that takes advantage of the features of Python, your lines of code should be less than PHP or equal.

Re:Python alternatives for PHP functions by aptwebapps on Tuesday December 25, 2012 @04:15AM (#4965565)
I don't think it's complete. For example this: http://www.php2python.com/wiki/function.array-walk/ could be replaced with map() in Python.
Re:Python alternatives for PHP functions by paranoiacblack on Tuesday December 25, 2012 @02:54AM (#4965429)
No, there are a lot of shortcuts and beautiful one-liners in Python. However, Pythonic code always focuses on being the simplest and cleanest as opposed to being the shortest. I suspect it's the author's way of imposing some good python coding standards at the same time.