Whenever I see a DAO or ICO contract, the token contract is a contract at a different address... Let's say I want to create a democratic DAO contract without an owner. When someone sends 1 ETH to the contract some tokens are generated by the contract and credited to the msg.sender (up to a specified maximum supply) wouldn't it make sense to pack them into one contract? What speaks against it or why are those contracts always separated from each other?
2 Answers
There are several possible reasons:
- Block Gas limit: The block gas limit limits how much functionality you can include in a single contract. This should be a non-issue because mainnet has 8M gas limit and it should be enough for most contracts.
- Security: Having separate contracts can make them easier to audit, each one is has a single purpose. But having two contracts can make interactions between them more complex.
- Upgradability: You can upgrade one contract without affecting the other too much.
But each crowdsale is different and you can priviledge one aspect over others, like usability, or simplicity.
Separation of concerns is a good programming practice.
The smart contract world needs to keep up with the best programming practices, as otherwise we have a bunch of amateurs going around and losing other people's money.