[Python-ideas] Framework for Python for CS101

Rustom Mody rustompmody at gmail.com
Tue May 26 16:55:36 CEST 2015



On Tuesday, May 26, 2015 at 7:16:18 PM UTC+5:30, Terry Reedy wrote:
>
> On 5/26/2015 2:07 AM, Chris Angelico wrote: 
> > On Tue, May 26, 2015 at 3:54 PM, Terry Reedy <tjr... at udel.edu 
> <javascript:>> wrote: 
>
> >> Programming is composition, the connections of outputs to inputs (as 
> with 
> >> circuit design).  'Print' is the enemy of composition. We agree so far. 
> > 
> > That's fine as long as it's okay to produce no results whatsoever 
> > until all processing is complete. 
> > In a pure sense, yes, a program's 
> > goal is to produce output, and it doesn't make a lot of difference how 
> > that output is produced. You can build a web framework in which the 
> > only way to send a result is to return it from a function. But there 
> > are innumerable times when it's more useful to produce intermediate 
> > output; whether that output goes to a file, a socket, the console, or 
> > something else, it's as much a part of real-world programming as 
> > returned values are. 
>
> The context is a beginning programming course where the goal is to teach 
> people to write 
>
> def f(a, b, c): return a*b + c 
> print(f(2, 3, 4)) 
>
> instead 
>
> def f(a, b, d): print(a*b + c) 
> f(2, 3, 4) 
>
> In other words, to teach beginners to relegate output to top level code, 
> separate from the calculation code. (Or perhaps output functions, but 
> that is a more advanced topic.)  The first function is easy testable, 
> the second is not. 
>

Thanks Terry for the elucidation
 

>
> For printing intermediate results, yield lines to top-level code that 
> can do whatever with them, including printing. 
>
> def text_generator(args): 
>     ... 
>         yield line 
>
> for line in text_generator: print(line) 
>
> is top-level code that prints intermediate results produced by a 
> testable generator. 
>
>
And thanks-squared for that.
Generators are a really wonderful feature of python and not enough 
showcased.
Think of lazy lists in haskell and how much fanfaring and trumpeting goes 
on around these.
And by contrast how little of that for generators in the python world. Are 
the two all that different?

You just have to think of all the data-structure/AI/etc books explaining 
depth-first-search and more arcane algorithms with a 'print' in the innards 
of it.
And how far generators as a fundamental tool would go towards 
clarifying/modularizing these explanations 

So yes generators are an important component towards the goal of 
'print-less' programming

> People want to see results, which is half of why I said not to delete 
> print.  But proper assignments and grading can enforce separation of 
> calculations from use of results.  The idea of separation of concerns 
> did not start with OOP. 
>
> -- 
> Terry Jan Reedy 
>
> _______________________________________________ 
> Python-ideas mailing list 
> Python... at python.org <javascript:> 
> https://mail.python.org/mailman/listinfo/python-ideas 
> Code of Conduct: http://python.org/psf/codeofconduct/ 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150526/1267cb3d/attachment.html>


More information about the Python-ideas mailing list