This is not practical when the number of shareholders is large because you will quickly reach the block gas limit. Instead you can use a pull system, allowing users to claim their dividends directly, but this method requires a large number of transactions.

Another alternative method to distribute the value of dividends is to use the dividend to directly increase the value of the shares. One example of how this might be done is the following:

Collect fees in ETH or any other token.

Every week create an auction which buys shares with the collected ETH.

Once the auction completes, provably burn the purchased shares.

Periodically buying and burning shares with fees collected has a similar effect to sending ETH directly. It is not quite the same, but still it's a good trick to have in your cryptoeconomic toolbelt. There are a bunch of variations on this mechanism & analysis that can be done; however, I'll leave that to you, dear reader ✨

All credit to Vitalik ❤️ for teaching me this fun mechanism. Special thanks to Danny Ryan & Hayden Adams for edits.