From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Should records be able to mimic primitive types? Date: Mon, 12 Jun 2017 13:40:27 -0400 Message-ID: References: <8777899d-ca8e-212c-b8bf-2f8da4c54836@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1497289250 23160 195.159.176.226 (12 Jun 2017 17:40:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Jun 2017 17:40:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 12 19:40:46 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKTKV-0005kl-Rw for ged-emacs-devel@m.gmane.org; Mon, 12 Jun 2017 19:40:43 +0200 Original-Received: from localhost ([::1]:39376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKTKb-0007us-4g for ged-emacs-devel@m.gmane.org; Mon, 12 Jun 2017 13:40:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKTKU-0007ua-7E for emacs-devel@gnu.org; Mon, 12 Jun 2017 13:40:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKTKR-00010J-5C for emacs-devel@gnu.org; Mon, 12 Jun 2017 13:40:42 -0400 Original-Received: from [195.159.176.226] (port=57444 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKTKQ-0000zu-Uo for emacs-devel@gnu.org; Mon, 12 Jun 2017 13:40:39 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dKTKJ-00056k-Hi for emacs-devel@gnu.org; Mon, 12 Jun 2017 19:40:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 44 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:pPHVdoth0ekeRP7NDhQZ3nlLM68= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:215597 Archived-At: >> It's not trying hard, just a simple check for a known, small, and >> rarely-changing list of primitive symbols. > To me, that's working very hard: > - extra code. > - extra maintenance > - extra run-time checks. > - no benefit since this doesn't catch a common situation. More concretely: what would be a scenario where such a check would be useful? AFAICT, you need all 3 of: 1- First, you'd need someone to be foolish enough to set his record's type to be one of the primitive types. This is the actual bug that your extra check would aim to catch. 2- Then you'd need to pass that object to a chunk of code which uses `type-of` and then checks the result for that primitive type. Otherwise, the type you set would behave just like any other non-primitive type so the "bug" would be harmless anyway. 3- Furthermore, you'd need this object to be manipulated exclusively in a way which also works with your record object without signaling an error (e.g. if the primitive type used is `integer`, it means your object should never be passed to the likes of `+` since otherwise the bug would already be discovered by `+` without any need for your extra check). I haven't seen any evidence that step 1 will ever occur, even by accident. No idea how likely is step 2. `type-of` is very rarely used (except via cl-defmethod) so it's fairly unlikely, but possible. Step 3 seems again very unlikely in itself, and even more so if step 2 occurred: if you checked with type-of that your object is of type `integer` there's a very high likelihood that you're going to then use operations which only work on integers. Will all 3 steps ever occur at the same time? Do we really want to make every call to `make-record` pay the extra test in order to hope to catch this hypothetical case? Obviously I think not, and I'd be curious to understand why you think otherwise. Stefan