[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ?-suffix for booleans... good-idea? or bad-idea?

From: Neil Jerram
Subject: Re: ?-suffix for booleans... good-idea? or bad-idea?
Date: Tue, 25 Apr 2017 19:08:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

I'm also not sure. In the past I've written code with an 'xxx?' variable, and then added a procedure to set it, giving 'set-xxx?!' - which is not exactly elegant.

Also I'm not sure it's best practice to have many variables/attributes/parameters with boolean values, as this can lead to code that has too many opaque uses of #t and #f. (I.e. it's often unclear, at the point of use, what each #t or #f means.) It might be better to refactor to something with non-boolean values, e.g. from

   (set! red? #t)
   (set! narrow?#t)


   (set! properties '(red narrow))

And in that case the question about '?' would disappear.


On 25/04/17 04:43, Alex Vong wrote:
Good question! I can't decide as well. I want to know how people think
about it.

In a lazy language, a variable is a 0-ary thunk, while a predicate is a
1-ary thunk. Since they are really just special case of a general thing,
it make sense to use foo? for both cases. But we all know guile is not
lazy, so I really don't know what to do.

Christopher Allan Webber <address@hidden> writes:

Hello everyone!  Here's a little bikeshed for us to paint.

I've noticed that it's common in Guile modules to use "foo?" for
variable names involving booleans.  It's tempting, because this looks
an awful lot like you're asking a question... and it's also common
for this even to be keyword arguments to procedures, etc.

But is it a good idea?  I thought "foo?" was supposed to be for
predicates, as a nicer version of the "foo-p" predicate convention in
other non-scheme lisps.  I can't imagine other lisps doing "foo-p" for
just variables with boolean values.

On the other hand, once you start adding ? to the end of boolean'y
things, it *does* become tempting to put them at the end of boolean
variables and arguments.  It looks pretty nice.

What do people think?  I'm struggling with deciding what's the right
thing for my own code, but leaning towards "we shouldn't use the ?
suffix for just boolean values".

  - Chris

reply via email to

[Prev in Thread] Current Thread [Next in Thread]