3 ms·
Also Java: bank.move(new Amount(100), new FromAccount(checkingAccount), new ToAccount(savingsAccount)); If you are really trying, you will be able to convey e
by cessor 7y ago
Also Java:
bank.move(new Amount(100), new FromAccount(checkingAccount), new ToAccount(savingsAccount));
If you are really trying, you will be able to convey enough information so that your fellow programmer. will understand what you are trying to accomplish. Unfortunately, in practice, even Java Experts will convey to you that this style is wrong, classes and objects are " too expensive", primitive values are fine, and that this is too verbose.*
I learned about this style from Yegor Bugayenko's Book "Elegant Objects", go check it out. https://www.elegantobjects.org/ https://www.elegantobjects.org/
*) Yes, Java is verbose; not trying to defend that. I am very happy about keyword arguments in Python, for example. But, as soon as you have classes, ctors, objects, you can use them to add rich semantics into your code. Works with functional languages and other, better typesystems, too.
- overgard 7y agoIs there an explanation that doesn’t require buying a $40 book? I searched the site and couldn’t find anything
- edflsafoiewq 7y agoOf course you can, but you can't simply hand-wave away the verbosity. What a language makes easy is usually more important than what it makes possible. In Python, adding from=from_account, to=to_account to clarify a call is basically free; you don't have to change the callee and you don't have to change any other call sites.
- xwowsersx 7y ago> What a language makes easy is usually more important than what it makes possible. very well said
- trophycase 7y agoI wouldn't write it either way. I would write something like bank.processTransfer(new Transfer(100, checkingAccount, savingsAccount)) where the transfer object is immutable.
- xwowsersx 7y agoCool, but the SmallTalk example requires a lot less squinting which is nice.
- dnautics 7y agoI think you don't have enough factories. bank.move(new Amount(100), AccountChannelFactory.create(AccountChannelFactory.CHECKING_CHANNEL, checkingAccount), AccountChannelFactory.create(AccountChannelFactory.SAVINGS_CHANNEL, savingsAccount));