[issue20496] function definition tutorial encourages bad practice
New submission from Alan Isaac:
Section 4.6 of the tutorial introduces function definition:
http://docs.python.org/3/tutorial/controlflow.html#defining-functions
The first example defines a function that *prints* a Fibonacci series.
A basic mistake made by students new to programming is to use a function to print values rather than to return them. In this sense, the example encourages bad practice and misses an opportunity to instruct. Since they have already met lists in Section 3, I suggest that returning a list of the values and then printing the list would enhance the tutorial.
----------
assignee: docs@python
components: Documentation
messages: 210077
nosy: aisaac, docs@python
priority: normal
severity: normal
status: open
title: function definition tutorial encourages bad practice
type: enhancement
_______________________________________
Python tracker
Terry J. Reedy added the comment:
There is a later example introduced by "It is simple to write a function that returns a list of the numbers of the Fibonacci series, instead of printing it:" that does exactly what you suggest.
----------
nosy: +terry.reedy
_______________________________________
Python tracker
Berker Peksag added the comment:
I agree with Terry. The print example is also useful to show the implicit return value of fib(). Quoting from the same section:
[...] In fact, even functions without a return statement do return a value, albeit a rather boring one. This value is called None [...]
----------
nosy: +berker.peksag
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker
participants (3)
-
Alan Isaac
-
Berker Peksag
-
Terry J. Reedy