r/programminghorror • • Oct 11 '26

Lua i sure do love not using local variables!

Post image

getfenv getfenv getfenv getfenv!

299 Upvotes

23 comments sorted by

107

u/SceneOutside4377 Oct 11 '26

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

5

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Oct 11 '26

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

2

u/DroneCyn Oct 12 '26

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 Oct 17 '26

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.

42

u/emazv72 Oct 11 '26

Stack allocation sucks. I'm joking

28

u/Linuxmartin Oct 12 '26

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 Oct 11 '26

Fent env

23

u/boiledbarnacle Oct 11 '26

Hey! He was paid by the char.

18

u/No-Point8651 Oct 11 '26

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

16

u/akoOfIxtall Oct 11 '26

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 Oct 18 '26

I think that plus it works is the definition.

2

u/Opposite_Mall4685 22d ago

Good code is like a cognitohazard. You know what good code is by knowing what good code isn't.

6

u/WannaCry1LoL Oct 12 '26 edited Oct 12 '26

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

5

u/Sophira Oct 12 '26

I love having impossible-to-debug race conditions.

2

u/JohnVonachen Oct 11 '26

DRY. Don’t repeat yourself.

4

u/Right_Ear_2230 Oct 13 '26

You just did

2

u/DesiresQuiet Oct 12 '26

Lua just makes me sad.

2

u/Havunenreddit Oct 13 '26

This is very inefficient code btw...

2

u/kwead Oct 14 '26

LMAO i think we were all once roblox studio spaghetti chefs

1

u/anderbaka Oct 12 '26

Classic Luau.

1

u/hammerclawz Oct 12 '26

W roblox luau

1

u/dosenscheisser Oct 13 '26

I dont even know where to start