« first day (587 days earlier)      last day (4360 days later) » 

sbi
9:00 AM
@GManNickG BTW, I commented on this very issue just a few hours ago.
 
@jalf So don’t use a singleton in those cases
 
Windows registry is the spawn of the devil.
 
but this doesn’t always apply
 
@KonradRudolph But you just described it as a use case for a singleton
 
So make it a singleton unless you don't need a singleton?
That's silly approach.
 
9:00 AM
the same is true for all the others you mention. It is convenient to have a single global instance of an object
 
global: `struct MyClass {}; MyClass global;` is a global variable
global + single instance: `struct { ... } globalSingleInstantiatedObject;`
global + single instance + lazy instantiation: ...
 
@jalf Yes but I didn’t say that every use of configurations can be modeled by it
 
Sometimes you want all three (global, single instance and lazy instantiation), but for some reason that's evil.
 
but in none of those cases does it make sense to make it impossible to create other local instances
 
@sbi Ah, been meaning to do that...
 
9:01 AM
@KonradRudolph Sure, but neither did you suggest any meaningful use which is modelled by it.
 
@ScottW Yes. Because I have two unit tests, each of which need to start with their own empty registry.
 
The only actual global I've used recently was a logger.
 
@DeadMG Ok, cross configuration then, I can’t think of a good example for that now
 
And then a third, global registry for the actual application to use
 
And I don't make it a singleton either, because why would I.
 
sbi
9:02 AM
@jalf Tripleton!
 
@ScottW I actually had a case where I had a triplet. There were always exactly three instances of the class.
 
I'd say, the greatest threat posed by Singleton is the potential to derail any conversation between developers and waste all creative energy.
Stop it already. Write a blog post. Or better yet, read the existing one(s)
 
He did.
 
@sehe I did!
 
@CatPlusPlus even then, I think a static function along the lines of Log.getLogger("mainLogger").LogThatShit("Shut up about longwinded"); works well, and doesn't require singleton
 
9:02 AM
It's not cool that singletons are being singled out.
 
@thecoshman loggers shouldn't be singletons. You might want to have multiple loggers.
 
@sbi Thx. Fixing the link took too long on my f**cking slow work PC
 
Singletons are more code to maintain, they bring a whole new set of problems (especially in MT), and they. are. fucking. useless.
 
@RadekdaknokSlupik I am arguing that point :P
 
9:03 AM
Yes, I hate singletons and I will argue about that till I die.
 
One Megatron is all it takes to destroy all singletons in your code.
 
@jalf The point is, let's not go kill the Germans each time anyone mentions the War.
 
Don't write code that's useless. YAGNI.
 
*sigh*
*Ctrl+A, Delete*
Lol, jk.
 
Ctrl-A moves the cursor to the beginning of the line. Nothing interesting.
:P
 
9:04 AM
@sehe YAY FAWLTY TOWERS
 
@CatPlusPlus Tautologies are redundant. They duplicate semantics.
 
Oh semantics
 
lol
 
@CatPlusPlus I still don’t get it though. It’s nothing special, is it? Just a class with a private constructor (I’ve got plenty of those) and a dedicated builder method
 
Kudos to Konrad for daring to argue with the cat.
 
9:06 AM
@KonradRudolph It's global state, which is bad for every reason that global state is bad for
and then it's enforced only one instance, which is a property that practically nobody ever needs, ever.
 
@KonradRudolph No that's not the same. It's part of the usual implementation, though. You could call the dedicated builder several times and expect a separate instance.
 
@DeadMG “global state” my arse, the state is hidden inside the class, this happens every single time you use a static class variable
 
@KonradRudolph No, a class with a private constructor and a dedicated builder method doesn't prevent you from creating more than one instance
@KonradRudolph but it's still a global. Just like a static class variable is. :)
 
@sehe Why would you expect that? It’s stupid on your part, and this isn’t restricted to singletons either, it’s a common thing
@jalf It may, what do you know?
 
@KonradRudolph Which I don't, because they're global state.
 
9:08 AM
@KonradRudolph Well, if it does, then it's a singleton, and then it's stupid. ;)
 
@DeadMG Well then you restrict yourself meaninglessly
 
Good code gives points to:
a) performance
b) scalability
c) maintenance friendly
d) readability
e) can be easily expanded
f) minimal WTF/s when you see it 6 months from now.
 
it's not meaningless at all
 
