Hi :) 2017-04-24 19:01 GMT+02:00 Christopher Allan Webber <[email protected]> :
> 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". > I think that there's no need to be super-consistent here. Actually, I can't think of any natural and elegant use of a boolean variable from the top of my head, but my gutt feeling is that it usually can be avoided (however, if you have some particular examples on your mind, I think it could be instructive to see them here). Also, there seems to be many aspects of this. When we're using a name inside a let or let* form, it shouldn't be very harmful to use question mark in the name of an intermediate variable. The thing with function parameters and global names are I believe more important, because they are a part of some interface. As for parameter names, I'm not sure whether it is a good idea to use question marks in the names that ought to refer to predicates. I'm not sure if it is better for a prototype of "filter" to be (filter condition? list) or (filter condition list) Actually, I find it more natural to interpret the predicate as a boolean flag to a function, rather than a predicate. That said, I think it is a bad practice to make boolean flags arguments to functions, because it is impossible to say how (f #false #true #false) differs from (f #true #true #true) nor what the roles of these arguments are (which is why I think the interface of "format" sucks) Hinldley-Milner languages avoid this problem, because a type signature tells more than just a name (and is more reliable), and they handle tagged unions easily, and it is much better to define a union and use one of its values, than a boolean value (and using Lisp symbols for this purpose, although more readable, is error prone and likely less efficient) Best regards, Panicz
