Blackmist,

Nothing wrong with global variables.

If anyone asks just say it’s the singleton pattern.

fbmac, (edited )

I asked stable diffusion for a photo-realistic version of this image. This isn’t what I had in mind

https://lemmy.fbmac.net/pictrs/image/de77e7be-0909-44e4-a359-09f602ce8f01.webp

ipkpjersi,

Nowadays they call it global state lol

winterayars,

“But what if I put the whole program into a class and then made it a class wide variable?”

MrMagnesium12,

Sounds like the piece of legacy software I have do deal with.

BilboBargains,

Our Father, who art in Microsoft HQ,

hallowed be thy naming conventions;

thy architecture;

thy will be done;

on earth as it is in Linus Tech Tips.

Give us this day our daily StackOverflow.

And forgive us our 'sploits,

as we forgive those who trespass against our user stories.

And lead us not into temptation;

but deliver us from a thicket of global variables.

For thine is the irritating project manager, the power and the glory,

for ever and ever.

Or at least 7 years until obsolescence.

Amen.

KittyCat,

You can do better, define intergalactic variables that share the same memory location across multiple programs so you can seamlessly pass variables from one to the next.

Decompose,

Is that you… Windows 95?

Fungah,

But not sand memory. It’s coars ena drogjh and irritating and gets everywhere.

hansl,

The ONE TRUE CONSTANT; even with an infinite universe, the value is the same in all of them.

Fungah,

Are the legends really true?

gandalf_der_12te,

accurate

alphacyberranger,
@alphacyberranger@lemmy.world avatar

Is it an orgy if multiple global variables are used in a multi threaded code?

darcy,
@darcy@sh.itjust.works avatar

not if everyone uses a Mutex. stay (thread) safe

noli,

Always practice safe stacks

dingleberry,

Exhibitionist Devs be like.

dylanTheDeveloper,
@dylanTheDeveloper@lemmy.world avatar

Me putting everything in ‘public:’

fsxylo,

Singletons:

Me: O_O;

pewgar_kbin,

the meme is spreading

Sanctus,
@Sanctus@lemmy.world avatar

Ironically, a guy named SingletonSean showed me how to avoid singletons.

stephfinitely,

I am not a programmer who knows how to program. I know this because global variables are how I fix most the issue I run into, but are constantly told this wrong.

idunnololz,
@idunnololz@lemmy.world avatar

Just create a global object and stuff your variable in there. Now you have a global singleton and that’s not a purely bad practice :D

HurgletOfficial,

I do this all the time in Python by creating a class like


<span style="font-weight:bold;color:#a71d5d;">class </span><span style="color:#0086b3;">Core</span><span style="color:#323232;">:
</span><span style="color:#323232;">    foo </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"bar"
</span>
ryannathans,

That’s not immutable nor a singleton

xmunk,

That makes it inherently multithread compatible!

magic_lobster_party,

Not necessarily a bad practice if the singleton is immutable, and it’s provided via dependency injection for example.

wreckedcarzz,
@wreckedcarzz@lemmy.world avatar

As a hobby coder: “mmmhm, mmmm, mmhm… I know some of these words!”

SkyNTP,

Software dev is full of obscure keywords that describe otherwise pretty simple or basic concepts you stumble upon in practice naturally and that you probably already understand.

  • singleton: a class/object that is designed to be single use, i.e. only ever instantiated with a single instance. Typically used when you use class/objects more for flow control or to represent the state of the program itself, rather than using it to represent data
  • immutable: read-only, i.e. unchangeable
  • dependency injection: basically when you pass a function or object into another function object, thereby extending their effective functionality, typically for modular code and to separate concerns.

Here’s one more of my favourite examples of such a keyword: memoization

Solemarc,

Ahh yes memoization, the complicated way to say “remember this, I might need it again”

Anonymousllama,

Important to contain all your mess to one side of the room, makes it easier to manage

shotgun_crab,

Yeah yeah let’s put all the eggs in one basket

z3rOR0ne,
@z3rOR0ne@lemmy.ml avatar

Ah yes. Global Objects, AKA the thinnest of condoms, lol.

xmunk,

Real enterprise programmers know that everything should be on the stack… so they declare a List《void*》 in main.

manapropos,

Real enterprise programmers know you can get another job in the next year or two so fuck best practice

idunnololz,
@idunnololz@lemmy.world avatar

But we might need to add more features in the future so it might not just be a list in a few years. Better encapsulate it in a few layers of abstractions just to be safe.

Techmaster,

Just call it “state management” and nobody will even care.

mdk_,

So you saying, just the tip?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • DreamBathrooms
  • ngwrru68w68
  • cubers
  • magazineikmin
  • thenastyranch
  • rosin
  • Durango
  • InstantRegret
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • mdbf
  • ethstaker
  • JUstTest
  • osvaldo12
  • tester
  • modclub
  • normalnudes
  • everett
  • GTA5RPClips
  • tacticalgear
  • Leos
  • anitta
  • megavids
  • cisconetworking
  • provamag3
  • lostlight
  • All magazines