@jalf It’s not necessarily a singleton
 
Singletons fail on so many levels.
 
9:08 AM
global state is horrendously bad and avoiding it is unambiguously good
 
We fail on so many levels.
 
there are plenty of use-cases for builder functions that may return identical objects upon execution
such as Integer.valueOf in a language we love to hate
 
that's memoization of an immutable object, not a mutable global
 
and say what you will about Java, caching of certain instances of Integers is a good thing
@DeadMG Wait, who was talking about mutables here?
I certainly wasn’t
 
@Konrad PODs are better.
 
9:09 AM
@KonradRudolph So what is it?
 
@RadekdaknokSlupik Not. The. Point.
 
why not? everybody who sees an immutable but globally accessible object says "constant"
 
@jalf Not a singleton
 
Sometimes things are inherently global, like a connection to a hardware interface. A singleton can be helpful here.
 
mutable? global. immutable? constant.
 
9:10 AM
I don't know what your class does, but if you have something that enforces that only one instance can ever be created, it suffers from the same critical design flaw as a singleton
 
that's the terminology
 
@jalf Are you intentionally not reading what I write? Please tell me what is bad about Integer.valueOf memoising values
@DeadMG No, that’s your made-up terminology
 
@KonradRudolph Which happens to match the terminology of every other programmer I've talked to
 
@KonradRudolph I am reading what you write. But you're mixing two completely orthogonal issues
 
@DeadMG how would you call a global constant?
 
9:11 AM
@DeadMG That’s patently untrue, unless you’re not talking to me now
 
@RadekdaknokSlupik Pretty sure that an object can only ever be mutable or immutable.
 
@jalf No. I’m not.
 
@KonradRudolph other.
 
Caching requires that an instance of a cache is visible to whoever does the caching. It does not require that ONLY ONE CACHE CAN EVER BE CREATED
 
@DeadMG And I doubt even that claim
 
9:12 AM
Hm, caps lock unleashed
This is now violent
 
Holy, this argument makes me question how much of programming I really know. I've never heard any of this terminology (though I can infer what it means at least)
 
Global state is bad.
 
Caps lock is a piece of shit. Remap it to Ctrl.
 
@jalf Singletons invoke emotion!
 
Hides dependencies. Refactoring this shit is a nightmare.
 
9:12 AM
@jalf I have no idea what you’re on about. Integer has only one cache
 
Jeremy, the only word you should now is semantics. It makes you look smart.
 
lol
 
@KonradRudolph But would it suddenly stop working if it was possible to create a second instance of the cache class?
 
@Cicada you accidentally the word use.
 
@CatPlusPlus What dependencies does it hide?
 
9:13 AM
I accidentally indeed
 
Between global and whatever is using that global.
 
@jalf I don’t understand what you’re saying. There is simply no way to create a second Integer cache
 
int x;
void f(); // does it use a global, or doesn't it?
 
Additionally, yes, things might stop working
for instance when you create a second string interning pool
 
void f(int&); // dependency is explicit
 
9:14 AM
Java never worked.
 
@Jeremy I got that feeling too when I first came here.
 
"fifteen years ago"
 
@KonradRudolph then it's up to you to not mix them. But what if I'm implementing the Integer class myself, and I want to write test? I want to ensure that I can create new, empty caches for each test? What if I want to reuse the cache class to implement similar caching for another class than Integer?
 
@CatPlusPlus Uh, the whole point of a singleton, as opposed to a set of globals, is that you can (and should) pass it around as an object.
 
So that's why everyone doesn't do that.
 
9:15 AM
@jalf @KonradRudolph: You're both talking past each other. Konrad is talking from a specifications POV, jalf from an implementation POV.
 
A global tuple!
 
There is a huge difference between saying Integer should have its own cache instance", and "no one can ever use the cache class for anything else"
 
lol
 
Because why when you can do Foo::getInstance.
 
@jalf You are hopelessly tangling up in your own arguments. “then it’s up to you not to mix them” – yeah, fuck static typing, it’s up to you not to use the wrong type. What ever happened to the compiler helping you?!
 
9:16 AM
@KonradRudolph What?
 
And if you're passing it around, why is it a singleton, anyway? Just create it in main and pass along.
 
@KonradRudolph Somebody missed a cache line this morning. :P
 
Frankly I think the rage against Singletons is mostly a counter-reaction to newbies learning it as the first (and last) design pattern and start abusing it everywhere. Proneness to abuse is not enough reason to declare the Singleton as inherently evil.
 
