That's funny, I was precisely thinking about a php to python converter,
some weeks ago.
Such a tool, allowing for example to convert some CMS like Drupal to
python, would be a killer app, when we consider the amount of php code
available.
But of course, there are lots of issues that'd have to be fixed :
- translating the php syntax to python syntax
- forcing scope limitations where php doesn't have any
- handling differences in semantics (for example, the booleanness of "0"
or)
- handling the automatic variable creation and coertion that php features
- handling the php types like arrays (which are neither python lists nor
python dicts)
- providing a whole mirror of the php stdlib (string and file functions,
access to environment vars...)
Some things, like PECL modules, would imo be almost impossible to handle
(there are already so much trouble to make Cpython extensions available
to other python implementations...), but I guess that 95% of existing
php websites could be wholly translated "just" with a language
translator and an incomplete stddlib replacement.
That's hell a lot of work anyway, so it'd be worth weighing it ^^
Actually, your module "phppython" might already be rather useful,
because I've crossed here and there people desperately asking for help
when translating some php function of their own to python.
But if the project were to become bigger, I guess some choices would
have to be rechecked. For example it seems you parse the php code your
own way, instead of using existing php parsers ; I think the most
flexible way would be walking some kind of php abstract syntax tree, and
translating it to python AST on the way. Also, writting the comments in
english woudl be mandatory :p
I'd like to have the opinion of people around : do you think that
complete language translators like php<->python or ruby<->python are
possible ? Impossible ? Not worth the effort ? Or must be reached by
another way (eg. Parrot and stuffs) ?
Regards,
Pascal
PS : Am I the only one having most of answers rejected by the antispam
system of python-list ? That's humiliating :p
bvidinli a �crit :
> if anybody needs:
> http://code.google.com/p/phppython/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
I'm not a big fan of PHP but I don't understand the desireability of
such a tool. If you have a good PHP app just run it. The point of
Python in my mind is that it is a cleaner syntax and promotes better
code. Anything that converts PHP to Python is going to leave you with
some butt-ugly Python. It also risks adding new bugs.
If you want a Python version of Drupal then perhaps that is the project
that you want to start. Start fresh using the existing project as your
requirements specification. Don't automatically import all their
coding choices that may be partially based on the language used.
--
D'Arcy J.M. Cain <da...@druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
It would be a great learning tool. I am pretty decent with PHP but
just getting started in Python. This might help such users flatten out
the learning curve.
--
Dotan Cohen
If there were such a tool available I would sugegst it come with huge
warnings suggesting that the resulting code not be used for learning
purposes. You would still be much better off with the tutorials.
I'm almost 100% sure it won't. The code is machine-generated, thus not easy
to the human eye, not idiomatic so you don't learn how to write good python
through it. You learn how to jump through hoops to code the same way in
python that you do in PHP.
Diez
I meant for single functions, not for translating entire apps.
I've had several messages not make it through.
:(
No difference. Either the functions are trivial, or they become
non-idiomatic.
Diez
I've been trying to investigate several instances of posts to
comp.lang.python.announce getting approved and making it out to the
mailing list but not the newsgroup. In each case, reposting as plain
text fixed the problem. I suggest that anyone having similar problems on
c.l.py do the same thing.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
Aahz> I've been trying to investigate several instances of posts to
Aahz> comp.lang.python.announce getting approved and making it out to
Aahz> the mailing list but not the newsgroup. In each case, reposting
Aahz> as plain text fixed the problem. I suggest that anyone having
Aahz> similar problems on c.l.py do the same thing.
The problem lies with moi. The ham/spam database had grown rather huge. I
tossed out a bunch of older ham and spam messages from the database and
retrained. That caused a large fraction of new posts to be held as
"unsure". Unfortunately, I didn't notice that for a couple days. I added a
couple hundred of the recently held hams and spams to the database and
retrained last night. This morning nothing new was held. Hopefully that
will solve the problem.
--
Skip Montanaro - sk...@pobox.com - http://www.smontanaro.net/
America's vaunted "free press" notwithstanding, story ideas that expose
the unseemly side of actual or potential advertisers tend to fall by the
wayside. Not quite sure why. -- Jim Thornton
Some thoughts.
1) Syntax. Not a big deal.
2) Semantics. My favourite approach was to create a Python framework
that represents PHP in Python and enables round-trips. So one could
translate forth and back. Python code that is compliant to the
conventions of the framework can also be translated to PHP and for
each PHP program P following equation holds:
py2php(php2py(P)) = P
This makes readable code mandatory.
3) PHP stdlib via C bindings ( ctypes? )
4) Corner cases of bindings: cut them off. Not everything has to be
translated. But produce stubs that raise NotImplementedError
exceptions.
Same arguments apply to Javascript. Not sure about Ruby but I do think
a parser is feasible despite context sensitivities. Ruby is not my
concern though.
Personally I'd be interested in Wordpress which I like and use.
Kay
as stated on project home, it is only intended for translating small
code snippets or small functions to python.
whole applications, cannot be converted using that...
only an idea, a very beta/alpha package,
since there are huge amount of php applications, files, codes all
around web, this would be a good tool if developed and used
properly...