From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id AC161138825 for ; Tue, 11 Nov 2014 00:17:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 87A36E07FA; Tue, 11 Nov 2014 00:17:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0D32CE07F9 for ; Tue, 11 Nov 2014 00:17:38 +0000 (UTC) Received: from [192.168.1.7] (ip70-181-96-121.oc.oc.cox.net [70.181.96.121]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id 13626340494 for ; Tue, 11 Nov 2014 00:17:38 +0000 (UTC) Message-ID: <5461559F.2050808@gentoo.org> Date: Mon, 10 Nov 2014 16:17:35 -0800 From: Zac Medico User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.8.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 To: gentoo-portage-dev@lists.gentoo.org Subject: Re: [gentoo-portage-dev] [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR References: <1415575480-19505-1-git-send-email-zmedico@gentoo.org> <54609D06.5020101@gentoo.org> <54610217.3080707@gentoo.org> <546120FA.9060305@gentoo.org> In-Reply-To: <546120FA.9060305@gentoo.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: fabdcfef-bdcd-4d87-9a30-30c04de7759a X-Archives-Hash: df1d987be357259a4710eb8bb91560aa On 11/10/2014 12:32 PM, Alexander Berntsen wrote: > On 10/11/14 19:21, Zac Medico wrote: >> Well, you'll have to clarify what's so "terrible" about it. Note that I didn't >> use os.path.isdir or similar because those functions hide all kinds of relevant >> exceptions, such as EACCES. > I wish there were a more declarative way of expressing this in Python. > It's extremely imperative. We could certainly express it in a way that doesn't involve any mutating loop control variables, but ultimately that's going to lead to more lines of code, and it will leave imperative programmers wondering why we didn't choose a simpler and more succinct approach. For example, we could create an class for iterating over the paths from a given path down to the root directory. Then we could create a function which selects the first element from that iterator that exists. Once the class and function are implemented, their usage would be very succinct: first_parent = first_existing(iter_parents(path)) -- Thanks, Zac