@jalf Forget the frigging cache class, nobody ever sees that
 
Should I be able to specify, in the type system, my specifications? Yes, that's what it's for. And if I should only have of X in production code, I should be able to specify that.
 
9:16 AM
@CatPlusPlus That could mean huge depth of passing
 
@KonradRudolph I can have multiple instance of strings too, and it's up to me to not mix them.
 
@Cicada so what?
 
But C++ is not the language for that, so as jalf rightly points our you're probably not getting much benefit from the cost of doing a singleton, because for testing you're too committed to the singleton design; it's too engrained into the class itself.
 
@StackedCrooked I don't see any practical problem that singleton solves, and only new ones that it introduces.
 
@jalf I don’t get what you’re saying
 
9:17 AM
So, yes, it's inherently evil.
 
Singletons are not evil, not really. It's the man who uses it. Like a gun, it won't shoot 30 people in a rampage by itself. Shooting a bad guy once in a while is fine. Same goes for singletons.
 
@RadekdaknokSlupik Do you really want to add one argument to every single method that may call one that requires a singleton? It's self-propagating
 
If it were as simple as this: class X {}; (debug) class X[singleton] {}; (release), then hell yes singletons would be okay. But in C++ it's just not maintainable enough for testing.
 
But using a singleton everywhere, like a gun, is a bad idea.
 
@DomagojPandža that's an absurd argument
 
9:18 AM
Guns are designed to kill.
 
@CatPlusPlus Because it makes no sense to create more than one instance. So the Create method (whatever it’s called) just always returns the same instance
 
@KonradRudolph But why, why, why would you need that enforced.
 
@CatPlusPlus Haven’t we been way past that argument now?!
 
int main() { X foo; /* just use the friggin instance */ }
 
@CatPlusPlus It's the compiler's job to enforce your specifications.
 
9:18 AM
@CatPlusPlus you want to manage a resource of which there is always only exactly one.
 
very high-level analogy
 
VRAM, for example.
 
@CatPlusPlus That requires passing the instance very deep in the calls.
 
Except when you suddenly need two, because you want to test something.
 
You can argue all you want. In the end only I am entitled to the singleton.
 
9:19 AM
@DomagojPandža guns have their uses. There are real-world scenarios that would be hampered by the absence of guns. There are situations where a gun is a very useful tool. for singletons to be comparable, there needs to be situations wher they are useful tools, where they are actually "the right tool for the job"
 
@Cicada Yes, explicit dependencies.
 
I have never encountered such a situyation
 
You cannot have two VRAMs.
 
@CatPlusPlus Which is why C++ is not the right language for those kinds of specifications.
 
@jalf Good point.
 
9:19 AM
@RadekdaknokSlupik you can when the OS virtualizes your GPU
 
@CatPlusPlus Contagious explicit dependencies.
 
@DeadMG I don't mind global state as long as it's either read-only or write-only.
 
@CatPlusPlus With that technique any method depending on the object will make all callers depend on it.
Recursively
 
If they need that, they should specify that as part of the interface.
 
Also, stateless Singletons I can live with.
 
9:21 AM
@jalf kernel programming. :)
 
It's crucial for testing.
 
@FredOverflow free functions.
 
Testing code using singletons is nigh impossible.
 
@RadekdaknokSlupik Free functions cannot implement interfaces, at least not in mainstream languages :)
 
@CatPlusPlus On the contrary, it’s no problem at all, since you can just swap out the instance for a mock instance
 
9:22 AM
And all your precious constraints are being trumped by bugs.
 
@CatPlusPlus add a reset member function to reset the state for each test.
 
Oh, right, let's not test the thing I've written, let's test something else.
 
@RadekdaknokSlupik I've seen that. It doesn't work.
 
I've been in so many discussions regarding singletons, it's numbing me down. It's like discussing religion, no matter how absurd it is, there will always be people defending it. And there's simply no point in beating a dead horse. Write the code you think works best, perhaps by fact, perhaps by belief... And enjoy.
 
9:23 AM
Especially when someone adds new member and forgets to update that stupid reset.
 
I don't work either.
 
@RadekdaknokSlupik many machines have two GPUs. Oops, our vram is a singleton? Oh shit...
 
@jalf exactly
 
@CatPlusPlus this->~T(); new (this) T;
 
