Why use a Web Framework?

You might be wondering why you need a web framework at all? After all, it just adds complexity and bureaucracy. You are a uber-nerd. If you want a web framework, you can write you own, dammnit!

How hard can it be to write your own framework?

The PySkool Guide to Build your own Web Framework!

Simples! First, write your own TCP/IP server. Also, build the server (the box) yourself too. While you are at it, don’t buy any hardware from these evil bourgeois capitalistic robber barons. Use an FPGA, and build your own processor. Hell, build your own FPGA using spare electrons (I’m sure you can find a few).

Then write the code to talk to the rest of the Internets. Don’t know how? Simples! Firefox is an open source program. Download its code, and start reading.

< 80 years later >

Congrats! You have a web server. You achieve the title of Hacker Kitty:

hacker kitty programming a mac

If you think I’m being facetious, isn’t this what 90% of advice in open source forums is? “The 90 million line code is there, why don’t you just read it and solve your problem?”

Reasons to use a web framework

Frameworks provide you with several useful features:

1. Url redirection: So that when the user goes to yourwebsite.com/kitty, the server knows it must run the script kitty.py.

2. Authentication: A simple way to determine if users have logged in. May also allow you to set cookies, so you can spam you users show them meaningful and spiritual ads that will enrich their lives.

3. Support for databases: At the minimum, you will have a database of usernames, right?

4. Security: Framework designers know most of the security attacks, and will have build safeguards in the framework. There might still be holes, but as long as the framework is open source, you know they will be found and fixed (someday).

The real problem with frameworks

So lets come to the real problem you don’t use frameworks: They are big, bloated, ugly and very hard to use (I’m looking at you Django. I recently read a long tutorial, at the end of which the author said ‘Now you can understand the official Django tutorial’. Because the official tutorial doesn’t make sense).

Not only are many frame works hard to start with, they have a lot of baggage and “magic”. If you want to do anything even slightly different from the “approved” way, you have to jump through a lot of hoops, and go digging into the dark innards of the documentation, written for version 0.01, and never updated since. You might wonder, why is this done this way? The answer is, usually, cause they say so. And you can’t blame the designers. In many cases, they are aware of the problems. But due to historical reasons, and backward compatibility, you are stuck with the decisions made by someone sitting drunk in his underwear (isn’t that how most web frameworks and programming languages designed? I dare you to prove me wrong).

But it doesn’t have to be this way. You don’t need to use huge ugly frameworks. Instead, you can use micro frameworks,  which allow you to bring in what you need, rather than what someone five years ago thought you might need today. In Python, the most famous micro framework is Flask. In a later blog, I will look at Flask vs Django.

Leave a Reply

Your email address will not be published. Required fields are marked *