From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Brooks Newsgroups: gmane.emacs.devel Subject: lengths and stuff Date: Sat, 26 Dec 2020 20:58:58 -0800 Message-ID: <87czyvsv3h.fsf_-_@db48x.net> References: <87o8ivumn5.fsf@telefonica.net>> > <83h7odrdwy.fsf@gnu.org>> <86sg7w39fh.fsf@163.com>> <83pn30pku5.fsf@gnu.org>> <86wnx8otoj.fsf@163.com>> <834kkbp9vr.fsf@gnu.org>> <87czyxuxw6.fsf@db48x.net>> <87y2hlt82w.fsf@db48x.net>> <87lfdlvsw4.fsf@logand.com>> <83h7o8ncly.fsf@gnu.org>> <87pn2wudab.fsf@db48x.net>> <87mty0c3m1.fsf@gnus.org>> <83czywnb86.fsf@gnu.org>> <87im8ob707.fsf@gnus.org>> <87eejcb6nx.fsf@gnus.org>> > <875z4ob5c9.fsf@gnus.org>> > <83mtxzly4f.fsf@gnu.org>> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11423"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: larsi@gnus.org, Eli Zaretskii , Stefan Monnier , emacs-devel@gnu.org To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 27 05:59:59 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktO9u-0002qQ-G4 for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Dec 2020 05:59:58 +0100 Original-Received: from localhost ([::1]:52164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktO9t-0007o5-Iv for ged-emacs-devel@m.gmane-mx.org; Sat, 26 Dec 2020 23:59:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktO9A-0007Nc-6S for emacs-devel@gnu.org; Sat, 26 Dec 2020 23:59:12 -0500 Original-Received: from smtp-out-4.mxes.net ([2605:d100:2f:10::315]:26660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktO97-0001Xs-6u for emacs-devel@gnu.org; Sat, 26 Dec 2020 23:59:11 -0500 Original-Received: from Customer-MUA (mua.mxes.net [10.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 0BCC9759BD; Sat, 26 Dec 2020 23:58:59 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mxes.net; s=mta; t=1609045142; bh=0O1vMQkOG7qlNlTgH9lcAiUWJR5Ywo83VVPqJ27t/7g=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type; b=P5oc/CPWPChnqO5pF2Co9cdPk7wVJ347HwwaPjR6GsZFMJMO2//MRBk46MOZpCXQb qYMekINBjH3GLfCrUSrCtcAD7JTxeeGCR6p8AA4EK1bQB/QC13aqan0Xp6pEu0Y2we vTpfvNzLwgrUX8UXLZ1YxaDYRljAu4ffODyHDx6Y= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGOfPtRkwAAABJQ TFRFpKfbdou67PD6JjJgAwUWXGSeIcyLHgAAAkZJREFUOI1VU8Fy6yAMxLi+Q13fCZ3cnQL3dqTc 7RD+/1feStDXVnXHDuvVSivZTMba2GPdw3gyCGcMAFxTyrTd9dwGoxHiZX9PmRFUHYAQlGGtXY+F Uk0SJOxgJiUEnH1qkitT9D+pQub7qGAmUbR6bu3CvI96Yv6QqkBBMrsyfZccr1/RDXGDTLf4P7ZY glVxe2V+/ACXWO1gvDO9/gDRpFFVmPluvLcmBjd5H6d8DEte+Pbk4rcY/Fa5tLKLOtCZsuQKYhpa LOkYDT7hESya7/WIET3lfQBqX0pwFtbI832Is0ayMUR9B+12xjgPCQ089cfwkCkX6L5TPmRelJTh zMS0Sz1PyjLAMCUWjcmgQLWQMds+e3aaauZDf9dU9A2/8kPVF2odCUoMKHkfjJR+mbgC+DRiycw5 3XSqGe6HmhN/AWjHypkAXOAFW5EiuA1ge2GiZuMb0s1fSEXcATeLUfbyEY2L8yPOmdSsdghQXx3K pz2eoeXuYvMCINVFDrCdNfVUp4eJ6cSEbjbgFjBEvonGGTrgv9cHjAc8aVgSAPoxaONbzfwhDIhR at7IIS7fAGiDSwIA9alhhTBzfA7YM2FY6eMwayrIGK8FDFmshmUA43WqhFtpvoqG9HHaJ7fqtgTz 8EWVkgZgtsylFliHDgk0MB7KAEC45C/rgnGvanNLXyzOeTzcT2nw/N44gfrtYXRQLoz9Q3TgmJRx 2Mx/Q51qzpm+l3m8z2SWBqC5+PZXAtNYlGFf/gKfHfjFkDT4x7od7R+w3Ls+ZdQBuQAAAABJRU5E rkJggg== In-Reply-To: (Drew Adams's message of "Sat, 26 Dec 2020 20:03:59 -0800 (PST)") X-Sent-To: Received-SPF: none client-ip=2605:d100:2f:10::315; envelope-from=db48x@db48x.net; helo=smtp-out-4.mxes.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:261880 Archived-At: Drew Adams writes: > With that "solution" you've only added a new problem: you > now need to advertise the new functions and advise users > to use them, not `length', in such a use case. Which > means you still have the need to identify the relevant use > cases, which means teach them about the `length' gotcha > (or hope they follow advice without understanding). IOW, > now you have 2 problems... Users certainly do need to know the performance cost of the functions that they use. But they also need alternatives. If (> (length list) n) is a trap for new players, then document it as so _and_ mention that there is a specific function that can be used to avoid the trap. But it's also worth mentioning that maybe the code should use a vector instead of a list, if the length is so important. Also, as was pointed out, this very thing happens 735 times in the Emacs lisp codebase. Probably most of those have no great performance impact, but it's a good observation. > [Personally, in the case considered, I'd use (cdr x). > I wouldn't use (not (null (cdr x))). And it doesn't > get simpler _or clearer_ than that, IMO.] True. It's not the first time I've noticed myself making something more complicated by eagerly converting to a boolean. But I still don't think that it's readable code. db48x