And even if there is only one VRAM, nobody prevents you from instantiating a class exactly once even if it isn't a Singleton :)
 
9:23 AM
Yes, more arcane code working around issues that singleton creates!
 
If I got the syntax right.
 
Moar moar!
 
There are plenty of places where you can get away with making something a singleton, because in practice, you typically only need one instance. If you're willing to sacrifice a few cornercase, plus testability and a few other things
 
You're just digging the hole deeper and deeper.
 
But there are no situations where you NEED the one-instance-and-one-instance-only guarantee of a singleton
 
9:24 AM
@FredOverflow the point is that nobody prevents you from creating multiple instances either.
 
@CatPlusPlus Well, either you want to test the actual object, in which case, go ahead, or you want to test a method but with a mock instance, in which case, pass another instance. Where is your problem?!
 
And if you don't need what a singleton "gives" you, why would you use it?
 
@RadekdaknokSlupik If not, then it's not a singleton and you just wasted time writing a class that enforces a constraint that's not really enforced.
 
@KonradRudolph How do you create "another instance" of a singleton?
 
@jalf You don’t, you have another class that implements the same interface
that’s how you usually mock
 
9:25 AM
@CatPlusPlus it's an implementation detail only visible to the test.
 
@RadekdaknokSlupik So? No one prevents you from creating a new std::ostream when you intended to use std::cout. Do you see that happening often? Should std::cout have been a singleton?
 
Tests cannot breach the contract, that's missing the point of testing.
 
Tests violate everything anyway.
 
@RadekdaknokSlupik If a programmer is too stupid to create exactly as many instances as he needs, he probably shouldn't be a programmer. I mean, if he cannot even get instance creation right, what else can we trust him with?
 
You're not going to say to the person writing client code "oh, you should just work around the singleton thing and create a new instance anyway".
 
9:26 AM
@FredOverflow Dereferencing dangling pointers?
 
@FredOverflow Uhm, that is just stupid, sorry
 
That's an Olympic sport, I hear.
 
"— Then why is it a singleton in the first place? — Oh, um, so you don't create more than one."
 
@FredOverflow people can make mistakes.
 
@RadekdaknokSlupik You correct the mistake and move on. No singletons involved. :Đ
 
9:27 AM
@RadekdaknokSlupik Again, show me the last time someone created a new std::ostream when they intended to write to cout
 
Now that's stupid.
 
@KonradRudolph No, it isn't. In many systems, you know exactly how many instances of a class you need, yet you don't enforce that there can only be exactly 10 instances of class Foo.
 
@CatPlusPlus That's not the point. The point is to always use the same instance. Not avoiding the creation of several
The latter is a consequence of the first
 
Yes.
 
9:27 AM
Singleton is explicitly about only one instance ever existing.
 
And most of the time, when you "know" you should only have one instance of something, you're wrong
 
@FredOverflow When it makes sense, sure, why not enforce it?
 
I use singletons whenever I want.
 
A year or two passes, and oops, I needed two instances after all!
That's why you shouldn't enforce it
 
@CatPlusPlus It's not about the number it's about that one instance
 
9:28 AM
@jalf Then remove the restriction. Type systems evolve
 
actively adding complexity to your code just to make it harder to adapt and maintain is insane
 
@Cicada Since when is 1 not a number?
 
@KonradRudolph ever tried turning a singleton into a non-singleton?
It is not pleasant
 
But entire codebase uses Foo::getInstance!
 
@FredOverflow You're misreading what I said
The goal of the singleton is that everyone is talking to the SAME instance
 
9:29 AM
@jalf Why not? It’s not a problem at all, just remove the restriction when creating instances
 
Conclusion: only create one
 
And that depends on three more singletons!
 
Not the other way around
 
And you don't even know about that, until you analyse the code, because dependencies are hidden deep in the implementation.
 
@KonradRudolph But again, why would I? Creating a singleton is more work up front, and then, later, when I find out I needed a second instance after all, it's even more work to remove it. Why would you do that?
 
9:30 AM
YAGNI, KISS.
 
@KonradRudolph The number of Foo instances a client needs is a property of the client (or even the entire system), not a property of Foo. Restricting Foo to n instances goes against all OO principles. Yes, I said it, Singletons are not object-oriented :)
 
@jalf Come on, the work is trivial. In both cases.
 
No, it's not.
 
@KonradRudolph You've never done it then
 
@FredOverflow It's not about restricting to n as I said
 
