Web2py vs Django, Implicit vs Explicit

Web2py가 python web framework에서 이단아 취급받는 이유는 약 9개의 major object를 explicit하게 import 하지 않고 prepared environment를 이용해서 개발자가 implicit하게 사용할 수 있도록 한 design decision에서 기인합니다.

특히 Django 개발자들이 이 부분을 언급하는 경우가 많은데  Django에서 explicit를 선호하는 이유는 Pythonic하다는 것입니다.

Zen of Python에 2번째 항목에 다음과 같이  “Explicit is better than Implicit” 로 명시되어 있습니다. Zen of Python이란 일종의 Python programming community의 mantra같은 것으로 Python programming시 기본적으로 지켜야 할 규칙(에티켓)과도 같은 것입니다.

드러내고자 하는 기능을 명시적으로 기술하는 것이 어떤 가정하에 기능하는 것보다 낫다는 것입니다. 그렇지 않는 경우 문제를 일으킬 수 있습니다.

The project I started working on has a bunch of maintainers, I guess several years of effort, but no unit-tests. When I asked why they had no unit tests, they said they had tried to go that way several times, but had given up each time as it wasn’t worth it. I found this hard to believe, how hard can it be to write unit tests? You just write ‘em and run ‘em.

Not so with web2py. I soon found out why it had been so difficult for them; because web2py code has the global environment, it has to expect the global environment, so any code that is run by unit tests must inject that global environment, which is actually really hard to do. So hard that it took me (an experienced python developer) a entire weekend to write a web2py nose plugin just so that I could run unit tests with nose. It would normally take about a minute to get cracking with nose: install it, type “nosetests”. http://greg.thehellings.com/2011/01/python-web2py-or-django/#comment-509

하지만 Web2py에 이런 implicit한 부분이 너무 부풀려져 있다는 것입니다. 실제로 Web2py에서 Implicit하게 import되어 있는 major object는 다음 9개이고

request, response, session from globals.py
cache from cache.py
translator from languages.py (instantiated as T)
redirect, HTTP from http.py
DAL, Field from dal.py

그 내용 또한 Explicit하게 문서화되어 있습니다.

Web2py Book – API

즉 Web2py의 Implicit한 부분은 Explicit하게 명시되어 있고, 숨기지 않으며 그로 인해 발생할 수 있는 문제는 대부분 잘못된 오해에서 비롯된 것입니다.

Missunderstanding about Web2py


이런 design decision으로 인해 framework과 application의 분리가 가능하고 서버 restart없이 수정이 가능(hot-swap)하다는  것입니다.

Because this allows hot swap and plug-and-play of applications and/or parts of an application without ever restarting the server, in development as well as in production, with any web server. This allows the system administrator to change any part of an application by installing a plugin at runtime. This opens the doors to many interesting possibilities. We believe there is a value in keeping the framework layer and the web application layer separated. Some of the ease of use in web2py is possible only because of this design choice.
– from Missunderstanding about web2py

마지막을 Massimo의 글을 인용하겠습니다.

They are philosophically differences:
Django preferes “explicit is better than implicit” so you have do define
lots of boilerplate
web2py says “do not repeat yourself” so you have lots of
default behavior (magic?) but documented and backward compatible.

Happy Coding~:)


About rookiecj

Hi all. Today is the day.
This entry was posted in python, web2py and tagged , , , . Bookmark the permalink.

One Response to Web2py vs Django, Implicit vs Explicit

  1. Pingback: web2py를 좋아하는 이유 « dingulx2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s