Hacker News new | ask | show | jobs
by jasonkeene 5192 days ago
So web2py introduces new members to __builtins__? Coming from a general Python programmer with no "vested interest" I have to say that isn't the best of ideas. len/dict/list are builtins because they are part of the language. They can be assumed to be present in any Python program. Teaching people that these web2py objects are available globally w/o importing them is setting a false expectation. This is pretty much monkey patching even if you aren't overriding stuff. Generally a no-no in the Python community.

With great power comes great responsibility.

2 comments

No, notice that "builtins" was in quotes. web2py does not actually add new members to __builtins__. Rather, web2py executes model files, controllers, and views in a pre-defined environment that includes a number of web2py API objects (though not the entire API). This includes about a dozen core objects, such as request, response, session, and cache, plus a set of HTML helpers (all derived from the same class and named after their HTML counterparts) and a set of form validators (all derived from the same class). This is all very well documented.

People like you who have never actually used web2py routinely express concern that this will somehow set up false expectations and confuse people about how Python modules and imports work, but in practice this is simply not the case. Note, web2py also includes a number of modules that require explicit importing, and applications can include their own modules as well as import standard library and third-party modules. As a result, web2py developers are perfectly comfortable with normal Python imports and do not have any false expectations.

Web2py is indeed using its "great power" responsibly.

Your reaction is very similar to the reaction people who have never used Python have when they discover Python has significant whitespace (with no vested interest against Python): "That's a horrible idea! It failed miserably for Fortran 40 years ago! That goes against everything I was taught!". Yes, it does not fit exactly with some mental model you already have. But no, it does not set up false expectations, much like Python does not set up false expectations of whitespace significance for C programmers who wrote a couple of Python programs.

Anthony already addressed the details in his reply below, but let me just add: IPython and sage essentially redo the python command line, and get nothing but praise. web2py, in some limited contexts (models and controllers) introduces a few useful names into the global namespace, and gets a ton of criticism.

Django (and just about every other framework) introduces a whole new language for templates, and no one squeaks, wheresa web2py uses plain Python as its template language with the smallest modification possible to provide that (you need to add "pass" at the end of a block, because you don't have indentation to guide you properly inside an html template; other template languages add an "endif" one way or another), and no one cares.

It is telling that all this criticism is coming from people who never use web2py, much like criticism of significant whitespace comes from people who do not use Python.

It is bigotry, disguised as a technical argument. In both cases.