[Zope] Line Wrap and the Zope Community?

Paul Winkler slinkp23@yahoo.com
Tue, 20 Nov 2001 12:51:08 -0500


On Tue, Nov 20, 2001 at 11:41:35AM -0500, Chris McDonough wrote:
> This particular case is fixed.

I don't know what it looked like before, but the text still goes off
the screen a bit on Netscape 4.74, linux, 800x600 display.

The cause? Long lines in the code examples, which of course are in
<pre> tags and can't be wrapped. This causes the whole table to be as
wide as the largest line in a <pre> tag. In this case, the examples
aren't that long but for some reason there are 6 unnecessary blank
spaces in front of each line. Maybe a stx issue?

I see this problem all over pages on Zope.org. Very often it's due to
people posting sloppy code examples with very long lines.  I've seen
some code examples with a single line that's 120 characters long.
People, please don't do that! Not only does it make your web pages
scroll off to the right, it makes your code harder to read and
understand, which is not nice to the newbies.

For example, browsing through the links from the first page of
http://www.zope.org/Documentation/nuser: at least half of them have
this problem. Some are very hard to read. Here's a particularly long
line:

    if search_expr=='' or string.find(string.lower(o.raw),string.lower(search_expr)) != -1 or string.find(string.lower(des),string.lower(search_expr)) != -1 or string.find(string.lower(title),string.lower(search_expr)) != -1 :


Simply break up the lines and it's much nicer, like this:

    if search_expr=='' or \
       string.find(string.lower(o.raw), string.lower(search_expr)) != -1 or \
       string.find(string.lower(des), string.lower(search_expr)) != -1 or \
       string.find(string.lower(title), string.lower(search_expr)) != -1 :
        ...


Also, there's a lot of redundancy... do we need to say
string.lower(search_expr) three times? No. Assign it to a new
variable. In this case, search_expr was never used again so we can
simply reuse the name search_expr, like so:

    search_expr = string.lower(search_expr)
    if search_expr=='' or \
       string.find(string.lower(o.raw), search_expr) != -1 or \
       string.find(string.lower(des), search_expr) != -1 or \
       string.find(string.lower(title), search_expr) != -1 :
        ...


Another variation... at this point it's definitely a matter of taste
(and maybe optimization):

    from string import find, lower
    search_expr = lower(search_expr)
    if search_expr=='' or \
       find(lower(o.raw), search_expr) != -1 or \
       find(lower(des), search_expr) != -1 or \
       find(lower(title), search_expr) != -1 :
        ...


-- 

paul winkler
home:  http://www.slinkp.com
music: http://www.reacharms.com
calendars: http://www.calendargalaxy.com