There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

CannotSleep420 , in The temptation is always there

This, but with not making unit tests instead of global variables.

CoWizard , in The temptation is always there

Have you tried 'd global variables? Should definitely make things easier to read

idunnololz , in The temptation is always there
@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

xmunk ,

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

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.

manapropos ,

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

z3rOR0ne ,

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

Techmaster ,

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

mdk_ ,

So you saying, just the tip?

stephfinitely , in The temptation is always there

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.

Sanctus , in The temptation is always there
@Sanctus@lemmy.world avatar

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

pewgar_kbin , in The temptation is always there

the meme is spreading

fsxylo , in The temptation is always there

Singletons:

Me: O_O;

dylanTheDeveloper , in The temptation is always there
@dylanTheDeveloper@lemmy.world avatar

Me putting everything in ‘public:’

dingleberry , in The temptation is always there

Exhibitionist Devs be like.

alphacyberranger , in The temptation is always there
@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

gandalf_der_12te , in The temptation is always there

accurate

KittyCat , in The temptation is always there

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.

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?

Decompose ,

Is that you… Windows 95?

Fungah ,

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

BilboBargains , in The temptation is always there

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.

winterayars , in The temptation is always there

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

MrMagnesium12 ,
@MrMagnesium12@feddit.de avatar

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

ipkpjersi , in The temptation is always there

Nowadays they call it global state lol

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines