annotate doc/philosophy.rst @ 60:682cd33e564c draft

Documentation (incomplete).
author David Barts <n5jrn@me.com>
date Sat, 08 Jun 2019 07:43:15 -0700
parents
children 55828c01e38f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
1 **********
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
2 Philosophy
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
3 **********
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
4
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
5 =================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
6 Be WSGI Compliant
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
7 =================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
8
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
9 It's the default standard for Python web frameworks.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
10 Only a fool wouldn't support it.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
11
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
12 ========================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
13 Don’t Reinvent the Wheel
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
14 ========================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
15
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
16 TinCan is mostly Bottle and Chameleon. Why rewrite the basic guts of an
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
17 application server, when they’ve already been written many times? Why
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
18 write a new templating engine, when there’s existing ones out there?
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
19 TinCan tries to leverage existing software as much as possible.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
20
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
21 ======================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
22 Keep It Simple, Stupid
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
23 ======================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
24
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
25 I wanted to get on with the business of actually *using* TinCan to do things,
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
26 so I didn't clutter it up with extra features that would be difficult to
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
27 implement. (That's why there's currently no way to choose alternate templating engines
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
28 to Chameleon. I tried to do that, and it proved overly complex. Maybe some day.)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
29
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
30 ===========================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
31 Don't Be Gratuitously Bossy
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
32 ===========================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
33
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
34 TinCan is not tightly coupled with an ORM, and never will be. I personally dislike
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
35 ORM's, and
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
36 `I am not alone <http://seldo.com/weblog/2011/06/15/orm_is_an_antipattern>`_.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
37 Moreover, not all web applications need to use an SQL database in the first
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
38 place.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
39
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
40 This is of no loss, even for those who prefer to use an ORM, since
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
41 it is easy enough use an ORM with TinCan (just add it to the script you make
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
42 to load the webapp, and include the ORM in the webapp's ``config`` dictionary).
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
43
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
44 ===========
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
45 Code-Behind
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
46 ===========
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
47
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
48 It's maligned by many, but I personally like it, and it
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
49 does *not* necessarily mean repudiating the MVC paradigm.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
50
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
51 =====================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
52 Don't Repeat Yourself
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
53 =====================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
54
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
55 One of the things I dislike about most Python web
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
56 frameworks is that I'm always tiresomely repeating "this is route foo, serviced
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
57 by controller foo \(which defines variables bar, baz and blort\), which uses template foo
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
58 \(which renders variables bar, baz and blort\)." This is completely unnecessary;
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
59 the relationships should be obvious by virtue of the similar names. The framework should figure
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
60 it out and just "do the right thing" by default.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
61
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
62 ============================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
63 MVC Comes in Different Forms
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
64 ============================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
65
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
66 If you show a little discipline, the template page will describe how data
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
67 is presented to the user, and how he or she can interact with it. A view
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
68 by any other name is still a view. The code-behind will tie that view into
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
69 the underlying business logic, and bridge the gap between the two. A controller
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
70 by any other name is still a controller.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
71
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
72 If you don't show discipline, you can clutter your templates up with bits
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
73 of Python code that represent controller logic, and clutter your controller up with
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
74 bits of presentation details. Of course you can. That's not the framework's
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
75 fault; that's the programmer's fault. Bad code can be written in any language,
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
76 for any platform.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
77
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
78 ==================================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
79 The Alternative is PHP or CGI, not Django or Flask
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
80 ==================================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
81
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
82 I'm not the only one out there who doesn't like all the repeating yourself
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
83 that most MVC frameworks make you do. There's still *a lot* of developers
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
84 out there writing CGI scripts or using PHP, because CGI and PHP don't make
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
85 you do all the busywork that frameworks do. (Can they be blamed? It really
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
86 feels silly when all you want is to get a quick, small site up.)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
87
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
88 That's a pity, because CGI is hideously inefficient and PHP is, well, just
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
89 plain hideous. \(A root namespace with literally *thousands* of builtins
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
90 cluttering it up, builtins with *no* consistent naming convention? Ugh!\)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
91
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
92 Hopefully, by making it easier for people to code efficient web sites using
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
93 a well-designed language that's easy to learn, I'll encourage more people
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
94 to create efficient sites in a well-designed language. If not, well, at least
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
95 I'll encourage *myself* to do so.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
96
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
97 ============================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
98 Meaningful Error Messages (If You Want Them)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
99 ============================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
100
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
101 Bottle can be notoriously tight-lipped about what's going wrong if and
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
102 when things go wrong. (And when you're developing and debugging code,
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
103 things go wrong). TinCan tries as hard as possible to catch errors and
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
104 log them. Enable logging, and when you see a 500 error, you will almost
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
105 always have a log file with a traceback in it helping to pinpoint the
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
106 cause.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
107
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
108 That is, assuming you enable logging. By default, it is turned off, simply
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
109 because WSGI provides no default place for errors to go.