unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Alan Mackenzie <acm@muc.de>
Cc: John Wiegley <jwiegley@gmail.com>,
	20241@debbugs.gnu.org,
	Artur Malabarba <bruce.connor.am@gmail.com>
Subject: bug#20241: 25.0.50; `setq' with only one argument
Date: Wed, 25 Nov 2015 08:27:43 -0800 (PST)	[thread overview]
Message-ID: <fff8c7a2-d550-4c3d-b247-5bbc86ec5ef1@default> (raw)
In-Reply-To: <20151125154030.GF2007@acm.fritz.box>

> > If you cannot now analyze the code properly to determine TRT, or
> > contact the author to make that determination, then do the obvious
> > (IMO): Assign a `nil' value explicitly where it is now assigned
> > implicitly.
> 
> That would be the worst thing: it would leave the code possibly failing
> exactly the way it did, but remove the evidence (which can be
> mechanically found).

It would leave the code behaving exactly as it did before.  AND it
would add information to developers that there is possibly an error
here - right here, in this sexp here.  AND it would say clearly what
that possible error is.

That doesn't "remove the evidence".  It puts a big sign around the
evidence saying "**EVIDENCE** - Check this code to see whether it
should really should assign a nil value.

But if you can DTRT now - analyze the code sufficiently and fix
it properly or contact the author for an opinion - then that's
the thing to do.

Or if you just leave the code as is, but ensure that a runtime
error is raised, that is also TRT.  It takes care of THIS bug,
but it does not fix that bug (indicated by the error occurrence).

That's fine.  When the error is raised someone can then work on
fixing that bug.  They can take the time to analyze and fix it
properly.  And they can ensure, while they are working on it,
that the code at least runs as it did before - by doing what I
suggested above: explicitly assign `nil' and add a comment.
 
> > AND flag that amended code with a comment saying what you've done,
> > and that you don't currently know whether (a) there is a bug here
> > or (b) `nil' is really what is needed.
> 
> Comments are less good than error messages from the byte compiler!

I disagree.  Each can be helpful in its own way.  In this case,
we have already located the potential problem, and the (right)
message to developers about it is that THERE IS an assignment
of `nil' and IT MIGHT BE PROBLEMATIC.  The source code is a good
place to convey that message, right next to the suspect assignment.

> > IOW: (1) At least just ensure that the code does the same thing
> > that it does now, but respects the intended meaning of `setq'.
> > (2) If you have to punt the careful analysis for later or for
> > someone else, then add a comment to that effect.
> 
> > > Maybe having the byte compiler error out in this situation
> > > isn't such a brilliant idea after all.
> 
> > IMO, the bug should be fixed to raise an _error at runtime_,
> > for both interpreted and byte-compiled code.
> 
> I've just tried it out.  The byte compiler generates an error message,
> but the .elc is written anyway.  No runtime error happens from such
> compiled code.  But running it interpreted would signal an error.

And who will run it interpreted?  THIS is worse than nothing, IMO.

What counts is the runtime behavior.  And that counts for both
source code and byte-compiled code.

> > Whatever else the byte-compiler might do is less important, as
> > long as it produces code that is comparable - e.g., code that
> > will also raise an _error at runtime_.
> 
> It currently doesn't do that.  I'm not convinced it should, either.

What would it take to convince you?  What is the purpose of
byte-compilation, in terms of the resulting code?  Is it to
change the behavior in ways other than optimization?  I don't
think so.

The byte-compiler is not just some QA tool to check whether i's
are dotted and t's are crossed.

It produces _code_ that is _run_, and that runtime behavior
should reflect the programmer's intention.  And that intention
is expressed in the source-code language (which can include
declarations to a compiler, but that's beside the point here).

> > It's OK for a byte-compiler to be smart, but not smarter than
> > the actual source code ;-).  It should pretty much try to
> > produce code that does the same thing, but hopefully usually
> > does it quicker.
> 
> Why is this topic suddenly seeming complicated?  :-(

I don't think it's complicated.  `setq' should raise an error
when it is passed an odd number of arguments.  _That's all._
The error should be raised when `setq' is invoked, obviously.

Anything else we might decide to do is extra communication
to programmers _about_ the code.  But the code itself should
DTRT.  Assigning `nil' for a missing value arg is not the
right thing; raising an error is the right thing.

If you want to leave the problematic code as is, but ensure
that a runtime error is raised, that's fine.  It is the right
thing.

But IF you decide to try to fix the problematic code now, and
IF you feel you are unsure about the fix, THEN the best thing
to do is to keep the behavior as it was (assign `nil'), but
make that behavior explicit and question it with a comment.

I would rather opt for just leaving the code as it is -
erroneous, and let it raise a runtime error.  But then we
will be in the same boat for fixing that error: analyze or
contact the author, etc.





  reply	other threads:[~2015-11-25 16:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 14:53 bug#20241: 25.0.50; `setq' with only one argument Drew Adams
2015-04-01 16:41 ` Stefan Monnier
     [not found] ` <mailman.3138.1427900048.31049.bug-gnu-emacs@gnu.org>
2015-11-23 14:31   ` Alan Mackenzie
2015-11-23 18:44     ` Glenn Morris
2015-11-23 18:54       ` Glenn Morris
2015-11-23 22:05         ` John Wiegley
2015-11-23 19:31       ` Alan Mackenzie
2015-11-24 11:32         ` Alan Mackenzie
2015-11-24 17:38         ` Glenn Morris
2015-11-24 18:04           ` Alan Mackenzie
2015-11-24 19:26             ` Artur Malabarba
2015-11-24 21:09               ` Alan Mackenzie
2015-11-25  1:46                 ` John Wiegley
2015-11-25  9:41                   ` Alan Mackenzie
2015-11-25 10:36                     ` Artur Malabarba
2015-11-25 11:07                       ` Alan Mackenzie
2015-11-25 11:13                         ` Artur Malabarba
2015-11-25 11:28                           ` Alan Mackenzie
2015-11-25 15:18                         ` Drew Adams
2015-11-25 15:40                           ` Alan Mackenzie
2015-11-25 16:27                             ` Drew Adams [this message]
2015-11-25 17:22                               ` Alan Mackenzie
2015-11-25 18:28                                 ` Drew Adams
2015-11-25 19:06                                   ` John Wiegley
2015-11-25 19:21                                     ` John Mastro
2015-11-25 19:22                                     ` Drew Adams
2015-11-25 19:34                                     ` Artur Malabarba
2015-11-25 19:40                                       ` John Wiegley
2015-11-25 20:20                                         ` Artur Malabarba
2015-11-25 20:37                                           ` John Wiegley
2015-11-26 11:07                                             ` Alan Mackenzie
2015-11-25 20:58                                         ` Alan Mackenzie
2015-11-25 21:19                                           ` Drew Adams
2015-11-25 21:52                                           ` John Wiegley
2015-11-26  0:21                                     ` Johan Bockgård
2015-11-26  8:58                                       ` Andreas Schwab
2015-11-26 12:06                                         ` Alan Mackenzie
2015-11-26 16:38                                           ` Artur Malabarba
2015-11-26 21:19                                             ` Alan Mackenzie
2015-11-27  0:07                                               ` Artur Malabarba
2015-11-25 13:11                       ` Nicolas Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fff8c7a2-d550-4c3d-b247-5bbc86ec5ef1@default \
    --to=drew.adams@oracle.com \
    --cc=20241@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=bruce.connor.am@gmail.com \
    --cc=jwiegley@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).