X-Received: by 10.66.154.167 with SMTP id vp7mr62231742pab.21.1448949250071; Mon, 30 Nov 2015 21:54:10 -0800 (PST) X-Received: by 10.50.142.73 with SMTP id ru9mr190056igb.9.1448949250037; Mon, 30 Nov 2015 21:54:10 -0800 (PST) Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!mv3no6866516igc.0!news-out.google.com!f6ni15525igq.0!nntp.google.com!mv3no6866513igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Mon, 30 Nov 2015 21:54:09 -0800 (PST) In-Reply-To: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=23.30.65.94; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj NNTP-Posting-Host: 23.30.65.94 References: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4f0f7fc5-c93a-4223-9c05-e192a8fafbbd@googlegroups.com> Subject: Re: Is vars() the most useless Python built-in ever? From: Rick Johnson Injection-Date: Tue, 01 Dec 2015 05:54:10 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:99769 On Monday, November 30, 2015 at 7:01:14 PM UTC-6, Steven D'Aprano wrote: > I'm trying to understand why vars() exists. Does anyone use it? I think your "mental dilemma" stems from the fact that python was originall= y created to be an easy language for noobs to learn (which it still mostly = is), however, over the years, feature creep has expanded this small general= purpose language to include many specific applications. The "vars" functio= n is a relic of the early days of Python and has not evolved because 99% of= Python hackers find it to be useless. I mean, heck, print did not evolve u= ntil Py3! Outside of a few test sessions in my early days with Python, I do= n't remember ever using the vars function again.=20 Your lament does remind me of a pet peeve i have concerning Python, and tha= t is, the lie about: "THERE SHOULD BE ONE (AND PREFERABLY ONLY ONE) WAY TO = DO IT!". In fact, in python there is almost always *MANY* ways to achieve t= he same output.=20 For instance, consider the output of vars(), globals(), locals(), dir(), an= d obj.__dict__. In many cases, all of these, or at least most of these, wil= l return the same answer(s). Not only is that type of interface repetitive,= it superfluously obfuscates the underling paths by which the value is obta= ined.=20 We may find this difficult to believe, but many a noob has been stumped by = the following questions: (1) How do you output a message without the print function? (2) How do you fetch a listing of an object's methods without the dir funct= ion? Listen, there is nothing wrong with creating "layers of abstraction". In fa= ct, without abstractions, we could not evolve our technologies, however, if= these "layers" are not intentionally crafted in logical order, then we qui= ckly move away from the intuitive structure of a "cake model" and into the = dreaded nightmare of the "spaghetti model". We should strive to structure o= ur code in the image of a MandelBot set (think: "levels of detail"), not a = hedge maze labyrinth of an "Overlook Hotel"!