1058
top 50 comments
sorted by: hot top controversial new old
[-] UndercoverUlrikHD@programming.dev 135 points 1 year ago

Is it really tempting for people? They've given me too many headaches when I've had to reformat or add functionality to files.

Unless it's a simple single use script that fit on the computer screen, I don't feel like global variables would ever be tempting, unless it's for constants.

[-] PetDinosaurs@lemmy.world 81 points 1 year ago

Most people suck at software engineering.

Plus, there's always the temptation to do it the shitty way and "fix it later" (which never happens).

You pay your technical debt. One way or another.

It's way worse than any gangster.

[-] squaresinger@feddit.de 42 points 1 year ago

Not if you leave the project soon enough. It's like tech debt chicken.

[-] SkyeStarfall@lemmy.blahaj.zone 16 points 1 year ago

Then, at your new job, you see garbage code and wonder what dumbass would put global variables everywhere

load more comments (2 replies)
[-] rodolfo@lemmy.world 20 points 1 year ago

amen

Plus, there's always the temptation to do it the shitty way and "fix it later"

double amen

load more comments (1 replies)
[-] FlickOfTheBean@lemmy.world 8 points 1 year ago

Rarely have I ever actually had consequences for my sins, which tends to be why I don't go back and fix them....

If tech debt weight is felt in any way, it tends to get fixed. If it's not felt, it's just incredibly easy to forget and disregard.

(This is mostly me not learning my lesson well enough from my time being on Tech Debt: The Team. I do try and figure out the correct way to do things, but at the end of the day, I get paid to do what the boss wants as cheaply as possible, not what's right :/ money dgaf about best practices until someone gets sued for malpractice, but on that logic, maybe the tech debt piper just hasn't returned for payment from me yet... Only time will tell)

[-] PetDinosaurs@lemmy.world 4 points 1 year ago

What industry do you work in?

[-] FlickOfTheBean@lemmy.world 7 points 1 year ago

Fair point, I work in a consumer facing, fast turn around, short lived code project industry. Not a typical software project with long life cycles.

These practices would almost certainly bite my company in the ass if we had to maintain anything for longer than year.

Occasionally, we do have to support a client for multiple years, and everytime it's a hilarious shit show trying to figure out how to keep all the project dependencies up to date. This is likely platform tech debt, and would be the beginning of the problem if we didn't have the privilege of being able to start over from scratch code-wise for each client's new order.

I guess I'm just in a lucky spot in the programmer pool where tech debt literally doesn't hit me as hard as it usually does others, and I just couldn't identify that before now lol

Instead of saying tech debt isn't that bad, my tune will change to something else. Like I said, I was on a team at one point that had a worse than usual tech debt problem, and it was unworkably stressful to deal with. Im guessing that experience is more typical of being near tech debt than my other experiences.

[-] PetDinosaurs@lemmy.world 7 points 1 year ago* (last edited 1 year ago)

Good on you for acknowledging that. 👍

I've fixed 20 year old issues that could kill people.

Different requirements. Different solutions.

That's why it's great to be an engineer!

[-] manapropos@lemmy.basedcount.com 3 points 1 year ago

If you’re smart you do it the quick and easy way and leave the company before it bites you in the ass. Only suckers stay with the same company for more than a few years

load more comments (1 replies)
[-] insomniac@sh.itjust.works 58 points 1 year ago

This community makes more sense when you realize the majority of users are CS students.

[-] Synthead@lemmy.world 13 points 1 year ago

Pointers hard!! LOL

[-] Dave@lemmy.nz 10 points 1 year ago

Hey, don't you group me in with people who have had a small amount of real training!

[-] yiliu@informis.land 26 points 1 year ago

They've given me too many headaches...

I.e. you did use them, but learned the hard way why you shouldn't.

Very likely OP is a student, or entry-level programmer, and is avoiding them because they were told to, and just haven't done enough refactoring & debugging or worked on large enough code bases to 'get' it yet.

[-] BorgDrone@lemmy.one 18 points 1 year ago

Is it really tempting for people? They've given me too many headaches when I've had to reformat or add functionality to files.

