[Tutor] Can anyone help answer this?

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jun 11 05:00:33 EDT 2020


On 10/06/2020 15:31, Peter Otten wrote:

>> And the Pythonic way of building lists is a list comprehension.
>> So this whole exercise should be reduced to:
>>
>> food_list = [Food(t) for t in tuple_list]
> 
> You forgot the * which I think is an advanced and even somewhat questionable 
> feature. 

You are right, but its not needed here. We could still use a
comprehension with:

food_list = [Food(name,taste) for name,taste in tuple_list]

utilising tuple unpacking.


> which gives opportunities to show
> 
> - idiomatic iteration
> - tuple unpacking
> - good ways for a function to communicate with its caller.
> 
> You may argue that this should have been taught before starting with custom 
> objects...

Yes, that was my point. The exercise appears to be all about
instantiating objects, but then misses the whole point of
having objects in the first place - that the functionality
resides inside the object. Encouraging students to create
functions that just use the constructor to return a list
is bad practice and also teaching a bad way of thinking.
It is exactly this kind of teaching that results in the
poor understanding of OOP that we see so often today.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list