Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Can global variable be passed into Python function? Date: Sat, 01 Mar 2014 02:03:51 +0200 Organization: A noiseless patient Spider Lines: 46 Message-ID: <87ob1qeqe0.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <531115e1$0$29985$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="7795"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zLAnDv2pog3zHb9Sc0jE5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:dKPScbc8oALe/KyvdhFnUgHoE6A= sha1:5c0j4acOhQSe1pOfsU+k7eJzN+U= Xref: csiph.com comp.lang.python:67258 Steven D'Aprano : > You can't have it both ways: you cannot claim that switch or case is > more readable than a chain of if...elif, and then propose a syntax > which is effectively a chain of if...elif while still claiming it is > an improvement. It's not. All you've done is introduce an element of > implicit magic to the syntax. You may be right that Python has too many practical problems for a truly fitting switch syntax. > Why (how?) would you want to use *multiple* classes for a single > switch? Well, I was just given a whole link on the very topic: Here's a shorter one: Anyway, while implementing states as singleton inner class instances is elegant and highly readable, the technique suffers in one significant respect: it can be very slow. Often a state machine has numerous states but the typical execution path only visits a few of them. However, the pattern calls for declaring classes (or instances) for all states in the state machine constructor. Switch statements make it possible to avoid this creation overhead. > Dict dispatch tables are elegant, attractive and efficient if you are > using pre-existing functions or functions you can create using lambda: I beg to differ. The dict dispatch tables are very hard to read. The fully blown-out if-else chain beats it in elegance hands down. > There are all sorts of simple and neat ways to handle switches in > Python. That's why the pressure on the language to grow special syntax > is quite low. It simply isn't important enough. Of course the threshold for new syntax should be exceptionally high. Python as a language is already close to the sweet spot. Marko