9:30 AM
If you think it's trivial, you've never seen a codebase littered with singletons and tried to refactor it.
 
removing a singleton from a nontrivial codebase is painful
 
@FredOverflow That’s wrong, it’s not always a property of the client. Haven’t we been over this in great detail now?!
@jalf I have
 
How I hope to see you on a major project in which you shoved a bunch of singletons a year ago which really keeps the thing together because it was the easy way out... And then you have to change something that is air-tight around your singleton(s). Well, I hope you stop by for a drink and tell me all about it. :P
 
@jalf It helps that I don’t call the accessor instance of the singleton instance since that implies singleton in the name.
@CatPlusPlus I never said that the wrong use of singletons makes it easy
but the right use does
 
@KonradRudolph Whether or not you have multiple VRAMS is not a property of VRAM itself.
 
9:31 AM
Don't use singletons because they are convenient.
Use them because they make sense.
 
@KonradRudolph I still need to see a "right use"
 
@FredOverflow It may be a property of the system though
 
I've never seen the right use.
 
I know of one or two situations where, to the best of my knowledge, you can probably get away with using a singleton. I have never ever seen a situation where using a singleton was actually beneficial
 
@KonradRudolph Right, so "the system" should do the appropriate thing. The VRAM class shouldn't assume it knows anything about the needs of "the system".
 
9:33 AM
@jalf What was wrong abut the resource manager then? Here, it’s not bad to have several instances but it also just makes no sense so I would definitely make its constructor private, to document that you don’t need to create more instances
@FredOverflow It’s a bloody part of the bloody system
 
sbi
> All discussions come back to the Windows registry eventually. — Walenty's law /cc @ScottW
 
@KonradRudolph You gain nothing by doing it.
You don't need to document that "you shouldn't do something that makes no sense".
 
@jalf Of course you do, self-documenting code. Also, you lose nothing by doing it, if you just do it right
 
Because it makes no sense. That was the premise. So why would anyone do it?
 
Exactly. If it makes no sense to people, they won't do it. You can't accidentally do it.
@jalf BINGO.
 
9:34 AM
@jalf I highly suggest you read Effective C++ then, because this is just wrong
 
@KonradRudolph Making VRAM a Singleton restricts its use to systems where there is only one VRAM. You can't reuse it in other systems. You make the class more complicated and less usable. Why would anyone want to do that?
 
@KonradRudolph Calling your resource manager "resource manager" makes it self documenting. It documents that this is a resource manager. You should use it as if it were a resource manager. How many of them you want is up to the user
 
Aren't managers an anti-pattern? :)
 
@FredOverflow Well, if that’s the case, don’t make it a VRAM then. I didn’t forward this argument, I don’t know the specifics well enough to argue for or against the use of multiple VRAMs
 
sbi
Uh oh. Now the starboard is overflowing with messages contra Singletons.
 
9:35 AM
@FredOverflow Usually, yes
 
@jalf Again, your arguments can be used, 1:1, to argue against static type systems in general
 
What if I want several sets of resources?
 
“singleton” is just one other property of a type that can be statically verified
 
@KonradRudolph Sure. But in that case, other arguments apply as well, so the outcome is (potentially) different
 
@jalf Not really
 
9:36 AM
@KonradRudolph You can argue all day about static type systems vs. dynamic type systems. I don't think there is a right answer. Both have strengths and weaknesses.
 
Not really is not really an argument.
 
sbi
@ScottW You make it easy to be tracked down. It took about 2mins. (You published a link to some company, and google found me your name for it.)
 
About threading data along, you just need a Reader monad, and problem solved.
 
@CatPlusPlus Yay, Monads > Singletons :)
 
Obviously.
 
9:37 AM
@FredOverflow Yes, but that’s not the point. The point is that jalf’s argument against the use of singleton to document a specific aspect of a type is a general argument against the usefulness of type checking
 
@KonradRudolph No, it's an argument against that aspect being desirable.
 
Not even only static type checking, incidentally
 
@KonradRudolph My point is that your "documentation" is wrong. You are documenting that "only one resource manager can exist" when that is not logically true. It was not a property of the code until you decided to "document" it
 
What if I want to manage two sets of resources?
 
You take a class which works fine with multiple instances, and add "documentation" saying "only one instance can be created", and suddenly, only one instance can be created
 
9:38 AM
Why should there be only one?
 
