annotate doc/philosophy.rst @ 72:e8b3b336e63e draft default tip

Update version.
author David Barts <n5jrn@me.com>
date Mon, 15 Jul 2019 13:17:48 -0700
parents 55828c01e38f
children
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
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
27 implement. (That's why there's currently no way to choose templating engines
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
28 other than Chameleon. I tried to allow that, and it proved overly complex. Maybe some day.)
60
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
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
49 does *not* necessarily mean repudiating the MVC paradigm (see :ref:`mvc-different-forms`).
60
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
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
62 .. _mvc-different-forms:
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
63
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
64 ============================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
65 MVC Comes in Different Forms
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
66 ============================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
67
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
68 If a programmer shows a little discipline, the template page will describe how data is presented to the user, and how he or she can interact with it. A view by any other name is still a view. The code-behind will tie that view into the underlying business logic, and bridge the gap between the two. A controller by any other name is still a controller.
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
69
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
70 If a programmer don't show discipline, s/he can clutter templates up with bits of Python code that represent controller logic, and clutter the controller up with bits of presentation details. Of course s/he can. That's not the framework's fault; that's the programmer's fault. Bad code can be written in any language, for any platform.
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
71
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
72 ==================================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
73 The Alternative is PHP or CGI, not Django or Flask
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
74 ==================================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
75
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
76 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
77 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
78 out there writing CGI scripts or using PHP, because CGI and PHP don't make
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
79 you do all the busywork that most frameworks do. (Can they be blamed? It really
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
80 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
81
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
82 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
83 plain hideous. \(A root namespace with literally *thousands* of builtins
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
84 cluttering it up, builtins with *no* consistent naming convention? Ugh!\)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
85
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
86 Hopefully, by making it easier for people to code efficient web sites using
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
87 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
88 to create efficient sites in a well-designed language. If not, well, at least
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
89 I'll enable *myself* to do so.
60
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
90
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
91 ============================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
92 Meaningful Error Messages (If You Want Them)
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
93 ============================================
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
94
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
95 Bottle can be notoriously tight-lipped about what's going wrong if and
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
96 when things go wrong. (And when you're developing and debugging code,
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
97 things go wrong). TinCan tries as hard as possible to catch errors and
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
98 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
99 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
100 cause.
682cd33e564c Documentation (incomplete).
David Barts <n5jrn@me.com>
parents:
diff changeset
101
61
55828c01e38f More documenting.
David Barts <n5jrn@me.com>
parents: 60
diff changeset
102 (Note that WSGI provides no default means for logging errors, so if you're running TinCan via WSGI, it will be totally silent unless you pass ``tincan.launch`` a suitable logger. The simple test server created by the ``launch`` command always logs to standard error.)