4 ms·
I agree with the gist of your post, but one positive about single use functions is that you can be explicitly clear about data visibility. In this contrived ex
by mopierotti 6y ago
I agree with the gist of your post, but one positive about single use functions is that you can be explicitly clear about data visibility.
In this contrived example, you can tell that formatting a title is not affected by user preferences, but formatting the body is. (And additionally that formatting a body has no information about the other fields of an entry)
def formatRssFeedEntries(userSettings: UserSettings, data: List[Entry]) {
val titles = data.map(entry => formatTitle(entry.title))
val bodies = data.map(entry => formatBody(entry.body, userSettings))
...
}
- barrkel 6y agoI agree. Blocks can somewhat substitute with scoping effects, and that's what I do with my inlined docs - they're nested {} with plain text description of contents and mentions of key variables and functions, scope is useful.