sbi
@ScottW From your SO profile to github.
 
@jalf No, it’s documenting “creating an element makes only sense through this function – which, oh, incidentally, only ever returns the same object but don’t care about that, just always use this method to create instances”
 
Maybe I should first cut the head off the singleton one?
 
@DeadMG His argument is more general, whether he likes it or not
 
This is not addressed to anyone in particular, but I'm getting tired of these sterile design discussions, especially regarding Singletons. Can we please just go back to discussing language features?
 
9:39 AM
@KonradRudolph You just said that there was no problem in having multiple resource managers. And honestly, I woudl probably usually want multiple resource managers
 
Should I bother referencing the books I read or should I just cut that out too? I ended up doing the robot thing and then the kernel thing to describe how I got in to it. The reason I chose the robot is because its about the closest thing I've ever done to firmware development (it was written for an embedded system)
 
@FredOverflow I've been thinking about a surprising aspect of Wide- kernel development.
 
@DeadMG Are you calling your language "Wide-" now instead of "Wide"?
 
@FredOverflow Like monads!
Wide--.
 
my plans for the binary ABI to cover exceptions could just be generalized into "exceptions as interface, return codes as implementation"
 
sbi
9:40 AM
@KonradRudolph I will regret to let myself be drawn into this, but... The general criticism of this is that you do not know whether, to a user of your class, it might not make sense to have more than one object, or a different one than what your function supplies, created with different parameters.
 
@jalf well, having more managers might be less efficient for instance. What do I know? But that wasn’t my point, my point was that it. just. makes. no. sense to call a constructor on this particular class.
 
and in addition, I can offer more control than C++ over compiler-generated functions
 
@DeadMG Interesting. You could use Go as an implementation language then ;) It has no exceptions, but multiple return codes.
 
why on earth would I do that?
 
sbi
@KonradRudolph It used to make no sense to allow more than 640k either.
 
9:40 AM
@sbi That is exactly what I have been saying all along. Over and out.
 
I'd still want real exceptions for user-mode code
 
@sbi As soon as there are parameters involved in the mix the argument becomes a completely different one – but even then, only the class itself knows how it’s constructed – or, indeed, whether a new instance should be constructed
 
sbi
@FredOverflow I know.
 
@sbi Totally different thing
 
@DeadMG I just wanted to mention Go, because I find it kinda interesting (in the sense that it is unusual, not that I think it is superior).
 
9:41 AM
The only argument for singletons that I can register with my system is called utter, ultimate, cat procrastinating laziness. I'd love to see a proper usage for the singleton design pattern for which a better one can't be found (and which is orders of magnitude more friendly to maintenance). If you're writing some experiment that's a one-night stand, then go ahead. But otherwise, contemplate better solutions.
 
@KonradRudolph Whoa. Trolling real hard there.
 
@KonradRudolph Well, my point is exactly that. "What do I know?" As the library implementer, you don't know exactly how people might want to use your library. So you should document what it can do. But you should not actively prevent it from being used in any situation other than the use case you had in mind
 
@FredOverflow Besides the go keyword, what's interesting?
 
@KonradRudolph I'm sure you're right. Not assuming things about builders is stupid on my part
 
@sehe No, it’s not.
 
9:42 AM
hallu
 
@Cicada I didn't mean I find Go interesting per se, but especially Go's "multiple return values instead of exceptions" approach.
 
@KonradRudolph I'm absolutely sure you didn't go back to the message that was a reply to.
 
Go's interfaces are interesting.
 
@jalf For the last time, only the object itself knows how it’s constructed. And that it includes the decision whether it’s constructed at all. It just so happens that in some special cases, this answer is “only once”. But the client should never care about this, it just uses the provided builder function
 
@KonradRudolph When I write an application, I decide what makes sense and what does not. I don't need the author of a library I use to do it for me. The library should protect against incorrect usage, sure, but it should not protect against "being in a situation that the library author had not anticipated"
 
9:43 AM
@FredOverflow I didn't find anything interesting about it
 
@DeadMG But it is unusual, isn't it?
 
@FredOverflow How?
 
My idea, or at least what I was trying upuntil life got busy again, was to write a programming language specifically for polymorphic code (code that can change its form.) Specifically meant to compile in to a unique and obsructed form for security purposes. It was just suppose to be for small snippets of code. I tried writing a code-polymorphism engine but I figured there were to many unknowns after the code was compiled that caused limits.
 
