this post was submitted on 08 Oct 2023
999 points (96.7% liked)

Programmer Humor

24736 readers
1737 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 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] UndercoverUlrikHD@programming.dev 135 points 2 years ago (6 children)

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 78 points 2 years ago (5 children)

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 38 points 2 years ago (1 children)

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

[–] SkyeStarfall@lemmy.blahaj.zone 15 points 2 years ago (2 children)

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 2 years ago (1 children)

amen

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

double amen

[–] magic_lobster_party@kbin.social 18 points 2 years ago (4 children)
[–] squaresinger@feddit.de 19 points 2 years ago (1 children)

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

[–] PetDinosaurs@lemmy.world 7 points 2 years ago* (last edited 2 years ago) (2 children)

Bruh. I fixed software from the 90's.

Scientific software too. Which is way weirder.

😀

[–] decerian@lemmy.world 5 points 2 years ago (1 children)

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 2 years ago* (last edited 2 years 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 2 years ago (4 children)

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 2 years ago (3 children)

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)
[–] yiliu@informis.land 25 points 2 years 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 17 points 2 years ago (6 children)

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 78 points 2 years ago (7 children)

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 42 points 2 years ago

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

[–] magic_lobster_party@kbin.social 34 points 2 years ago (1 children)

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

[–] wreckedcarzz@lemmy.world 32 points 2 years ago (1 children)

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

[–] SkyNTP@lemmy.ml 32 points 2 years ago* (last edited 2 years ago) (1 children)

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 2 years ago

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

[–] Anonymousllama@lemmy.world 19 points 2 years ago (1 children)

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 10 points 2 years ago

So you saying, just the tip?

load more comments (3 replies)
[–] SquishyPandaDev@yiffit.net 44 points 2 years ago (3 children)

Obligatory, mutable global variables are evil.

[–] magic_lobster_party@kbin.social 29 points 2 years ago (2 children)

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

[–] marcos@lemmy.world 15 points 2 years ago (2 children)

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

[–] drcouzelis@lemmy.zip 18 points 2 years ago (1 children)

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

[–] BassTurd@lemmy.world 4 points 2 years ago

It started as a variable, then ended as a constant.

[–] Yen@feddit.uk 11 points 2 years ago (3 children)

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 2 years ago* (last edited 2 years 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 9 points 2 years ago (1 children)

As opposed to immutable variables

*confused screaming*

[–] yiliu@informis.land 5 points 2 years ago (1 children)
load more comments (1 replies)
load more comments (1 replies)
[–] KittyCat@lemmy.world 25 points 2 years ago (4 children)

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)
[–] Successful_Try543@feddit.de 19 points 2 years ago (2 children)

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 16 points 2 years ago (3 children)

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 2 years ago* (last edited 2 years ago) (2 children)

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 21 points 2 years ago (1 children)

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 2 years ago* (last edited 2 years 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 2 years ago* (last edited 2 years ago) (2 children)

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

load more comments (2 replies)
load more comments (2 replies)
[–] alphacyberranger@lemmy.world 18 points 2 years ago

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

[–] stephfinitely@lemmy.world 14 points 2 years 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 2 years ago* (last edited 2 years ago)

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

[–] dylanTheDeveloper@lemmy.world 7 points 2 years ago

Me putting everything in 'public:'

[–] pewgar_kbin@fedia.io 6 points 2 years ago

the meme is spreading

[–] BilboBargains@lemmy.world 6 points 2 years ago* (last edited 2 years 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.

[–] dingleberry@discuss.tchncs.de 6 points 2 years ago

Exhibitionist Devs be like.

load more comments
view more: next ›