
Ask HN: Relaunch my website in Ruby/Python or continue with PHP? - syed123
Hey All,
My site http:&#x2F;&#x2F;LetsLunch.com is written in PHP - YII framework - we are looking to relaunch it with a new angle&#x2F;pivot. Any ideas on should we continue to build on existing PHP or switch to more modern languages like ruby&#x2F;rails, angular etc.. is switching over and rewriting worth it?
======
Can_Not
First off, most of those languages/frameworks aren't even modern, let alone
"more modern" than PHP. Next most of them are not significantly faster than
PHP, if they're not definitely slower than PHP. If you're not using modern
PHP, you can upgrade to PHP7.x faster than a full rewrite. I would avoid
rewriting anything non-trivial, because you have no guarantee that your new
codebase will be completed in a predictable amount of time, let alone be
faster. If a specific sub-module needs to be in a faster language, rewrite
that small part in something like golang or elixir. You need to be really
careful with full rewrites, you're more likely to end up with a whole year of
lost productivity than a success story. I'd recommend learning how to profile
and optimize performance _after_ migrating to PHP7+.

~~~
syed123
This is really helpful. I was being pushed to upgrade by the programmers i am
trying to hire who say old website code is kind of spaghetti..and a new clean
rewrite in node/ruby will go a long way in hiring good bayarea programmers.

