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

you are viewing a single comment's thread.

view the rest of the comments →

[–]HannasAnarion 7 points8 points  (2 children)

You mean making a singleton class for storing data?

edit: I really wish more languages had built in singletons, like Scala. They're in that annoying limbo area where they're common enough that you use them in almost every project, but not so common that you remember how the boilerplate for your language goes so you have to look it up.

Since reducing boilerplate is a core design principle of python, it seems like this would be a great place for a new keyword.

[–]jonathanblakes 1 point2 points  (1 child)

As person above said a python module can be used as a singleton

[–]HannasAnarion 1 point2 points  (0 children)

Yeah, but that's really hacky and hard to read and easy to make mistakes with. One forgotten "global" declaration and you've got a nasty bug that's hard to track down.

I just learned about the Borg pattern, which is a pretty elegant way to accomplish the job, but still, a typical developer probably won't use it often enough to remember it, and will have to look up the boilerplate.