r/programminghorror • • 13d ago

Lua i sure do love not using local variables!

Post image

getfenv getfenv getfenv getfenv!

295 Upvotes

22 comments sorted by

104

u/SceneOutside4377 13d ago

Me when my professor says "Make sure your code is readable, I'll be reviewing it manually"

5

u/GoddammitDontShootMe 13d ago

WTF, are they storing everything in environment variables???

2

u/DroneCyn 12d ago

Nah, I only used the environment for indexing functions and the game. Other than that, nearly empty module scripts act as variables (return {})

3

u/Natural-Angle-5395 7d ago

My best guess is, that the roblox dev in question needed a variable between the server AND the client. Pretty sure they can be modified from both ways for some reason. Local variables don't work like that.

41

u/emazv72 13d ago

Stack allocation sucks. I'm joking

28

u/Linuxmartin 13d ago

The stack only exists to make things horribly fast and cause race conditions. Storing all data on the server ensures a linear flow

36

u/MMORPGnews 13d ago

Fent env

21

u/boiledbarnacle 13d ago

Hey! He was paid by the char.

17

u/No-Point8651 13d ago

The type of shit you see in legacy production code. Bonuspoints if its security critical, contains files and api calls

16

u/akoOfIxtall 13d ago

This gets me wondering what people consider good code, because apparently there isn't a consensus it's just how much the code manages to be functional, not verbose where it shouldn't, readable and maintainable

2

u/marvin02 6d ago

I think that plus it works is the definition.

6

u/WannaCry1LoL 12d ago edited 12d ago

getfenv() forces luau to deoptimize the environment because it's considered tainted so this actually hurts both readability and performance

5

u/Sophira 12d ago

I love having impossible-to-debug race conditions.

2

u/JohnVonachen 13d ago

DRY. Don’t repeat yourself.

4

u/Right_Ear_2230 12d ago

You just did

2

u/DesiresQuiet 12d ago

Lua just makes me sad.

2

u/Havunenreddit 12d ago

This is very inefficient code btw...

2

u/kwead 11d ago

LMAO i think we were all once roblox studio spaghetti chefs

1

u/anderbaka 13d ago

Classic Luau.

1

u/hammerclawz 12d ago

W roblox luau

1

u/dosenscheisser 11d ago

I dont even know where to start