There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

stephfinitely , in The temptation is always there

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.

idunnololz , in The temptation is always there
@idunnololz@lemmy.world avatar

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

HurgletOfficial ,

I do this all the time in Python by creating a class like


<span style="font-weight:bold;color:#a71d5d;">class </span><span style="color:#0086b3;">Core</span><span style="color:#323232;">:
</span><span style="color:#323232;">    foo </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"bar"
</span>
ryannathans ,

That’s not immutable nor a singleton

xmunk ,

That makes it inherently multithread compatible!

magic_lobster_party ,

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

wreckedcarzz ,
@wreckedcarzz@lemmy.world avatar

As a hobby coder: “mmmhm, mmmm, mmhm… I know some of these words!”

SkyNTP ,

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 ,

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

Anonymousllama ,

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

shotgun_crab ,

Yeah yeah let’s put all the eggs in one basket

xmunk ,

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

idunnololz ,
@idunnololz@lemmy.world avatar

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 ,

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

z3rOR0ne ,

Ah yes. Global Objects, AKA the thinnest of condoms, lol.

Techmaster ,

Just call it “state management” and nobody will even care.

mdk_ ,

So you saying, just the tip?

CoWizard , in The temptation is always there

Have you tried 'd global variables? Should definitely make things easier to read

CannotSleep420 , in The temptation is always there

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

UndercoverUlrikHD , in The temptation is always there

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 ,

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.

rodolfo ,

amen

Plus, there’s always the temptation to do it the shitty way and “fix it later”

double amen

magic_lobster_party ,

// TODO: Fix later

squaresinger ,

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

PetDinosaurs , (edited )

Bruh. I fixed software from the 90’s.

Scientific software too. Which is way weirder.

😀

decerian ,

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 , (edited )

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.

squaresinger ,

That’s like what happens if From Software made programming challenges.

Railcar8095 ,

Later is the name of the intern my company hired when I resigned :)

rodolfo ,

I wish I was so lucky to have comments.

in real life, I’m fighting with - I’m not joking - a few dozen “quick patches”. code does not reflect in any point functional requirements, and dude is adamant he’s in the right and supersarcastic in any occasion.

PetDinosaurs ,

I’ve been working at my current company for almost a year.

I had no idea it could be this bad.

I actually had to fight/plead with someone to “please read the code”. Guy did get fired though.

FlickOfTheBean ,

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 ,

What industry do you work in?

FlickOfTheBean ,

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 ,

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!

magic_lobster_party ,

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

FlickOfTheBean ,

Ah yeah, that would be a worry, except I forgot to mention that most of the code I work on usually gets thrown away after like 6 months. Makes tech debt not have nearly as big of an impact on me.

We do have a longer lasting code base that the little widgets I make run off of. That has a much more strict requirements to ensure tech debt is not introduced specifically so we don’t end up in that sort of a position.

That said, and yet we couldn’t even keep it out of our own code base. So yeah, I think my original comment is just wrong because I forgot all the ways tech debt actually has effected me in the past and how my industry’s project cycle is so short term that i rarely have the opportunity to run into tech debt that I caused in a problematic way…

magic_lobster_party ,

That make sense. Most industry best practices are there to prevent problems that arises when code is evolving over a long period of time.

FlickOfTheBean ,

Yeah, that makes total sense.

Most software engineers also have to actively maintain and add features to their finished project, and those aspects change a lot about how the problem can be approached.

I failed to take into account why might I have not been effected by tech debt despite occasionally creating it before commenting. Will have to make sure that filter gets a bit stronger lol

squaresinger ,

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

SkyeStarfall ,

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

squaresinger ,

That’s how this industry works ;)

Maddier1993 ,

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

manapropos ,

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

nogrub ,

and thats why we are reading a book about clean code at my apprenticeship

yiliu ,

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 ,

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 ,

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 ,

But those would be constants, not variables.

CapeWearingAeroplane ,

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

Slotos ,

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

CapeWearingAeroplane ,

My void* doesn’t care about your const!

magic_lobster_party ,

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.

insomniac ,
@insomniac@sh.itjust.works avatar

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

Dave ,
@Dave@lemmy.nz avatar

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

Synthead ,

Pointers hard!! LOL

ZILtoid1991 ,
@ZILtoid1991@kbin.social avatar

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.

fluxion ,

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

GTG3000 ,

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.

Successful_Try543 , in The temptation is always there

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 ,

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 ,

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 ,

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

Successful_Try543 ,

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 , (edited )

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

Successful_Try543 ,

Productive research is also hard to imagine with such coding practice either.

Techmaster ,

That’s why when your job hires new people right out of college they have no idea what they’re doing and now must be trained how to actually do the job. “What, you mean we aren’t writing this enterprise application in python!?”

rtxn ,

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.

wreckedcarzz ,
@wreckedcarzz@lemmy.world avatar

Oh they were paying, way too much

SquishyPandaDev , in The temptation is always there
@SquishyPandaDev@yiffit.net avatar

Obligatory, mutable global variables are evil.

