Mewlo Web Framework Blog Entry #5 - January 29, 2014 - Third Party ComponentsSo I took a little time off working on Mewlo, but I'm back to it now, and starting to have a little more fun with it.
Today I thought I'd talk a little bit about which components of Mewlo will be handled (at least initially) by 3rd party open source libraries.
I see Mewlo occupying a middle ground between Django, a framework which uses very few 3rd party components, and Pylons/Pyramid, which is heavily reliant on 3rd party components (both excellent frameworks).
First, let's talk about different ways one might utilize 3rd party components/libraries in a framework.
In the Pylons/Pyramid framework, the framework works hard to make it possible for programmers to use alternative components for major core functions -- such as the database engine, the template engine, etc. The advantages of such an approach is that the coder is free to use whichever alternative components they prefer. The disadvantages are that the framework cannot rely on the existence of features and functions, and must sometimes go to extreme lengths to coordinate actions, resulting in overly-complex code. Sometimes operations must be left to the coder to implement simply because the framework cannot know how the operations would be implemented by different components. Each component has it's own way of working and it's own coding conventions.
Django, in using custom in-house components for most things (database engine, templating system), can offer a more uniform API and a cleaner more integrated framework. Components are highly optimized for the framework and follow a unified set of conventions. The built-in Django components are actually quite excellent. The disadvantages of such an approach include the in-house coding and maintenance effort required for such components, rather than relying on a high quality active third party open source component, and inflexibility of not allowing programmers to choose their own components for core features (database engine, templates, etc.).
With Mewlo, a conscious effort has been made to follow a philosophy of "one right way to do things". As such, we are not concerned with offering programmers the flexibility of using their own database engine, template engine, etc. I realize this can be a controversial decision for some -- and where there is no real complexity cost associated with offering choices (as is the case with template engines), we may relax this strategy. But in general, we begin with the premise that enforcing the use of a specific component set is not a bad thing.
Furthermore, Mewlo leans much more heavily in the direction of reinventing-the-wheel and writing code in-house, for most functionality. As such we avoid the use of components when such components are integrated tightly into the framework -- it's my belief that the more different components maintained by different organizations, the more moving parts there are that lead to messier and convoluted code.
Having said that, Mewlo does use some key 3rd party components/libraries. These components represent a substantial amount of non-trivial intricate code and they are actively developed and maintained by other entities. It is judged that reinventing these components would not be a good expenditure of time, and we have tried to focus on components that do one thing well.
But, it should be noted, that Mewlo makes an attempt to abstract the interface to these components using thin-wrappers, so that all user-written code goes through a Mewlo API, rather than interacting with these 3rd party components directly. This has several benefits. First, it allows Mewlo to present a uniform outwardly-facing API interface. Second, it allows us to replace components in the future without changing the basic API. Third, it's consistent with our strategy of designing Mewlo as an language-neutral OOP hierarchy that we could move to another language.
Note that the 3rd party Components I am speaking of here are python libraries that play essential core roles in Mewlo. I am not talking about occasions when some custom user code will want to use an arbitrary library to perform some limited action.
Template Engine - Jinja2
------------------------
We have preliminarily chosen the
Jinja2 templating system for Mewlo (we could have just as easily chosen
mako). As discussed earlier -- a programmer using Mewlo does not invoke Jinja2 functions directly, but acts through an abstract Mewlo class that could easily be extended to support additional templating engines.
ORM Database Layer - SqlAlchemy
-------------------------------
For database operations that do not have to run at the absolutely fastest speed, there are huge advantages to using an object-oriented ORM database layer. An ORM database library/component is an intricate thing with lots of moving parts that relies on some esoteric language features. As such, it's exactly the kind of thing that we would prefer to hand off to a well-maintained 3rd party component.
SqlAlchemy fits this bill nicely. Again, all database operations are done via Mewlo classes, which abstract the calls to SqlAlchemy and facilitate DRY coding with minimal reuse of configuration information.
Form Construction and Validation - WTForms
------------------------------------------
Mewlo currently uses the small
WTForms library to handle form creation, presentation, and validation. Form handling is small enough in scope, that we could replace this in the future with our own custom library -- or move to a larger form library. For now it represents a good solid minimal form handling component.
Low-level Web Objects - Werkzeug
--------------------------------
Mewlo currently uses the
Werkzeug library to handle the low level request and response objects (including cookies, etc.) that lie at the heart of a web framework. The choice of Werkzeug does violate one of our guidelines for choosing 3rd party components in that it includes code to provide a large number of features that we have no interest in using. Because we only use minimal pieces of the Werkzeug library, it is highly likely that we will rewrite this component in-house for Mewlo, or move to a much more minimal library for request and response handling.
Others
------
There are several parts of Mewlo that have not been implemented yet, but which will most likely depend on the adoption of 3rd party component libraries:
* Css/Javascript/Ajax frameworks
* Internationalization library