sbi
@KonradRudolph No. I do not want a class I am supposed to use to restrict how and how often I can instantiate it. If I need only one object of it, I can create just one object, even if it's not a singleton. If I need more than one, it being a singleton is a major show-stopper. BTDT. It took days to make changes throughout a multi-100kLoC codebase (what with singletons being global state, rather than parameters passed down), and introduced tons of bugs. Nasty.
 
Multiple return values are cool.
 
9:43 AM
@KonradRudolph That's absurd. The user of the class needs to know what object it's given
 
@DeadMG Well, what other modern language uses multiple return codes instead of exceptions?
 
the only thing I remember about "Go" was "C but more suck"
 
I need to know "do I get a newly created cache instance, or do I get one that's full of everyone else's data"
 
@sehe No, assuming that you always get back a different instance is.
 
It's definitely less sucky than C.
If only because of interfaces, defer and modules.
 
9:44 AM
@sbi Why is it a show-stopper? Why do you care, as a client, how many instances are created? Why should e.g. Integer.valueOf not be allowed to cache values?
 
no exceptions == suck
 
@KonradRudolph Well, fuck me. I didn't say that. You could. Of course it depends on the docs of that API. You were reducing singletons to private-constructibles + builder. It's not the same. Period
 
Integer cache is an implementation detail, not an exposed interface.
 
@jalf It knows everything about the object that it needs to know. Namely, that it fulfils the contract that is documented. Everything else is implementation detail
 
@KonradRudolph Integer is not a Singleton. You are talking about caching immutable objects, which is a completely different story.
 
9:45 AM
It's about things you use directly.
 
@sehe It is the same thing in my view. Where is the difference, pray?
@FredOverflow sbi’s argument wasn’t about singletons
 
I couldn't care less what's used to implement a cache, I don't deal with it.
 
@FredOverflow More like Flyweight
 
@KonradRudolph One of them is mutable, and the other is not.
 
This goes nowhere. Time to do something useful.
 
9:46 AM
@KonradRudolph Imagine java.util.ArrayList was a Singleton, because James Gosling only used one list in his little toy programs.
 
Though, I question if its do-able with meta-template programming in C++ (which, now that I think of it, it may be). WHich is why my programming language idea was stupid. Lol.
 
@DeadMG Now you completely confused me. Which one is mutable and which one isn’t, then?!
 
@KonradRudolph That builders might return different instances on repeated invocation. <whistle/> Or perhaps depending on context (time, thread, calling context)
 
@FredOverflow Having it as a singleton makes no sense, so it isn’t one
 
@KonradRudolph The one whos mutability is exposed.
 
9:47 AM
@Jeremy So, you've tried to reinvent LISP?
 
if the returned object is immutable, then it's no problem- if the exposed object is mutable then it is a problem
 
@sehe But they might not. In which case (and only then!) they are a singleton. That’s all I was ever saying
 
45 mins ago, by sehe
I'd say, the greatest threat posed by Singleton is the potential to derail any conversation between developers and waste all creative energy.
 
@KonradRudolph It makes sense as long as you only need one list. A lot of toy programs fall into this category. And then one day, you need multiple lists, and you're screwed.
 
@DeadMG And which one’s is that? I seriously have no clue what you are talking about
 
9:48 AM
Tbh, I've never looked at list. Does it do something similar?
 
sbi
@KonradRudolph In that case, the singleton was a DoThatEngine, and the guy who wrote it was guaranteed that there never ever would be a need to DoThat twice at the same time. Well, PM was wrong about that, the guy had left by the time (but wrote me a mail about it when I complained to him), and we were stuck with repairing the design at any cost, adding function parameters across all the codebase. That was hell.
 
@KonradRudolph Please reread what you actually did say and then consider whether you really need to put up a fight about it.
 
lisp*
 
[RFC] New room policy: we don't talk about singletons, ever.
 
@FredOverflow Stop being stupid guys, this is not a serious discussion any more.
 
9:48 AM
lol
 
@sehe I re-read it, I still understand it the same way. If that’s now what you meant, please explain it.
 
@Jeremy It's designed around the idea of code = data. Also, you can edit your messages for up to 2 minutes, see newbie hints.
 
sbi
room topic changed to Lounge<C++>: If you can't help it, bring a naked pointer. But, please, no singleton! [c++] [c++11] [c++-faq]
 
