[Tutor] Simple Python Program

Luke Paireepinart rabidpoobear at gmail.com
Sun Aug 1 05:51:41 CEST 2010


I think I agree more with bob on this one - he wasn't saying functions weren't important, just that they weren't important to this case. Sure polymorphism and inheritance and properties and generators and list comprehensions are awesome and useful, but I wouldn't suggest they are necessary for every situation.  Same with Functions. That's just the trap that java fell into by making everything an object... It just adds a couple of useless lines that will just serve to confuse newbies and irritate pros.
IMHO.

Sent from my iPhone

On Jul 31, 2010, at 10:11 PM, bob gailer <bgailer at gmail.com> wrote:

> On 7/31/2010 8:24 PM, Steven D'Aprano wrote:
>> On Sun, 1 Aug 2010 04:35:03 am bob gailer wrote:
>>   
>>> Continue to avoid writing functions. They are not necessary for such
>>> a simple program.
>>>     
>> That is *terrible* advice. Absolutely awful.
>>   
> 
> Well I disagree. I was trying to steer the OP to get the simplest possible program running, then do incremental expansion.
> 
> In my understanding user defined functions serve these purposes:
> 1 - modularizing large programs
> 2 - factoring out common code
> 3 - providing callbacks
> 4 - choosing callable objects from some collection.
> 5 - providing a main function for the if __name__ == "__main__" idiom
> 6 - what else can we think of?
> 
> None of these are needed in this simple case.
> 
>> Functions should not be avoided unless necessary. Functions should be
>> used unless there is a compelling reason to avoid them.
>>   
> 
> Once the OP has succeeded in getting some program running he will experience some relief and satisfaction. Then I think it is time to add language features. But not just for the sake of using them.
>> This is not 1972 any more, and we're not teaching kids to write
>> spaghetti code with BASIC and GOTO.
> 
> Functions have no relationship to avoiding spaghetti code. Python makes spaghetti code impossible since it lacks a goto or equivalent statement.
> 
>> Functions, or their object-oriented
>> equivalent methods, are *the* single most important feature of
>> programming. And they're simple too
> 
> Well - almost simple. Until you get into issues like global vs local names, positional vs keyword arguments, required vs optional arguments, default values (especially mutable objects), * and **, generator functions, magic methods, nested defs, decorators, ....
> 
>> -- they might not be the first thing you teach an absolute newbie who has never programmed before
> 
> That is what our OP appears to be.
> 
> -- 
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list