Sharing: File Reader Generator with & w/o Policy

Mark H Harris harrismh777 at gmail.com
Sun Mar 16 00:47:30 EDT 2014


On 3/15/14 10:48 PM, Chris Angelico wrote:
> There's a cost to refactoring. Suddenly there's a new primitive on the
> board - a new piece of language . . . Splitting out all sorts of things into
> generators when you could use well-known primitives like enumerate
> gets expensive fast {snip}
>
>
> [1] https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)

Very good to remember. I am finding the temptation to make all kinds of 
generators (as you noted above). Its just that the python generator 
makes it so easy to define a function that maintains state between calls 
(of next() in this case) and so its also so easy to want to use them... 
almost forgetting about primitives!

And the rule of three is one of those things that sneaks up on oneself. 
I have actually coded about seven (7) such cases when I discovered that 
they were all identical. I am noticing that folks code the same file 
reader cases "with open() as fh: yadda yadda"  and I've noticed that 
they are all pretty close to the same. Wouldn't it be nice to have one 
simpler getline() or getnumline() name that does this one simple thing 
once and for all. But as simple as it is, it isn't. Well, as you say, 
use cases need to determine code refactoring.

The other thing I'm tempted to do is to find names (even new names) that 
read like English closely (whatever I mean by that) so that there is no 
question about what is going on to a non expert.

for line in getnumline(file):
       {whatever}

Well, what if there were a project called SimplyPy, or some such, that 
boiled the python language down to a (Rexx like) or (BASIC like) syntax 
and usage so that ordinary folks could code out problems (like they did 
in 1964) and expert users could use it too including everything else 
they know about python? Would it be good?

A SimplyPy coder would use constructs similar to other procedural 
languages (like Rexx, Pascal, even C) and without knowing the plethora 
of Python intrinsics could solve problems, yet not be an "expert".

SimplyPy would be a structured subset of the normal language for 
learning and use (very small book/tutorial/ think the Rexx handbook, or 
the K&R).

Its a long way off, and I'm just now experimenting. I'm trying to get my 
hands around context managers (and other things). This is an idea I got 
from Anthony Briggs' Hello Python! (forward SteveHolden) from Manning 
books.  Its very small, lite weight, handles real work, but--- its still 
too big. I am wanting to condense it even further, providing the minimal 
basic core language as an end application product rather than the 
"expert" computer science language that will run under it.

or, over it, as you like.

(you think this is a nutty idea?)

marcus



More information about the Python-list mailing list