|
My reply is encapsulated in my reply to Nelek, up above. In short, if it works for you, it works. That's all that matters.
|
|
|
|
|
I use singletons freely, especially as flyweights[^]. But there are also other uses, such as threads that each perform a specific function.
|
|
|
|
|
Wow, flyweight. You don't hear much about that pattern being used. I've implemented it once but then it didn't get used in prod anyways.
|
|
|
|
|
David O'Neil wrote: Globals are a tool.
I agree with that. I just think that in Python they made globals to default like that to make it easier for people learning to program. However, I don't think it makes it easier really. It is confusing in a different way really.
David O'Neil wrote: But if I found a place where a Singleton absolutely made sense, I'd use a Singleton
That's good balance. Also, I like a Singleton for app configuration. There really is only one app config but there it is also a good candidate because it is made up of multiple properties which probably means having them all together in one object is nice instead of spread around in the code where you have to look everywhere to find them.
|
|
|
|
|
The Python code you posted looks ugly. I agree with your assessment. My reply to your other point is encapsulated in my reply to Nelek, up above. If it works for you, though, it works. And that's all that really matters.
|
|
|
|
|
David O'Neil wrote: If it works for you, though, it works. And that's all that really matters.
Yeah, I agree to a point. I'm working on some old prod code right now that is written in Java.
Because the original dev didn't understand anything he created every variable as a global.
The code is 2500 lines or so and it does some important prod work that is very simple --- or could be simple if the code wasn't so terrible.
Now you can't tell if you can change the variable you are looking at in the method way down on line 1000 because it may be used somewhere else and you can't tell if your change will kill it.
Side Effects
These are side effects. And they are really bad. The new paradigm of Functional Programming has a main point of attempting to remove all side effects because they are so difficult to manage. In Functional Programming, no function should ever create a side effect. Globals do the exact opposite.
Also, my main point about Python is the way that everything you declare and use automatically gets placed in the global namespace. That will always seem crazy to me.
|
|
|
|
|
raddevus wrote: Because the original dev didn't understand anything he created every variable as a global.
Oh, you poor, poor soul! I can only imagine the cuss-fest! I'd be right there cussing with you! Blame that on HR hiring incompetents! Unless it was created by the owner of the company, then you'd best polish your resume!
|
|
|
|
|
David O'Neil wrote: Unless it was created by the owner of the company, then you'd best polish your resume!
Yeah, it is a tough one. The company I work for was a "Startup" back in '98 or so and basically hit the ground running. Owner hired a "friend who could program" and so a lot of crazy stuff was created.
Slowly we are getting rid of it, but of course it is like changing the wings while flying.
|
|
|
|
|
Stop using Python and rediscover inner peace?
Just a thought!
|
|
|
|
|
Super Lloyd wrote: Stop using Python and rediscover inner peace?
I agree. but it goes back to the fact that lots of Python libraries have arisen out there that let you import and call a function and it does everything for you.
It's like candy for kids. They know they should eat nutritional food, but they keep coming back to candy.
|
|
|
|
|
Globals have a place.
Right next to GOTO.
|
|
|
|
|
Or even ...
def printGlobal():
print(str(extra))
extra = 35
printGlobal()
extra = "Python are stupid."
class Arsinine:
def __init__(self):
printGlobal()
a = Arsinine()
|
|
|
|
|
Exactly! More proof that globals are terrible and cause confusion.
But, I'm sure the Genius-Global-Creating-Devs* can keep track of them in their minds.
*Was a good example of this a soft troll?
|
|
|
|
|
|
Cp-Coder wrote: get a Kindle They are not immune to viruses.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Cp-Coder wrote: What is wrong with people stupid enough This pandemic has brought the stupid out in a lot of people. The most obvious, in my opinion, are those claiming not wearing a mask is the same as murder.
Some would say microwaving to disinfect might be resourceful.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
After reporting this story, microwaving of library books grows by 1000% as bored lock-ins get ideas.
|
|
|
|
|
Try a cfl lightbulb!
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
Clearly people is stupid... they should stab the book with a wood stick and put it into the bonfire along with some marshmallows...
|
|
|
|
|
Cp-Coder wrote: get a Kindle or something! Those won't survive the microwave either
|
|
|
|
|
Shhhhhhhhh! Don't cancel the video entertainment orders.
|
|
|
|
|
Put some ketchup on them and they're quite tasty though.
Jeremy Falcon
|
|
|
|
|
|
Should aggressive fishermen attend Angler Management Therapy?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The social workers are trawling for clients again.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|