------
jstewartmobile
Stay the course and tune out the fashionistas. We maintain large codebases in
all three, and I can only remember one case where any of the languages got in
the way (PHP's poor threading support). And even that case wasn't a show
stopper--we just used fork() instead.

Great business idea BTW. If I lived in a larger city I would definitely try it
out!

~~~
syed123
Thanks for the helpful tips. Its hard to live in SF and not feel like missing
out on Ruby/rail, node.js and other new fast and easy programming languages.

------
odonnellryan
I'd say, if the site can be rewritten quickly, use the language you're most
productive in.

If the site is small and can be ported in < 1 week might be a good rule.

But if your most productive language is PHP, why not leave it?

No reason to use Rails, Node, or Python for this.

~~~
syed123
i thought new languages are easier,scalable, more libraries etc since they are
new. But it will take more than a week for sure to port the site data to new
rails/node. Thats why wanted to make sure its well worth switching.

~~~
odonnellryan
I wouldn't say Python or Rails is more scalable, but the libraries may make
certain things easier.

What libraries do you feel you're missing out on?

------
mabynogy
Rewrite it in Go with Caddy for the backend and plain JS for the front.

[https://caddyserver.com/](https://caddyserver.com/)

------
saluki
Check out Laravel if you're sticking with PHP but interested in a new
framework.

~~~
vldx
Definitely try out Laravel.

I'm not involved in the PHP community, but had a chance to take off a client
project and decided to go with Laravel. It was real pleasure working with in
combination with writing modern PHP overall.

Jeffrey Way's Laracast was of help for me and is worth checking out.

~~~
gremlinsinc
As a laravel dev by day (and sometimes night) --- can say Vue.js and Laravel
are VERY modern frameworks and constantly updated--Vue is optional and can be
swapped for React / Angular or even jquery -- but laravel is a great backend
or api for a service oriented architecture.

------
sparkling
Do you have some ugly corners in your code base? Lots of legacy stuff that you
want to rework anyway, regardless the language? Then it might make sense.

~~~
syed123
website is kind of slow and some bugs..so i am wondering if refactoring or
bugs fixing is worth it or switching to a new modern language.

~~~
jstewartmobile
If your problem is speed, Ruby & Python probably aren't going to help. Query
optimizations typically yield a lot of bang for the buck. Once you've
harvested all of the low-hanging fruit there, in-memory caching (memcached,
redis) can also bring a lot to the table.

~~~
odonnellryan
Ruby and Python could help -- but depends what you're doing. They aren't going
to magically make your DB queries faster... but certain libraries can perform
many, many times faster.

Though, that's the library, not the language.

~~~
syed123
it also helps to find more programmers here in the bayarea if i switch to
ruby, node etc all the cool programming dudes that i want to hire -are not in
php.

~~~
odonnellryan
Not many devs want to work on PHP codebases, that's absolutely correct. PHP
does not really look great on the resume, unfortunately.

But you should be hiring to solve a problem -- seemingly speed and
reliability, in your case -- not for a language.

But yeah, tell them what stack they will be working on ;)

------
git-pull
I did PHP before Python. Done CakePHP, Drupal back in the day. Then did some
idiorm + paris w/ slim.

That said, I'd like to try to sell you on Python. First off, let's begin by
saying PHP is a solid web language with mature tools. I haven't looked at the
ecosystem in maybe 5 years. Due to this, I can't speak for PHP 7 and the
latest and greatest best practices and libraries.

But as of 2017, I think python has surpassed PHP in web development. This is
due to some fundamental things being baked into the language, and external
factors like luck, timing, and momentum.

0\. PHP's "lost years": PHP didn't capitalize on standardization, packaging
and libraries for a long time. I don't know what the reason was, but it was
PHP 5 for a long time and the language didn't "move".

This allowed other languages like ruby to gain ground back in 2005-2012. PHP 6
never happened. The community had to pull together and start PHP-FIG and
stuff. During those years, a lot happened, other language ecosystems gained
significant traction.

Sure, there were great strides in _individual_ projects like Drupal and
Wordpress. But these CMS and frameworks lacked a package manager during that
time. And despite being OOP, developers weren't sharing each other's code the
same way Ruby and Python did.

1\. Code standardization: Python nails this. PEP8 (code style), PEP257 (code
documentation).

1.1 Code aesthetic: While the lack of subcolons and block-style struck me as a
gimmick for a while (remember I did PHP before python), I came to find it
makes code a hell of a lot easier to read.

2\. Package management - People started publishing packages early on. Even if
there was distutils/setuptools warts for a couple years, the practice of
having a real market for code was great. PHP didn't have that for a long
time.. anyone remember PEAR?

3\. OOP: Python's OOP makes it very clear to move up the class tree. This sort
of winds in with the the code style too, you can easily navigate and traverse
large codebases and wrap your brain around chunks of code really fast in
python.

4\. Imports: Better implemented in python. Much more straight forward and
clear. You can pull in a full module from your environment's current packages
or relative location (import flask or import . mymodule). You can also import
objects like constants, functions and classes scoped in a module, like "from
mymodule import myfunction", also import as an alias, "from mymodule import
myfunction as a".

5\. Community: At this point, Python's community is more active. Though PHP
seems to be strong as well. People are building websites in PHP and are still
successful at it. That says a lot.

6\. Use Domains: Python is being used in big data (pyspark), general data
science with pandas, numpy, juypter. The web with django, flask. System
utilities like supervisor. People can write mobile games with kivy. There are
C speedups like Cython. ORM's like Peewee and SQLAlchemy are mature and
superbly documented.

6.1 Web: Python's most popular web framework, Django, is very mature. The ORM
is very nice. Migrations. Documentation. Flask, a popular framework for
Python, also have excellent documentation and many users. And aside from that,
there are many other web libraries like Pyramid, and ones I can't even think
off the top of my head. Pyramid is actually one I hear great stuff about
haven't even tried yet.

7\. Runtime implementations: CPython (default), pypy (python-hosted), Jython
for Java and IronPython for .NET

8\. Performance: pypy, numpy/pandas has tabular / typed speedups. I'm probably
forgetting a few.

9\. C/C++ integration: Boost.Python, pybind11 (new and highly cool), CFFI,
Cython, Swig, and the CPython's own implementation of C API's, which CPython
itself builds upon is at your disposal, and ctypes.

10\. Documentation: Python itself, as well as the top libraries in the open
source community all use Sphinx to generate documentation. Builds nice static,
themed HTML sites with a nifty feature called "intersphinx" to link across
project documentation. And it's used at scale in the community. Big thanks to
ReadTheDocs.org for providing a place for the community to host.

In most cases, the above "nice things" about python have been around in
production and used at scale long before I did Python full time. This gives
python a significant advantage.

Some additional free resources on Python:

\- [https://python-guide.readthedocs.io](https://python-guide.readthedocs.io)

\- [https://github.com/vinta/awesome-python](https://github.com/vinta/awesome-
python)

~~~
syed123
Thanks for the detailed rundown. How long do you think it will take to rebuild
the existing letslunch.com website from scatch in python? just a rough
estimate without going for the nitty gritty of table sizes, length, number of
lines of code.. letslunch has data of 90,000 users, 60,000 lunches, 12-15
dynamic pages and about 6 api's that we use from linkedin, facebook etc

~~~
git-pull
Build it in parallel with your current codebase.

If you're not doing so already, create a staging database you can use for
developing this. That way if something goes berserk production data stays
safe.

Get a jumpstart by using Django and creating models that match your database
via inspectdb [1]. Most important thing is getting the data to fit and relate
as you'd expect.

Some recommended plugins are django-debug-toolbar
([https://github.com/jazzband/django-debug-
toolbar](https://github.com/jazzband/django-debug-toolbar)) and django-
extensions ([https://github.com/django-extensions/django-
extensions](https://github.com/django-extensions/django-extensions)).

Then for Social API logins use [https://python-social-auth-
docs.readthedocs.io](https://python-social-auth-docs.readthedocs.io). For
Social API's themselves there are python wrappers, like
[https://github.com/mobolic/facebook-sdk](https://github.com/mobolic/facebook-
sdk). In the worst case, you'll be querying API's directly with requests
([http://docs.python-requests.org](http://docs.python-requests.org)).

Next, you begin to build views (and their templates) around the models you've
created. You're going to want them to run at a parity with what you have in
PHP. Use urls.py regular expressions to match your URL's too.

This is how you mitigate the risk of doing a "migration". And also a great way
to get some experience under the belt while you do it. You should be able to
get your site working off a staging database in a read-only way when you do
this. Keep the PHP site in production until your ready to switch.

If you use JSON/REST, also check out Django REST Framework.
[http://www.django-rest-framework.org/](http://www.django-rest-framework.org/)

I'm going to be making a detailed blog post on django in a few days as well.

[1] [https://docs.djangoproject.com/en/1.11/howto/legacy-
database...](https://docs.djangoproject.com/en/1.11/howto/legacy-
databases/#auto-generate-the-models)

~~~
syed123
Based on the website and code base i have, i just want a rough estimate..are
we talking 2 weeks, 2 months or 6 months here to rebuild in a new language?
does it provide any advantage that the code was already written and api's work
etc in the other language? trying to see if something can be reused or is it
gonna be a total build from scatch new website..

~~~
git-pull
> does it provide any advantage that the code was already written and api's
> work etc in the other language

If you build your models to be an exact fit with your current data, yes.

> Based on the website and code base i have, i just want a rough estimate..are
> we talking 2 weeks, 2 months or 6 months here to rebuild in a new language?

That's like asking a consultant for a time estimate when they don't know all
the details. Factors include:

\- How much python you know already

\- How long does it take for you to grasp the fundamentals of virtual
environments, packages, importing, etc.

> trying to see if something can be reused or is it gonna be a total build
> from scatch new website..

\- Good point: If you end up keeping old API's running on the PHP side and
just migrating the HTML stuff first, or only. That is a shortcut to get going
faster.

\- How much templating you have to do. But I think you can do that in maybe (2
Weeks). Django templates are easy to learn and you can extend from a common
base.

\- Database models. I think you should try the inspectdb thing ASAP as a trial
to see how easy it is to display _any_ data from your current schema. Be sure
to use a copy (or sample) of your prod data in a separate staging database
though. You could do that tonight. Getting everything (relations and all) to
map perfectly (ORM -> your current db schema) could take a couple of weeks to
get perfect. Use this 'managed = False':
[https://docs.djangoproject.com/en/1.11/howto/legacy-
database...](https://docs.djangoproject.com/en/1.11/howto/legacy-databases/)

\- Development hosting: I recommend trying out Heroku. The deployment is
straight forward. But outside of that you're going to have to wrap your brain
around how to deploy it. nginx + uwsgi + supervisor is a common combo if
you're doing it right on the server.

\- Business logic: Most of this is done inside your views. This could take a
month or so.

Since django is a big framework and these things work in tandem, it could be
3-6 months. Remember to build it in parallel so the PHP site can continue to
be maintained if needed. And create a staging database that's based off your
production schema with some sample data in there.

Also while you do this, you're going to continually get faster as you gain
mastery with python.

For a speed boost, you can continue to keep API's running in PHP while you
convert other stuff over first.

~~~
syed123
wow..excellent advice. You made me day and week!!

