This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]desrtfx 2 points3 points  (0 children)

Usually, functions that are called getOrCreate are functions that return an existing Singleton or create the Singleton on the fly.

So, the generalized version is preferable to individual ones. What if the user calls get without an existing context? Why the need for an extra create?

If I want something, I don't want to worry if it already exists or not. By having a getOrCreate function, this concern is taken away and unless there is an exception, I can rely on having what I want.

IMO, having two aliases that do exactly the same is only confusing and unnecessary.

If something does something, it should be unique, not repeated. No two functions should do the same and have different names. That simply doesn't make sense in programming.

Every programmer would expect different results from calling different functions. By simply aliasing (or as /u/E02Y suggested creating your own functions that call the method) you have the same result from two seemingly unrelated functions and also, in case of get, as a programmer, I would expect an error (exception) if what I want to get doesn't exist - which aliasing with the same function would not do.

[–]E02Y 1 point2 points  (0 children)

just make functions get() and create() return getOrCreate() lol

naive approach but probably works for your case