jeosol <
jeron...@gmail.com> writes:
> Thanks to @Mart, @informatigo for the contributions.
>
> My original point of putting each class in a file is just my first
> thought/pass but you guys provide other important considerations. I
> see the limitation of one class per file that method when I have
> defmethods with multiple classes as arguments. At this point, I am
> more concerned about best organization option.
It really depends on your problem.
Take for example this lambda-list parser:
https://framagit.org/com-informatimago/com-informatimago/blob/master/common-lisp/lisp-sexp/source-form.lisp#L576
There are multiple variants of lambda-lists, that are defined as
subclasses of lambda-list, but also of a mixin defining the various
groups of attributes a lambda-list can have.
It would be quite inconvenient to split those classes over multiple
files, when the block of defclass forms from 585 to 594 defines all the
variants in a clear and declarative way.
Notice also that quite a number of generic functions are defined with
all their methods at once, and again, it would be much harder to
maintain consistency if they were split out into defmethod in separate
files.
> @Mart, the reason I considered using different packages for each file
> is following common lisp style guide (see
>
http://labs.ariel-networks.com/cl-style-guide.html). In that case, I
> can only import relevant functions into each file. This may be an
> overkill though. In an old code, I used a single package method and it
> was sure a lot simpler to deal with. I am trying to find out merits,
> e.g., faster compilation of one option vs. the other.
In general I don't like style guides because they take into account only
one or a few use cases, and they may not match your current situation.
When you're a newbie and you're developing code that falls in the coding
style use case, or you're paid to follow it, you should certainly follow
it, but if this condition is false, you should rather use your brains.
Notice also how coding style guides are given in the form of rules
generaly more formal than less. If you can formalize rules, then you
can implement software to enact them. See for example slime indent and
paredit. If you have software implementing some rules, don't try to
fight it (and do use those software, because most other programmers will
use them, and unfortunately, currently editors and IDE don't reformat
code upon loading to follow the taste of the reader).
But it should tells you something: that coding rules are not to be
followed by human beings! Style is a question of taste, and cannot be
formalized, and foremost, cannot be generalized.
For example, this program has perfectly good style:
http://www.99-bottles-of-beer.net/language-common-lisp-114.html
(And notice that slime indents it incorrectly, since it insists on
aligning STREAM and the first line of the string literal with FORMAT).