1093
top 50 comments
sorted by: hot top controversial new old
[-] UndercoverUlrikHD@programming.dev 143 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 84 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 44 points 1 year ago

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

[-] SkyeStarfall 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 18 points 1 year 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 1 year ago
[-] squaresinger@feddit.de 22 points 1 year ago

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

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

Bruh. I fixed software from the 90's.

Scientific software too. Which is way weirder.

😀

[-] decerian@lemmy.world 5 points 1 year ago

Why is that weirder? The people writing scientific software are, by and large, less good at writing software than people who only specialize in software development. I'd expect there to tons of terrible engineering practices in an old code base like that

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

good question.

Because even trivial things like Fourier transforms (to people like me) are very difficult to understand to those that don't know them. They took me years to understand. Non scientific software engineers do not understand those. It's just a different course of education.

You're also right about old code base as well. Algorithms like these belong in c++ (or C or fortran), and it's extremely difficult to explain why to people who have no understanding of numerical computing.

It's just different education.

load more comments (1 replies)
load more comments (3 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)

[-] magic_lobster_party@kbin.social 7 points 1 year 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 60 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 20 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 (6 replies)
load more comments (3 replies)
[-] SquishyPandaDev@yiffit.net 48 points 1 year ago

Obligatory, mutable global variables are evil.

[-] magic_lobster_party@kbin.social 34 points 1 year ago

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

[-] marcos@lemmy.world 18 points 1 year ago

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

[-] drcouzelis@lemmy.zip 18 points 1 year 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 1 year 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)
[-] Walnut356@programming.dev 5 points 1 year ago* (last edited 1 year ago)

I feel like it's like pointers.

"Variable" refers to the label, i.e. a box that can contain anything (like *ptr is a pointer to [something we dont know anything about])

Immutable describes the contents, i.e. the stuff in the box cant change. (like int* ptr describes that the pointer points to an int)

Rust makes it very obvious that there's a difference between constants and immutable variables, mainly because constants must be compile time constants.

What do you call it when a variable cant change after its definition, but isnt guaranteed to be the same on each function call? (E.g. x is an array that's passed in, and we're just checking if element y exists)

It's not a constant, the contents of that label are "changing", but the label's contents cant be modified inside the scope of that function. So it's a variable, but immutable.

[-] 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)
[-] fsxylo@sh.itjust.works 27 points 1 year ago

Singletons:

Me: O_O;

[-] 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.

load more comments (3 replies)
[-] alphacyberranger@lemmy.world 22 points 1 year ago

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

[-] darcy@sh.itjust.works 11 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 16 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 22 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 7 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.

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

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

load more comments (2 replies)
[-] 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 17 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.

[-] fbmac@lemmy.fbmac.net 15 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

[-] stephfinitely@lemmy.world 14 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.

[-] 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 6 points 1 year ago

the meme is spreading

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

Nothing wrong with global variables.

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

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

Programmer Humor

19544 readers
689 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