1075
top 50 comments
sorted by: hot top controversial new old
[-] UndercoverUlrikHD@programming.dev 144 points 9 months 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 85 points 9 months 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 44 points 9 months ago

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

[-] SkyeStarfall@lemmy.blahaj.zone 16 points 9 months 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 9 months ago

amen

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

double amen

[-] magic_lobster_party@kbin.social 21 points 9 months ago
[-] squaresinger@feddit.de 22 points 9 months ago

In a 10 year old commit from someone who's left the company 5 years ago.

[-] PetDinosaurs@lemmy.world 8 points 9 months ago* (last edited 9 months ago)

Bruh. I fixed software from the 90's.

Scientific software too. Which is way weirder.

😀

load more comments (3 replies)
load more comments (3 replies)
[-] FlickOfTheBean@lemmy.world 8 points 9 months 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)

[-] magic_lobster_party@kbin.social 7 points 9 months ago

For me most of the people who have written our most annoying tech debt left the company long time ago.

load more comments (3 replies)
load more comments (3 replies)
load more comments (2 replies)
[-] insomniac@sh.itjust.works 59 points 9 months ago

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

[-] Synthead@lemmy.world 13 points 9 months ago

Pointers hard!! LOL

[-] Dave@lemmy.nz 10 points 9 months ago

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

[-] yiliu@informis.land 26 points 9 months 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 19 points 9 months 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 (6 replies)
load more comments (3 replies)
[-] idunnololz@lemmy.world 85 points 9 months 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 48 points 9 months ago

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

[-] magic_lobster_party@kbin.social 40 points 9 months ago

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

[-] wreckedcarzz@lemmy.world 38 points 9 months ago

As a hobby coder: "mmmhm, mmmm, mmhm... I know some of these words!"

[-] SkyNTP@lemmy.ml 37 points 9 months ago* (last edited 9 months ago)

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@lemmy.world 7 points 9 months ago

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

[-] Anonymousllama@lemmy.world 22 points 9 months 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 9 months ago

So you saying, just the tip?

[-] xmunk@sh.itjust.works 9 points 9 months ago* (last edited 9 months ago)

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

[-] idunnololz@lemmy.world 8 points 9 months 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 9 months ago

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

load more comments (4 replies)
[-] SquishyPandaDev@yiffit.net 46 points 9 months ago

Obligatory, mutable global variables are evil.

[-] magic_lobster_party@kbin.social 32 points 9 months ago

The definition of a variable is that it’s mutable. If it’s immutable it’s constant.

[-] marcos@lemmy.world 15 points 9 months ago

There's no ISO standardized definition for variable. People use that word with all kinds of meaning.

[-] drcouzelis@lemmy.zip 18 points 9 months ago

Waaaait a minute... isn't it called a variable because the contents are, you know, variable?

load more comments (1 replies)
[-] Yen@feddit.uk 11 points 9 months ago

This is needlessly obtuse. The definition of the word is that it's non-constant. There isn't an ISO definition of the word no, but there are many reputable dictionaries out there that will serve as an alternative.

load more comments (3 replies)
load more comments (1 replies)
[-] QuazarOmega@lemy.lol 10 points 9 months ago

As opposed to immutable variables

*confused screaming*

load more comments (2 replies)
load more comments (1 replies)
[-] KittyCat@lemmy.world 28 points 8 months 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.

load more comments (4 replies)
[-] fsxylo@sh.itjust.works 27 points 9 months ago

Singletons:

Me: O_O;

[-] alphacyberranger@lemmy.world 22 points 8 months ago

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

[-] darcy@sh.itjust.works 12 points 8 months ago

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

load more comments (1 replies)
[-] Successful_Try543@feddit.de 20 points 9 months 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 9 months 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 9 months ago* (last edited 9 months 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 9 months 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 9 months ago* (last edited 9 months 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.

[-] magic_lobster_party@kbin.social 8 points 9 months ago* (last edited 9 months ago)

Lecturers at universities tend to have little to no industry experience at all.

load more comments (2 replies)
load more comments (2 replies)
[-] winterayars@sh.itjust.works 18 points 8 months ago

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

load more comments (1 replies)
[-] stephfinitely@lemmy.world 14 points 9 months 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 13 points 8 months ago* (last edited 8 months 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 9 months ago

Me putting everything in 'public:'

[-] dingleberry@discuss.tchncs.de 7 points 9 months ago

Exhibitionist Devs be like.

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

Programmer Humor

18253 readers
1 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