I don’t get it either. Why would you ever feel the need for them to begin with?

load more comments (5 replies)
load more comments (2 replies)
[-] idunnololz@lemmy.world 84 points 1 year ago

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

[-] Techmaster@lemm.ee 47 points 1 year ago

Just call it "state management" and nobody will even care.

[-] Anonymousllama@lemmy.world 21 points 1 year ago

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

load more comments (1 replies)
[-] mdk_@lemmy.world 13 points 1 year ago

So you saying, just the tip?

[-] xmunk@sh.itjust.works 8 points 1 year ago* (last edited 1 year ago)

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

[-] idunnololz@lemmy.world 7 points 1 year ago

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@lemmy.basedcount.com 7 points 1 year ago

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

load more comments (7 replies)
[-] SquishyPandaDev@yiffit.net 46 points 1 year ago

Obligatory, mutable global variables are evil.

[-] QuazarOmega@lemy.lol 10 points 1 year ago

As opposed to immutable variables

*confused screaming*

[-] yiliu@informis.land 5 points 1 year ago
load more comments (1 replies)
load more comments (1 replies)
[-] KittyCat@lemmy.world 27 points 1 year ago

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@lemmy.world 4 points 1 year ago

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

load more comments (1 replies)
[-] Decompose@programming.dev 3 points 1 year ago

Is that you... Windows 95?

load more comments (1 replies)
[-] fsxylo@sh.itjust.works 24 points 1 year ago

Singletons:

Me: O_O;

[-] alphacyberranger@lemmy.world 21 points 1 year ago

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

[-] darcy@sh.itjust.works 12 points 1 year ago

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

load more comments (1 replies)
[-] Successful_Try543@feddit.de 20 points 1 year ago

I've once had a course involving programming and the lecturer rewrote the code, which we were usually using at our institute, making ALL variables global. - Yes, also each and every loop counter and iterator. 🤪

[-] Chriszz@lemmy.world 17 points 1 year ago

There’s no way you teach a uni course and do this kind of thing unless to demonstrate poor practice/run time difference. Are you sure you were paying attention?

[-] Successful_Try543@feddit.de 17 points 1 year ago* (last edited 1 year ago)

Yes. He really thought it was efficient and would avoid errors if literally all variables were defined in a single Matlab function he called at the beginning of the script. We students all thought: "Man, are you serious?" As we didn't want to debug such a mess, in our code, we ignored what he was doing and kept using local variables.

[-] Chriszz@lemmy.world 23 points 1 year ago

Ah I misread I thought it was specifically a programming course. I can expect this from a math prof.

[-] Successful_Try543@feddit.de 8 points 1 year ago* (last edited 1 year ago)

Yes, it was a course on finite deformation material models. And no, you do really, really not want to declare each and every variable in your material subroutine globally for the whole finite element program.

[-] rtxn@lemmy.world 4 points 1 year ago* (last edited 1 year ago)

I've seen two teachers do this, both of them mathematics professors who teach programming for the extra cash. One uses C, the other Pascal.

load more comments (1 replies)
[-] winterayars@sh.itjust.works 18 points 1 year ago

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

[-] MrMagnesium12@feddit.de 7 points 1 year ago

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

[-] stephfinitely@lemmy.world 13 points 1 year ago

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.

[-] fbmac@lemmy.fbmac.net 12 points 1 year ago* (last edited 1 year ago)

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

[-] dylanTheDeveloper@lemmy.world 8 points 1 year ago

Me putting everything in 'public:'

[-] dingleberry@discuss.tchncs.de 7 points 1 year ago

Exhibitionist Devs be like.

[-] BilboBargains@lemmy.world 6 points 1 year ago* (last edited 1 year ago)

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.

[-] pewgar_kbin@fedia.io 5 points 1 year ago

the meme is spreading

[-] Blackmist@feddit.uk 4 points 1 year ago

Nothing wrong with global variables.

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

[-] CannotSleep420@lemmygrad.ml 4 points 1 year ago

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

load more comments
view more: next ›
this post was submitted on 08 Oct 2023
1058 points (96.6% liked)

Programmer Humor

19503 readers
320 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS