[Tutor] Re: first program

Andrei project5 at redrival.net
Sat Dec 6 10:48:42 EST 2003


RoT wrote on Sat, 06 Dec 2003 21:36:46 +0800:

<snip>
>> Paragraph 2.2.6.1 of the Library raference (Built-in objects -> Built-in
>> types -> Sequence types -> String methods).
> 
> mmm, I worked through 'python for non-programmers' and then 'Learning Python' by Mark Lutz and David
> Ascher, which I now realise was updated last in 2000. I suppose I now need to locate some sort of
> changelog to study or a more up to date tutorial.

String methods were introduced in v 2.0:
http://www.python.org/2.0/new-python.html

Btw, you might also be interested in the Python Quick Reference
(http://rgruet.free.fr/). It labels things with different colors based on
the version they were introduced in and is a very useful piece of info.

>>>> Last comment for now: the last main() method might be a bit long; you may
<snip>
> mmm, without any guidance on the matter I decided to write into functions code that was to be
> reused, and code that sort of stuck out on its own. In hindsite I could have put it all into

That's a very good principle of course. But you really shouldn't have code
blocks of 100+ lines because it's hard to see what's going on - maintenance
problem. How long code blocks can maximally be depends on all kinds of
factors, but I think that the amount you can see on a single screen is a
useful rule of thumb - though obviously that depends on the size of the
screen, size of the font, etc :).

> functions and only have 10 or 20 'main()' lines but I was not sure this would aid the readibility,
> I presumed a more structural approach with a functional/oo approach when needed for code reuse,

It's not very hard to see that (to quote an example I gave in my previous
message) all code for getting the login info from the user is really a
piece that can stand on its own quite comfortably. I'm sure if you look at
your code critically you can find more such pieces.

> would be the way to go. Are you advocating putting as much code as possible into functions?

Yep, but obviously code inside a function should belong together, it
shouldn't be in a function just so that it's not written inside the main()
loop. Functions also make it easier to browse your code if you have an
editor which shows an outline of your classes/methods.
<snip> 
> The thing is, that its
> hard to find nice applications this size written in python to study, from what I have found they
> are either scraps of code/functions or large, overly (complex) modular frameworks using a variety
> of shell/languages

Have you looked at uselesspython.com? I can also point you to two of my own
programs: http://project5.freezope.org/mathter/index.html/# (almost
entirely procedural programming, about 1k lines) and
http://project5.freezope.org/kiki/index.html/# (wxPython based, about 500
lines). I'm not claiming they're perfect - in fact Kiki contains a function
close to 100 lines long - but you can learn from mistakes just as well as
you can learn from perfection :).

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.




More information about the Tutor mailing list