922
you are viewing a single comment's thread
view the rest of the comments
[-] UndercoverUlrikHD@programming.dev 123 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.

[-] insomniac@sh.itjust.works 59 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 24 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 19 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?

[-] CapeWearingAeroplane@sopuli.xyz 1 points 1 year ago

Unironically: For in-house scripts and toolboxes where I want to set stuff like input directory, output directory etc. for the whole toolbox, and then just run the scripts. There are other easy solutions of course, but this makes it really quick and easy to just run the scripts when I need to.

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

But those would be constants, not variables.

[-] CapeWearingAeroplane@sopuli.xyz 1 points 1 year ago

I typically don't declare them as such - bring the pitchforks!

[-] Slotos@feddit.nl 1 points 1 year ago

Everything’s a variable if you’re brave enough.

[-] CapeWearingAeroplane@sopuli.xyz 2 points 1 year ago* (last edited 1 year ago)

My void* doesn't care about your const!

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

In software that’s already badly engineered. Either you do the work and refactor everything, or accept it’s probably not worth all the effort.

[-] fluxion@lemmy.world 2 points 11 months ago

As with the sexual connotation here, the temptation is not rooted in long-term considerations like future maintainability

[-] ZILtoid1991@kbin.social 2 points 1 year ago

Depends on what you're doing. Functional programming has its own downsides, especially once you want to write interactive programs, which often depend on global states. Then you either have to rely on atoms, which defeat the purpose of the functional programming, or pass around the program state, which is janly and can be slow.

I personally go multi paradigm. Simpler stuffs are almost functional (did not opt for consting everything due to performance issues), GUI stuff is OOP, etc.

[-] GTG3000@programming.dev 1 points 11 months ago* (last edited 11 months ago)

Well, if you're writing something the user will be looking at and clicking on, you will probably want to have some sort of state management that is global.

Or if you're writing something that seems really simple and it's own thing at first but then SURPRISE it is part of the system and a bunch of other programmers have incorporated it into their stuff and the business analyst is inquiring if you could make it configurable and also add a bunch of functionality.

I also had to work with a system where configurations for user space were done as libraries setting global constants. And then we changed it so everything had to be hastily redone so that suddenly every client didn't have the same config.

[-] PetDinosaurs@lemmy.world 1 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 0 points 1 year ago

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

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

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

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

That's how this industry works ;)

[-] Maddier1993@programming.dev 1 points 7 months ago

You're gonna see that even if you were pious at your own job. So you're only wasting time.

this post was submitted on 08 Oct 2023
922 points (96.4% liked)

Programmer Humor

19315 readers
94 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