comparison doc/philosophy.rst @ 61:55828c01e38f draft

More documenting.
author David Barts <n5jrn@me.com>
date Sun, 09 Jun 2019 10:37:45 -0700
parents 682cd33e564c
children
comparison
equal deleted inserted replaced
60:682cd33e564c 61:55828c01e38f
22 Keep It Simple, Stupid 22 Keep It Simple, Stupid
23 ====================== 23 ======================
24 24
25 I wanted to get on with the business of actually *using* TinCan to do things, 25 I wanted to get on with the business of actually *using* TinCan to do things,
26 so I didn't clutter it up with extra features that would be difficult to 26 so I didn't clutter it up with extra features that would be difficult to
27 implement. (That's why there's currently no way to choose alternate templating engines 27 implement. (That's why there's currently no way to choose templating engines
28 to Chameleon. I tried to do that, and it proved overly complex. Maybe some day.) 28 other than Chameleon. I tried to allow that, and it proved overly complex. Maybe some day.)
29 29
30 =========================== 30 ===========================
31 Don't Be Gratuitously Bossy 31 Don't Be Gratuitously Bossy
32 =========================== 32 ===========================
33 33
44 =========== 44 ===========
45 Code-Behind 45 Code-Behind
46 =========== 46 ===========
47 47
48 It's maligned by many, but I personally like it, and it 48 It's maligned by many, but I personally like it, and it
49 does *not* necessarily mean repudiating the MVC paradigm. 49 does *not* necessarily mean repudiating the MVC paradigm (see :ref:`mvc-different-forms`).
50 50
51 ===================== 51 =====================
52 Don't Repeat Yourself 52 Don't Repeat Yourself
53 ===================== 53 =====================
54 54
57 by controller foo \(which defines variables bar, baz and blort\), which uses template foo 57 by controller foo \(which defines variables bar, baz and blort\), which uses template foo
58 \(which renders variables bar, baz and blort\)." This is completely unnecessary; 58 \(which renders variables bar, baz and blort\)." This is completely unnecessary;
59 the relationships should be obvious by virtue of the similar names. The framework should figure 59 the relationships should be obvious by virtue of the similar names. The framework should figure
60 it out and just "do the right thing" by default. 60 it out and just "do the right thing" by default.
61 61
62 .. _mvc-different-forms:
63
62 ============================ 64 ============================
63 MVC Comes in Different Forms 65 MVC Comes in Different Forms
64 ============================ 66 ============================
65 67
66 If you show a little discipline, the template page will describe how data 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.
67 is presented to the user, and how he or she can interact with it. A view
68 by any other name is still a view. The code-behind will tie that view into
69 the underlying business logic, and bridge the gap between the two. A controller
70 by any other name is still a controller.
71 69
72 If you don't show discipline, you can clutter your templates up with bits 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.
73 of Python code that represent controller logic, and clutter your controller up with
74 bits of presentation details. Of course you can. That's not the framework's
75 fault; that's the programmer's fault. Bad code can be written in any language,
76 for any platform.
77 71
78 ================================================== 72 ==================================================
79 The Alternative is PHP or CGI, not Django or Flask 73 The Alternative is PHP or CGI, not Django or Flask
80 ================================================== 74 ==================================================
81 75
82 I'm not the only one out there who doesn't like all the repeating yourself 76 I'm not the only one out there who doesn't like all the repeating yourself
83 that most MVC frameworks make you do. There's still *a lot* of developers 77 that most MVC frameworks make you do. There's still *a lot* of developers
84 out there writing CGI scripts or using PHP, because CGI and PHP don't make 78 out there writing CGI scripts or using PHP, because CGI and PHP don't make
85 you do all the busywork that frameworks do. (Can they be blamed? It really 79 you do all the busywork that most frameworks do. (Can they be blamed? It really
86 feels silly when all you want is to get a quick, small site up.) 80 feels silly when all you want is to get a quick, small site up.)
87 81
88 That's a pity, because CGI is hideously inefficient and PHP is, well, just 82 That's a pity, because CGI is hideously inefficient and PHP is, well, just
89 plain hideous. \(A root namespace with literally *thousands* of builtins 83 plain hideous. \(A root namespace with literally *thousands* of builtins
90 cluttering it up, builtins with *no* consistent naming convention? Ugh!\) 84 cluttering it up, builtins with *no* consistent naming convention? Ugh!\)
91 85
92 Hopefully, by making it easier for people to code efficient web sites using 86 Hopefully, by making it easier for people to code efficient web sites using
93 a well-designed language that's easy to learn, I'll encourage more people 87 a well-designed language that's easy to learn, I'll encourage more people
94 to create efficient sites in a well-designed language. If not, well, at least 88 to create efficient sites in a well-designed language. If not, well, at least
95 I'll encourage *myself* to do so. 89 I'll enable *myself* to do so.
96 90
97 ============================================ 91 ============================================
98 Meaningful Error Messages (If You Want Them) 92 Meaningful Error Messages (If You Want Them)
99 ============================================ 93 ============================================
100 94
103 things go wrong). TinCan tries as hard as possible to catch errors and 97 things go wrong). TinCan tries as hard as possible to catch errors and
104 log them. Enable logging, and when you see a 500 error, you will almost 98 log them. Enable logging, and when you see a 500 error, you will almost
105 always have a log file with a traceback in it helping to pinpoint the 99 always have a log file with a traceback in it helping to pinpoint the
106 cause. 100 cause.
107 101
108 That is, assuming you enable logging. By default, it is turned off, simply 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.)
109 because WSGI provides no default place for errors to go.