How to organize source code in multiple files?
Posted: Fri Sep 05, 2008 5:01 pm
Most of the time I work in Emacs with interpreter running and all my code loaded, but I wanted to make an ASDF definition file.
I understand that when a multi-file project is compiled and loaded, it's done sequentially, file after file, so you have to be careful about the definitions order:
- Compilers issue warnings on compiling forward references to functions, but I suppose this is harmless - and unavoidable in case of a circular dependency. But what about a function declared inline?
- Macros should be compiled before usage, so they should be grouped somewhere near the beginning of build order - even if a macro actually belongs to a specific domain of code (i.e. specific class)?
- Classes have to be defined before a DEFMETHOD can specify them. Does that mean they should be separated from the relevant methods and put all in a different file?
- Is it important to specify the generic methods? And where should I put them?
This is probably again me not understanding "the Lisp way to do things", but I feel I have to group code in a way that pleases the compiler, not in one that makes most sense semantically...
I understand that when a multi-file project is compiled and loaded, it's done sequentially, file after file, so you have to be careful about the definitions order:
- Compilers issue warnings on compiling forward references to functions, but I suppose this is harmless - and unavoidable in case of a circular dependency. But what about a function declared inline?
- Macros should be compiled before usage, so they should be grouped somewhere near the beginning of build order - even if a macro actually belongs to a specific domain of code (i.e. specific class)?
- Classes have to be defined before a DEFMETHOD can specify them. Does that mean they should be separated from the relevant methods and put all in a different file?
- Is it important to specify the generic methods? And where should I put them?
This is probably again me not understanding "the Lisp way to do things", but I feel I have to group code in a way that pleases the compiler, not in one that makes most sense semantically...