Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would say that this is only true for very, very simple use cases. Even moderately complex code should at least be accompanied with a concise documentation. Here is an example from my work:

Consider the case were two database fields should either both be NULL or both must have a value. Instead of 'amount' and 'currency' and documenting the relation, should we really name the fields 'amount_if_currency_is_not_null' and 'currency_if_amount_is_not_null'?

And is it really sufficient to define 'amount' as INTEGER without any documentation and then demand that everyone new to the project and not familiar with financial calculation immediately understands that the value is given in the lowest unit of the associated currency, i.e. cents for US dollar vs. one hundred millionth of a bitcoin vs. Icelandic króna (which has no subdivision).

Good luck to find a short name that makes that obvious.



You dont mix business logic and data like that.

You name the fields currency and amount and have the business logic rejecting invalid pairs.

You should use a currency type for the other issue, not an integer.


Upon reflection a proper strong currency amount type that has a strongly typed currency property as a requirement for existence makes sense.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: