From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: proposal to make null string handling more emacs-y Date: Wed, 25 Apr 2012 16:51:04 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1335365497 8112 80.91.229.3 (25 Apr 2012 14:51:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 25 Apr 2012 14:51:37 +0000 (UTC) Cc: emacs-devel@gnu.org To: Steve Yegge Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 25 16:51:34 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SN3Z5-0007OZ-FW for ged-emacs-devel@m.gmane.org; Wed, 25 Apr 2012 16:51:31 +0200 Original-Received: from localhost ([::1]:45360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN3Z4-0007wt-WD for ged-emacs-devel@m.gmane.org; Wed, 25 Apr 2012 10:51:31 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN3Z0-0007wK-U9 for emacs-devel@gnu.org; Wed, 25 Apr 2012 10:51:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SN3Yu-0001W5-IM for emacs-devel@gnu.org; Wed, 25 Apr 2012 10:51:26 -0400 Original-Received: from hermes.netfonds.no ([80.91.224.195]:47458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN3Yu-0001Ur-B7 for emacs-devel@gnu.org; Wed, 25 Apr 2012 10:51:20 -0400 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58] helo=stories.gnus.org) by hermes.netfonds.no with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1SN3Yf-0000RF-K7; Wed, 25 Apr 2012 16:51:05 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEUxLi8UDg8HAgMNBwh9 c2Xc1q1ZPV4UAAACQ0lEQVQ4jV2UzXYaMQyFZXD2Np7sYabdjy0eYAB5TxP7/V+lVzIEWp0scvzN 1b+gQGZxmBf3+O/5MixUubDaE4TxXZp6v8wwIAA4Mw8upo/eb/MgBrz0JtTc2nvf6fvCeYDa1e7T AAv+FETyfZjyg3l6AOk/1gYoTInjVF+gb0S7RbMCCO8Aoq1o8JTzf6ALElBFjr69I5E90iItf2rv 4cXvDGhiIvJ634pWSLwCEIlarebpYC0ZxbsYxJsOvYnziRSkHFnLpM1aIBu+VZAC+q0pWG9abaIO ABht33NiCDNitCYOIRNlnogS6oRiGmnpfBIUK4UUAZwbZQLUpgqN7lB/aI/K0e0tEx5zIodWPqeC vPstUoZzJpd/5ogKWyVHaXWardb+VFTx/qIt0Z3b/Fsft/XzAsVYRXl1vm2xAmR99vLveKtDr1wI tL05wgodWyZb1fDMqIttyvmuo2XOYTRchIKCud7YFFFTQicSz0eAy7HvzRWGVBs6ze4wLwDXj8Y6 c11FcczlfCvzSRX1G8ug797OpWQM+2gJ7MpC9v2GOVl65Vdv2O2CGOiqbHE8M8+/+x8EXBJTJqyF gaKH8dm/Jmn5AFdk98dLwTLN80f/OvnGu8XSjSZRgNjXeWq2ojir+IhRFOzmtR4UFEhMpp5OemvH iq22FSVsiOUEBdwc6xUKnGHYO4A4XN2XB4Bij4k4XWDmc79DITdeRnfLKellJfw0XBXcE2Jwxsbl bElHgIVXEb0PpF90WGmAfeHstxT/AiT/zy9yz+OlAAAAAElFTkSuQmCC X-Now-Playing: The Cure's _The Head On The Door_: "Screw" In-Reply-To: (Steve Yegge's message of "Tue, 24 Apr 2012 17:24:57 -0700") User-Agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.1.50 (gnu/linux) X-MailScanner-ID: 1SN3Yf-0000RF-K7 MailScanner-NULL-Check: 1335970266.12121@9jo1XtO3a+/XwgqCBGmzEw X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.224.195 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:149989 Archived-At: Steve Yegge writes: > I think we should change all the core string-manipulation functions to > deal gracefully with nil arguments. I think it's an intriguing idea. Let's look at some not-quite-real bits of code. We get a string from a map, and then, if it exists, we want to insert it twice, capitalised. Because `capitalize' bugs out on a nil parameter, this is how we do it today: (let ((foo (plist-get map 'foo))) (when foo (setq foo (capitalize foo)) (insert foo) ... (insert foo))) The "problem" here being the dreaded `setq'. For reading comprehension, its nice to not mutate variables. If we instead allowed `capitalize' to take a nil parameter, we'd have the more readable (let ((foo (capitalize (plist-get map 'foo)))) (when foo (insert foo) ... (insert foo))) And we can get away with a much more functional style if we allowed `insert' to take nil as a parameter (meaning "insert nothing"): (insert (capitalize (plist-get map 'foo))) instead of (let ((foo (plist-get map 'foo))) (when foo (insert (capitalize foo)))) I also often see code like (well, the equivalent of) (let ((foo (capitalize (or (plist-get map 'foo) "")))) ...) to avoid all the checking and `setq'-ing, but this makes the code less clear, and you end up with nonsensical tests like `(zerop (length foo))' later in the code if you really need to check whether you had a `foo' there anyway. I don't really see much of a downside to allowing (many) stringey functions to take nil as a parameter. And there's an upside. So why not? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog http://lars.ingebrigtsen.no/