is there a way to: import something = app-xyz-classes-something; ?
someone
someone at somewhere.com
Sat Jun 26 02:19:18 UTC 2021
On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer
wrote:
> That being said, I strongly recommend just to name the file the
> same as the module name.
Although you made it clear that you do not favor this use-case I
am really satisfied with your solution because, at least to me,
has some pros; consider the following type "namespace" where sm
stands for stock manager ie: the app prefix (and fw for framework
ie: the common library):
```d
import fw.code.common; /// framework; ie: app-independent common
code
import sm.code.common; /// app-specific common code
import sm.types.common.currency; /// app-specific common types
import sm.types.common.equity;
import sm.types.specific.trade; /// app-specific specific types
import sm.types.specific.position;
import sm.types.specific.account;
/// eg: + whatever
/// eg: has accounts[]
/// eg: has positions[]
/// eg: has trades[]
```
... linked as following with this build script:
```d
#!/bin/bash ### not D code but I do not know how to tag this block
/usr/bin/dmd \
"../common/code/fw-code-common.d" \
"./code/sm-code-common.d" \
"./types/sm-types-common-currency.d" \
"./types/sm-types-common-equity.d" \
"./types/sm-types-specific-trade.d" \
"./types/sm-types-specific-position.d" \
"./types/sm-types-specific-account.d" \
-w -de \
-run "./code/sm-code-app-demo.d" \
;
```
... and on each module:
```d
module sm.code.app.demo; /// this matching the main demo app
alias typeCurrencyFormat0 =
sm.types.common.currency.gstrCurrencyFormat0;
alias typeCurrencyFormat2 =
sm.types.common.currency.gstrCurrencyFormat2;
alias typeCurrencyFormat4 =
sm.types.common.currency.gstrCurrencyFormat4;
alias typeCurrencyRange =
sm.types.common.currency.gudtCurrencyRange;
alias typeStockID = sm.types.common.equity.typeStockID;
alias typeTrade = sm.types.specific.trade.gudtTrade;
alias typePosition = sm.types.specific.position.gudtPosition;
alias typeAccount = sm.types.specific.account.gudtAccount;
```
Naming directory/files/type-namespace and aliasing this way
allows me to:
- move and rename source files as needed: only need to update the
build script if so
- aliasing the types I will be using in any given module once at
the top of the source file and using this alias all the way back
to the bottom: perfect hierarchical-unambiguously-namespace
keeping code cleanliness all the way down; no-need to rename
anything on any source file when its name/placement changes on
the file-system.
- although I am currently mimicing the type namespace following
the file-system file/directory structure I am able to build the
namespace independent of the file-system if I wanted to; say, the
name-space using all lower-case letters while the file-system
using mixed caps and spaces instead of _ or - or non-latin glyphs
or whatever.
What I like most of it is that it scales well for big and complex
apps while being really flexible ... and neat :)
More information about the Digitalmars-d-learn
mailing list