@sbi Well, then the design was messed up – but not because of the singleton, but rather because the client code probably used the object wrong. I’m guessing because everybody invoked the instance method themselves, rather than passing an object?
 
Which is 99% cases when singletons are used.
 
sbi
9:50 AM
@KonradRudolph Yeah. That's what we've been saying all along: If there's a singleton, then the design is messed up. Not because the client code used the object wrongly, but because requirements change, and the class wasn't up to it.
 
So advocating them is harmful.
 
Ah, I see. And thanks for the tip. testedit
 
@sbi Read my edit.
 
Yarr, my pointer is naked ... well, that's kinky ... i think i'd stick with raw pointer ^^
 
9:51 AM
btw, I would never advocate the use of a singleton, and having it as a “design pattern” is just fucking stupid in my opinion. It just so happens that sometimes a builder function happens to always return the same object …
 
Didn't Erich Gamma admit that the Singleton Design Pattern was a huge mistake?
 
@sbi Then add an additional builder function (or change the existing one), shouldn’t be a problem, no? The change should be totally localised.
 
sbi
@FredOverflow Yep.
 
You know what I'm gonna do? I'm gonna go to my library, borrow every Design Patterns book there is and rip the Singleton chapter out. That's my contribution to making the world a better place.
 
sbi
@KonradRudolph The problem is that every singleton is also usable as a globalton. If there can only ever be one of them, you can access that single on right away, wherever you need it, can't you? And, bang!, you're doomed.
 
9:52 AM
lol
 
How bout we talk about pointers vs references for a change?
0
Q: Do the advantages of using references over using pointers justify occasional "null-references"?

StackedCrookedI'm currently designing a class hierarchy that looks roughly like this: struct Protocol { // Pass lower-layer protocol as a reference. Protocol(Protocol & inLLProtocol) : mLLProtocol(inLLProtocol) { } // A protocol "always" has a LLProtocol. Protocol & mL...

 
Occasional null references? WTF is that supposed to be?
 
@sbi That is something we can agree on.
 
@FredOverflow For lack of a better name.
 
Null reference is ill-formed.
 
9:53 AM
"When discussing which patterns to drop, we found that we still love them all. (Not really—I'm in favor of dropping Singleton. Its use is almost always a design smell.) " Mr. Erich Gamma
 
@StackedCrooked Dereferencing a null pointer to bind it to a reference is UB.
 
@StackedCrooked And now you’ve given up the most important advantage of references, i.e. that they can never be null
 
You cannot dereference a nullptr. It's UB.
 
sbi
@KonradRudolph And in order to avoid this problem, avoid singletons. They are nothing more than glorified global state. And they bring all the problems global state brings (bare a minor one: it cannot be overwritten by a new instance).
 
@sbi I’m insisting that it sometimes makes sense not to have a public constructor and to provide builder functions instead. And then we’re back to square one.
In fact, were it up to me, I’d re-design C++ to have no constructors at all, and only builder functions
 
9:55 AM
Dereferencing a nullptr opens a portal to NULLand where bloodthirsty unicorns and their multithreaded brothers, multicorns, torture people who propagate usage of singletons.
 
@KonradRudolph Given that you are wary of the global aspect of singletons as well all in all it doesn't strike me that you're advocating singletons.
 
@LucDanton Like I said above, I’d never advocate them. It just so happens that sometimes a class with a private constructor happens to only ever provide a single object
 
Which reminds me, mid as well ask; anyone have any advice for:
http://stackoverflow.com/questions/10670985/i-need-help-developing-a-polymorphism-engine-instruction-dependency-trees
 
@DomagojPandža I like your answer for the wild exponents of e.
 
I haven't got much of a response on it, and it doesn't seem to by an easy topic to find material on (maybe I am looking in the wrong direction though.)
 
9:59 AM
0
A: Plagued by multithreaded bugs

DeadMGYour code has significant other issues apart from just that. Manually deleting a pointer? Calling a cleanup function? Owch. The fact that this multithreaded bug is occurring is just a symptom of the core problem- your code has bad semantics in any threading situation and you're using completely u...

upvotes please, I'm feeling insecure on Programmers
 
@ScarletAmaranth Glad to be of service. =)
 
@KonradRudolph This is schizophrenic though because you have the function to get access to what happens to be the same instance every time and yet to make dependencies explicit you want would-be users to accept the type as a parameter, right?
 

« first day (587 days earlier)      last day (4360 days later) »