Functional Programming: WAS: Too Self Centered

beno zope at thewebsons.com
Tue Jan 7 21:59:11 EST 2003


At 01:55 AM 1/8/2003 +0000, you wrote:
>Python is very "self" centered! :-)
>
>Your code is correct, and typical of Python.  Python programmers type
>"self" a lot.  It is commonly complained about, but after programming
>in Python for a while, now I prefer it.
>
>You are not required to read "Style Guide for Python Code; PEP8", but
>it is highly recommended:
>
>http://www.python.org/peps/pep-0008.html

Will do.


>You can get rid of some "self"s by using
>"x += 1" instead of "x = x + 1"
>You use "+=" inconsistently.

Right.


>Indent more than 1 space, Python uses indentation exclusively to
>specify code blocks, so it helps to be able to see indents clearer.
>Most people use 4 spaces.  Any coder's text editor will make this easy
>for you.

Two comments on that. Will do.


>Your program will blow up reading a large file because of your
>recursive use of "subsequentRead(self)" and "subsequentLines(self)".
>The form of recursion you are using is called "tail-recursion".
>Python does not optimize tail-recursion.  Outside of the LISP world,
>tail-recursion is not used (and rarely optimized).  A "while" loop
>would be better.

Hmmm. I'm really sold on the philosophical merits of *Functional 
Programming*.  But I appreciate any feedback you have concerning 
optimization here. I need to stick with Python because I'm addicted to Zope ;)


>Instead of "maketrans" and "translate", just use "replace".

Thank you :))


>I have no idea what your code is supposed to do, I will guess you wish
>to count how many lines in a file, and then turn the newlines into
>spaces to turn the multiline file into one long string.

I'm preparing a Zope product. I've long wanted a script that could receive 
input from a text file and convert it to a select/options drop-down box 
that a visitor could click revealing the testimonial like this:

<select>
<option>See what John Doe has to say!</option>
  <option>&#xa0;</option>
  <option>This is my testimonial. Aint</option>
  <option>it cool. I just think you're</option>
  <option>the best thing since sliced</option>
  <option>bread. Love ya! Line 3 </option>
  <option>&#xa0;</option>
  <option>John Doe  </option>
</select>

My background is marketing and this can be used everywhere without taking 
up much screen space (real estate). It's a brilliant marketing move I 
scooped from site-sell.com years ago. This product will go inside another 
product called *Easy Site* that people new to Zope can use to easily 
template complex sites for *brochureware*: just the kind of thing I would 
have liked two years ago.

Thanks for the code sample below. I'll rewrite :))
beno







More information about the Python-list mailing list