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.

winterayars , in The temptation is always there

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

MrMagnesium12 ,
@MrMagnesium12@feddit.de avatar

Sounds like the piece of legacy software I have do deal with.

fbmac , (edited ) in The temptation is always there
@fbmac@lemmy.fbmac.net avatar

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

https://lemmy.fbmac.net/pictrs/image/de77e7be-0909-44e4-a359-09f602ce8f01.webp

ipkpjersi , in The temptation is always there

Nowadays they call it global state lol

BilboBargains , in The temptation is always there

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.

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.

o11c , in Every Single Freaking Time

I don’t remember the last time I used ctrl-C. It’s always select or "+y.

bellsDoSing ,

I additionally mapped that latter one to F2, because being able to repeatedly copy from VIM and paste into another application without having to move your hand between mouse and keyboard is nice.

Of course, that’s VIM. If you meant “vim mode” in shell, then that’s a different story.

fl42v ,

And I just set clipboard unnamedplus

gandalf_der_12te , in The temptation is always there

accurate

dingleberry , in The temptation is always there

Exhibitionist Devs be like.

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

Me putting everything in ‘public:’

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?

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

bloopernova , in emacs
@bloopernova@programming.dev avatar

I generally code in VSCode, and manage org-roam notes and information in Emacs. Works well enough for me.

netchami ,

Any particular reason why you don’t code in Emacs? Since you already set up Org Mode and Org Roam, I’m sure you know how the configuration works and how to write some Elisp. It’s actually not that much work to set up all the things you would need for programming (lsp-mode, etc.)

bloopernova ,
@bloopernova@programming.dev avatar

I guess I just preferred VSCode for coding? Every time I’ve tried to use Emacs for my coding workflows I’ve given up, I think I’m just used to VSCode in that respect. It is weird, I know.

fsxylo , in The temptation is always there

Singletons:

Me: O_O;

pewgar_kbin , in The temptation is always there

the meme is spreading

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

Ironically, a guy named SingletonSean showed me how to avoid singletons.

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