magic_lobster_party ,

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

marcos ,

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

Yen ,

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.

marcos ,

Well, starting with the definition from algebra, where it’s not something allowed to vary…

I guess more people know about math than use imperative programing languages.

SkyeStarfall ,

Except that’s exactly what it is allowed to in algebra.

Sure, in most equations you solve in early algebra school there is only one possible value for the variables. But in many equations there can be multiple, or even infinite. It’s an unknown, and the contents can vary (depending on other constraints, ie. The rest of the equation(s)).

marcos ,

There’s no time in algebra for your variables to vary.

When you have a non-unitary set of solutions, you have a constant non-unitary set of solutions.

drcouzelis ,
@drcouzelis@lemmy.zip avatar

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

BassTurd ,

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

Walnut356 ,
@Walnut356@programming.dev avatar

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 ,

As opposed to immutable variables

confused screaming

yiliu ,

Or mutable constants…

Eufalconimorph ,

<span style="color:#323232;">int const golden = 1.618;
</span><span style="color:#323232;">int* non_constant = (int*)&amp;golden;
</span><span style="color:#323232;">golden = 1.61803399;
</span>

Casts are totally not a danger that should require a comment explaining safety…

Eufalconimorph ,

And more generally mutable aliasing references of any sort are evil. Doesn’t mean they’re not useful, just that you need magic protection spells (mutexes, semaphores, fancy lock-free algorithms, atomics, etc) to use them safely. Skip the spell or use she wrong one, and the demon escapes and destroys all you hold dear.

TheSlad , in emacs

Meanwhile webstorm/intelliJ users:

signature look of superiority

empty wallet

jelloeater85 ,
@jelloeater85@lemmy.world avatar

Nope 😉

www.jetbrains.com/community/opensource/#support

www.jetbrains.com/community/dev-recognition/

Plus their Java and Python IDEs have free community versions as well.

onlinepersona , in Did someone say emacs?

IBM thinkpad in the background with a CRT

I can send it to you via FTP

Nailed it.

edinbruh ,

But he’s using a model M, not a symbolics space cadet. Totally inaccurate

Johanno , in classic configure neovim experience

Jetbrains junkie here. What do you need a terminal Editor for?

darcy , in emacs
@darcy@sh.itjust.works avatar

sigma vim user

mutter9355 ,

Omega neovim user

darcy ,
@darcy@sh.itjust.works avatar

gigachad ed user

Chunk ,

Ed is king. Every single time I have to work on a severely resource constrained system I always use Ed.

That’s literally never happened to me but that won’t stop me from saying it.

mutter9355 ,

I mean, I don’t know how severly resource constrained a system has to be to not even be able to run vi.

Gentoo1337 ,
@Gentoo1337@sh.itjust.works avatar

You haven’t seen my grandma’s pc

mutter9355 ,

No, but I have seen my grandma’s pc

AVincentInSpace ,

I once used Linux on an actual honest-to-God teletype.

Granted, it was set up as a novelty and the thing it was hooked up to was a Pi 4, but still.

amycatgirl ,
@amycatgirl@lemmy.blahaj.zone avatar

enlightened echo user

Chunk ,

Except I’m too dumb to use even the neovim plugin manager let alone configure the thing. I have to copy existing configs like a noob :(

mutter9355 ,

Isn’t copying from others how everyone does (neo)vim? Besides, I’m even “worse” and just use lazyvim.

azdalen , (edited ) in emacs

deleted_by_author

  • Loading...
  • Corr ,

    I use vscode with vim plugin. I find this to be a pretty great combo, for me at least

    Cube6392 ,

    VS Code + vim plugin is sooo slooow. I’m happy it works for you but I can’t wait to finish on boarding my onboarding buddy so I can go back to vim where I belong

    XTornado , (edited )

    I do too… but it’s not perfect. If you use the extension that uses neovim in the background is seems is the best option but still I miss my “never needing a mouse” feeling I had on emacs. I mean maybe is just lack of knowing keybindings… but back on the day when I used spacemacs it was all so intuitive.

    I also miss magit…

    yetAnotherUser ,

    What does CUI mean?

    ursakhiin ,

    I genuinely think it’s funny that in a post that isn’t making fun of Emacs you felt the need to defend Emacs.

    It’s making fun of Emacs users for always finding ways to talk about Emacs. (Which I don’t think is a real problem anymore)

    narc0tic_bird , in emacs

    You guys recommend VSCodium over VSCode. Is there a working sync solution similar to the one built into VSCode where you can sync all settings and extensions between machines?

    QuazarOmega ,

    Yes! It’s this one open-vsx.org/extension/zokugun/sync-settings I really like it for using a normal repository over a “gist” and so you can also use any git server provider, I think the developer is also a contributor of VSCodium itself

    mykneedoesnthurt , in emacs
    @mykneedoesnthurt@kbin.social avatar

    What's a plugin? What's VSCode?

    DBase IV does not need any of this.

    Syudagye , in classic configure neovim experience
    @Syudagye@pawb.social avatar

    that is accurate

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines