News for hackers. Stuff that matters.
Re:Singleton Is a Bad Idea by 32gbsd on Sunday April 10, 2022 @11:38AM (#30978030)
An exe is a singleton, a file is a singleton. Most things in a computer are singletons. We have been battling this OOP problem for decades. Memory mapped structure is volitile busy work. There is no perfect design pattern
Re:Singleton Is a Bad Idea by Matthias247 on Sunday April 10, 2022 @02:01PM (#30979773)
When you start executing a binary, it becomes a procoess. As long as the code in the binary allows for it, there can be multiple instances of it. So a exe/binary is more along of a regular class than a singleton.
Re:Singleton Is a Bad Idea by ardit33 on Sunday April 10, 2022 @02:43PM (#30980300)
If two process are modifying the same file.... that file is a 'single object'. So, the Parent's point stays. A process can create its own copy, and do things with it, but eventually it has to load and save it at one single place.
Re:Singleton Is a Bad Idea by gpderetta on Sunday April 10, 2022 @03:00PM (#30980494)
That's exactly the same as a specific non-singleton object instance. Processes have handles that represent open files.

The filesystem tree on an unix OS is a better example but that was also been identified as a mistake and there have been attempts to rectify it (namespaces)

Re:Singleton Is a Bad Idea by nedbat on Sunday April 10, 2022 @01:00PM (#30979037)
I don't know what you mean by "a file is a singleton": I have many files on my computer, and I can open any of them multiple times.
Re:Singleton Is a Bad Idea by postalrat on Sunday April 10, 2022 @02:14PM (#30979939)
And what happens when all those places you have the file opened want to write or read the file?
Re:Singleton Is a Bad Idea by philihp on Sunday April 10, 2022 @02:39PM (#30980257)
You fclose the handle when you're done, or you create some kind of synchronized semaphore, if you wanna be extra.

The issue is really around having multiple handles for writing (not just reading or appending), and the number of times you actually have this problem here is vanishingly rare.

Re:Singleton Is a Bad Idea by nedbat on Sunday April 10, 2022 @03:02PM (#30980516)
I'm not saying it's a good idea to open it more than once at the same time, but nothing is preventing me from doing it, so I'm not sure what is meant by, "a file is a singleton"?
Re:Singleton Is a Bad Idea by bdcravens on Sunday April 10, 2022 @02:30PM (#30980128)
In most cases nothing, the OS or applications will naively read it or write what they believe the current state to be.
Re:Singleton Is a Bad Idea by gpderetta on Sunday April 10, 2022 @02:29PM (#30980120)
They need to use some form if mutual exclusion? Same as for non-singleton objects in a process.
Re:Singleton Is a Bad Idea by yokaze on Sunday April 10, 2022 @04:28PM (#30981374)
> There is no perfect design pattern

There I can certainly agree, but ...

> An exe is a singleton, a file is a singleton. Most things in a computer are singletons.

I would say you are mistaking the instance for the class. An individual exe/file/... are instances of the abstract concept file or executable.

What you are interacting with is usually an instance, not a class.

Re:Singleton Is a Bad Idea by 32gbsd on Sunday April 10, 2022 @10:31PM (#30983927)
And a singleton is not an instance? Its all the same thing; 1 file, 1 instance. A file has properties, size, data memory, you can copy, paste it, delete it. A file has a type though generic.
Re:Singleton Is a Bad Idea by yokaze on Monday April 11, 2022 @03:56PM (#30993962)
> And a singleton is not an instance?

No, a singleton is a pattern that ensures that there is at most a single instance of a class.