565 reputation
1514
bio website
location
age
visits member for 2 years, 2 months
seen Jul 4 at 13:01

Jul
5
awarded  Famous Question
Jul
2
awarded  Curious
May
7
awarded  Yearling
Apr
29
awarded  Notable Question
Jan
30
comment So Singletons are bad, then what?
Great explanation of DI, and I've been using DI extensively in the last few years. But I'd like to point out that occasionally, doing DI manually is unreasonably cumbersome, and some languages don't support automatic DI well, e.g. C++. I've found service locators (implemented as singletons, yes) to be a good alternative in those cases, they've got only a few of the weaknesses of singletons you identified above.
Jan
2
awarded  Notable Question
Dec
11
awarded  Critic
Dec
2
awarded  Nice Question
Oct
3
awarded  Popular Question
May
23
comment Naming functions that retrieve a value
@DietrichEpp I'm following your advice after all by now, it's not really helpful to have a verb in the name of pure functions. All the gets are gone now, with the exception of actual accessors (of which I only have few).
May
16
comment Naming functions that retrieve a value
@DietrichEpp That's a good point in favour of not prefixing anything with calculate. I'm not entirely sure about dropping all the get's, but you have a point, there's not really a need for it.
May
15
comment Naming functions that retrieve a value
@DietrichEpp I agree, it's not such a clear distinction. We do say "The sine of x" or more generally "f of x", so function/result is synonymous. In that sense, we might think of sine as a property of a number x though. Aren't all functions that get/calculate a value from some input structure without changing it mathematically pure?
May
15
comment Naming functions that retrieve a value
@DietrichEpp That has me thinking, but I believe I can argue sin() away: sine is the name of an actual mathematical function, while magnitude describes the result of some computation, just like square root. Would I call the sqrt function get_square_root? I think so.
May
15
accepted Naming functions that retrieve a value
May
15
comment Naming functions that retrieve a value
That said, "Reserve the get prefix for things that are conceptually properties of the object [...], even if the value is not explicitly stored in the object" sounds good to me.
May
15
comment Naming functions that retrieve a value
What about my example? The magnitude of a vector is in some sense one of its properties, but it's also a slightly expensive calculation, with the sqrt.
May
15
comment Naming functions that retrieve a value
I'm not prefixing "every function that returns a value" with get, that would defeat the purpose. I'm prefixing "every function whose sole purpose it is to retrieve a value or a set of values from some data structure or object". Nor would I prefix fopen with get, I'd call it "open_file" and I'd have my verb :)
May
15
asked Naming functions that retrieve a value
May
14
awarded  Popular Question
May
7
awarded  Yearling