Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'beginner': 0.05; 'subject:Python': 0.06; '(of': 0.07; 'cure': 0.07; 'plenty': 0.07; 'result,': 0.07; 'string': 0.09; '"""add': 0.09; '"my': 0.09; 'beginners': 0.09; 'function,': 0.09; 'subject:skip:c 10': 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '"default': 0.16; 'backward': 0.16; 'belongs': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'highlight': 0.16; 'loops': 0.16; 'on"': 0.16; 'ought': 0.16; 'personally,': 0.16; 'reusable': 0.16; 'subject: \n ': 0.16; 'subject:between': 0.16; 'subject:programming': 0.16; 'those,': 0.16; 'utterly': 0.16; 'y):': 0.16; 'language': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'library': 0.18; 'wed,': 0.18; 'examples': 0.20; 'meant': 0.20; 'written': 0.21; 'cc:addr:python.org': 0.22; 'print': 0.22; 'precise': 0.24; "shouldn't": 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'this:': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'feature': 0.29; 'on,': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'usually': 0.31; '13,': 0.31; 'agreed.': 0.31; 'boundary': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:that': 0.31; 'there.': 0.32; 'probably': 0.32; 'everyone': 0.33; 'cases': 0.33; 'not.': 0.33; 'totally': 0.33; 'actual': 0.34; 'maybe': 0.34; "i'd": 0.34; 'problem': 0.35; 'problem.': 0.35; 'something': 0.35; 'beyond': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'returning': 0.36; "didn't": 0.36; 'useful': 0.36; 'subject:?': 0.36; 'should': 0.36; 'effort': 0.37; 'application': 0.37; 'turn': 0.37; 'list': 0.37; 'clear': 0.37; 'generic': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'sure': 0.39; 'enough': 0.39; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'dangerous': 0.60; 'most': 0.60; 'took': 0.61; 'simply': 0.61; "you're": 0.61; 'times': 0.62; 'complete': 0.62; 'advanced': 0.63; 'show': 0.63; 'more': 0.64; 'finally': 0.65; 'kept': 0.65; 'virus': 0.65; 'between': 0.67; 'it!': 0.67; 'real- world': 0.68; 'skip:w 40': 0.68; 'wish': 0.70; '2015': 0.84; 'dict,': 0.84; 'directory:': 0.84; 'off"': 0.84; 'off,': 0.84; 'subject: *': 0.84; 'this...': 0.84; 'tie': 0.84; 'treats': 0.84; 'procedural': 0.91; 'subject:Good': 0.91; 'to:none': 0.92; 'differences': 0.93; 'instructors': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=KdsyrpCJJfKVHmSn5+Z3PngHSsS3b1tJQmZ7LUgITZY=; b=LIQW+8yJjKhOsXcUmmWQXxmp9W4xOqMwgR2mC+fxTlXygWUpzY89obPx7BCbMBmtQu i7aXOx7IfpGnbcDNRKyKjoa2ezw803O22fqBnZMRgjMqusVv2yaV8RqpyrQM3lzOMH2a 8DTERoFcyqkpvA/26OYGnfXnSABWOhSDyIYXI78/8jQcpHZKKe3hM+Z5Ity5ivRMbQ/4 V9ZxaeRfvlmBnjVu/k16sgUlKS+B7HRrOUTLwKGij2OsqUHH6cC6iheUOvEObllnYytg nduE2qiQJTi8YzhK9tKipf8aTqV+5raHFTAjsqgmbLs0e8FEVvVEFmSojnjLGnBbdrOX EJaw== MIME-Version: 1.0 X-Received: by 10.107.134.206 with SMTP id q75mr24060546ioi.27.1431492900044; Tue, 12 May 2015 21:55:00 -0700 (PDT) In-Reply-To: <5552a591$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <02dba7aa-8466-4937-a8d8-82ffd03e5568@googlegroups.com> <87wq0gyvyr.fsf@elektro.pacujo.net> <55515f9d$0$12987$c3e8da3$5496439d@news.astraweb.com> <60c01c07-aef9-4232-92cd-22e6c017fc9c@googlegroups.com> <4628bce6-98d5-44b7-bb3b-bcb796c0df77@googlegroups.com> <5552a591$0$12979$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 13 May 2015 14:54:59 +1000 Subject: Re: Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 93 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431492908 news.xs4all.nl 2895 [2001:888:2000:d::a6]:51861 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90526 On Wed, May 13, 2015 at 11:14 AM, Steven D'Aprano wrote: > On Wed, 13 May 2015 02:05 am, Chris Angelico wrote: > >> So if you're writing a library function, it probably shouldn't use >> print()... but your application is most welcome to. You usually know >> which one you're writing at any given time. > > You might be, but beginners are not. I meant the generic "you" there. A beginner may well not know whether to use / or //, whether it's better to use a list or a dict, etc etc etc. That's what instructors are for. Make the distinction that library functions shouldn't use print but application code can, and then examples like this... > I'm not sure I accept Rustom's fix for the problem (I think that his cure is > worse than the disease), but it is *hard* to get some beginners to use > return instead of print: > > def add_twice(x, y): > """Add twice y to x.""" > print x + 2*y > > > sort of thing. ... can be answered simply by explaining that "add_twice" ought to be written as a library function rather than an application. It's the exact same answer as this: def find_all_whatevers(base_dir): whatevers = [] os.chdir(base_dir) for fn in os.listdir(): if fn is a whatever: whatevers.append(fn) if fn is a directory: whatevers.extend(find_all_whatevers(fn)) return whatevers The working directory belongs to the application, not to a library function, so this shouldn't use os.chdir(), even though it does spare you the effort of string manipulation. (Of course, a real-world version of this should use os.walk(), but that's a complete rewrite.) The precise boundary between reusable functions and the actual application isn't always easy to draw, and there'll be times when you refactor something across that line. That's not a problem. There are still plenty of cases that are clear enough to use for explanation. > Personally, I think that banning print is only useful if you wish to > encourage cargo-cult programming: > > "Don't use print!" > "Why not?" > "My CS lecture said not to use it! I dunno, maybe it has a virus or > something." Agreed. There are VERY few features which should be utterly and totally banned, and they're usually kept only for backward compatibility with a time when people didn't know how dangerous they were. In Python, the only one I can think of is Py2's input(), which should be treated as XKCD 292 treats GOTO. (If you really *do* want to take a string from the user and immediately eval it, just write it as "eval(raw_input())" so everyone knows.) C has gets(), which is similarly dangerous and has a similarly straight-forward replacement. PHP has register_globals (or did until recently - it took a long time to go from "default is on, we recommend you turn it off" through "default is off, we recommend you don't turn it on" to finally "bad feature is removed"). Beyond those, there's not much that doesn't have at least _some_ reason for existing. > I'd rather give them exercises designed to show (rather than tell) the > differences between printing a result and returning a result, and how they > effect re-usability of software components and function chaining. Using a > procedural language is *perfect* for that, since you can highlight the > differences: > > function foo(n:int): int; > begin > foo := n+1; > end; > > procedure foo(n:int); > begin > writeln(n+1); > end; Yep. I'd also use clear function/procedure names to make it more visible, and probably tie this in with loops to show how you can print more than one thing but can only return one. (Generators are a more advanced topic.) A few examples go a long way. ChrisA