all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: Is it possible for a macro to expand to nothing?
Date: Sat, 28 Nov 2009 10:17:27 +1100	[thread overview]
Message-ID: <87r5rjwoag.fsf@lion.rapttech.com.au> (raw)
In-Reply-To: heojcr$1a4h$2@colin2.muc.de

Alan Mackenzie <acm@muc.de> writes:

> Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
>> Alan Mackenzie wrote:
>
>>> Your notion of the correct use of macros seems to be a religious idea
>>> rather than one fully thought through.  You justify it with circular
>>> reasoning.  Whilst using a macro to generate an evalable form may be
>>> the most usual thing, there is no reason not to use it to produce
>>> other list structure.
>
>> Except that such macros can only be executed in a particular context
>> i.e.  they depend on something that cannot be expressed via their
>> argument list.
>
> Yes, many lisp structures can only be "executed" in particular contexts,
> `,@' for example, yet nobody slags them off for that.
>
>
>> At best that is poor style, and at worst it is poor engineering.
>
> That is so supercilious - you haven't even given an example of this
> phenomenom, discussing why it is poor style or poor engineering.  There's
> just this vague insinuation that you know better.
>
> I will give an example, namely `c-lang-defconst' from cc-defs.el.  Are
> you going to assert that it is poor style, or even poor engineering,
> simply because it generates an internal data structure rather than an
> excutable form?  If so, then it's up to you to say how it could have been
> done better, preferably submitting a patch.

I have found this an interesting discussion. I'm not sure which side of
the fence I fall on. 

Pascal/s assertion this is not good style has considerable merit. In
general, I think most do expect the result from a macro to be a form
that can be evaluated. 

On the other hand, Alan's arguments also have merit. If a macro can be
useful in generating something other than a form that can be evaluated,
such as a data structure and can do so in a way that is cleaner/simpler
or just easier to understand than doing the same using functions, then
it would make sense. His examples from the C modes seem to be a case in
point. 

To some extent, I would suggest this is one of those situations where
its ok to break the 'rules' provided you understand what the rules are
and you make it explicit in your comments/documentation that this is an
exception to the more common usage. In other words, Pascal is correect
that generally, good style would dictate that a macro returns a form
that can be evaluated. At the same time, if there is a situation where
using a macro in a way that isn't totally in keeping with good style
will result in code that is easier to understand/maintain, then it is
reasonable to do so provided this is documented and made clear. to some
extent, this follows Alan's example regarding goto. While good style
suggests you should avoid goto, there are situations where using goto is
the clearest and most maintainable solution, especially if avoiding its
use makes you jump through a whole lot of hoops to simply avoid
something that  someone has said is bad style. 

The whole notion of what is and is not good style is all about making
your code easier to understand and maintain. Style should not be viewed
as a set of rules that can never be broken (or change for that
matter). If anything, style guidelines are simply that, guidelines on
how to write your code to make it easier to understand and
maintain. When first programming, its a good idea to follow style
guidelines quite religiously. However, once you understand why the
guidelines are there and you become more experienced, you should
understand the difference between good and bad code and know when you
can break the rules.  

There is also a certain amount of personal taste/style that needs to be
considered. I've seen code that follows all recommended style guidelines
that is still almost impossible to understand and I've seen code that
appears to break many style guidelines that is very clear and easy to
follow. What I've found to be far more important is consistency. When
working with someone elses code, you get a feel for their style and way
of programming. Provided they are consistent, this isn't too bad
regardless of their adherence to common style guidelines. The worst is
code that sometimes adheres to guidelines and sometimes does not. My
view is to try and follow the 'accepted' style guidelines for the
language you are working in and document situations where you thought it
necessary to do something different that is outside normal style
conventions.

Tim
 

-- 
tcross (at) rapttech dot com dot au


  parent reply	other threads:[~2009-11-27 23:17 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-23 14:56 Is it possible for a macro to expand to nothing? Alan Mackenzie
2009-11-23 16:03 ` Drew Adams
     [not found] ` <mailman.11344.1258992201.2239.help-gnu-emacs@gnu.org>
2009-11-23 16:31   ` Alan Mackenzie
2009-11-23 17:29     ` Drew Adams
2009-11-23 18:33     ` Pascal J. Bourguignon
2009-11-23 18:51       ` Drew Adams
     [not found]       ` <mailman.11354.1259004470.2239.help-gnu-emacs@gnu.org>
2009-11-23 20:08         ` Pascal J. Bourguignon
2009-11-23 20:24           ` Alan Mackenzie
2009-11-23 22:09           ` Drew Adams
     [not found]           ` <mailman.11367.1259014174.2239.help-gnu-emacs@gnu.org>
2009-11-23 23:55             ` Pascal J. Bourguignon
2009-11-24  0:55               ` Alan Mackenzie
2009-11-24  9:42                 ` Pascal J. Bourguignon
2009-11-24 10:45                   ` Alan Mackenzie
2009-11-24 11:14                     ` Pascal J. Bourguignon
2009-11-24 16:39                       ` Alan Mackenzie
2009-11-24 19:17                         ` Pascal J. Bourguignon
2009-11-25 14:13                         ` Jeff Clough
     [not found]                         ` <mailman.11467.1259158369.2239.help-gnu-emacs@gnu.org>
2009-11-26  6:53                           ` Alan Mackenzie
2009-11-26 11:11                             ` Pascal J. Bourguignon
2009-11-26 11:52                               ` Lennart Borgman
     [not found]                               ` <mailman.11564.1259236392.2239.help-gnu-emacs@gnu.org>
2009-11-26 12:16                                 ` Pascal J. Bourguignon
2009-11-26 12:43                                   ` Lennart Borgman
2009-11-27  8:32                         ` Kevin Rodgers
     [not found]                         ` <mailman.11626.1259310779.2239.help-gnu-emacs@gnu.org>
2009-11-27 13:15                           ` Alan Mackenzie
2009-11-27 13:52                             ` Pascal J. Bourguignon
2009-11-27 16:57                               ` Alan Mackenzie
2009-11-27 17:09                                 ` Pascal J. Bourguignon
2009-11-27 17:19                               ` Helmut Eller
2009-11-27 17:45                                 ` Pascal J. Bourguignon
2009-11-27 23:17                             ` Tim X [this message]
2009-11-28  0:06                               ` Pascal J. Bourguignon
2009-11-28  8:29                                 ` Alan Mackenzie
2009-11-28 10:25                                   ` Pascal J. Bourguignon
2009-11-28 12:57                                     ` Thierry Volpiatto
     [not found]                                     ` <mailman.11699.1259413441.2239.help-gnu-emacs@gnu.org>
2009-11-29  0:54                                       ` Pascal J. Bourguignon
2009-11-24 11:56                     ` Pascal J. Bourguignon
     [not found]     ` <mailman.11352.1258997403.2239.help-gnu-emacs@gnu.org>
2009-11-23 18:42       ` Pascal J. Bourguignon
2009-11-23 20:12         ` Drew Adams
     [not found]         ` <mailman.11356.1259007263.2239.help-gnu-emacs@gnu.org>
2009-11-23 20:21           ` Pascal J. Bourguignon
2009-11-23 22:09             ` Drew Adams
     [not found]             ` <mailman.11368.1259014177.2239.help-gnu-emacs@gnu.org>
2009-11-24  0:03               ` Pascal J. Bourguignon
2009-11-23 20:09       ` Alan Mackenzie
2009-11-23 16:49 ` Jeff Clough

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

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

  git send-email \
    --in-reply-to=87r5rjwoag.fsf@lion.rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.