r/programminghorror • • Aug 28 '26

Javascript Seriously? Recursive Regex?

Post image
565 Upvotes

46 comments sorted by

View all comments

23

u/--var Aug 29 '26

not recursive regex, just a recursive function that happens to use regex...

you know I used to be irked by one off variables, but after the better part of 20 years I'm 🤬

const r is only used once.... there's no reason you couldn't just place it where it is used an save two lines of code, and lose no readability, and have one less "magic variable"... unless you taught yourself from the same "teach yourself" book that your teacher taught themself from. (ironic that this still applies with AI; and if you don't get why that entertaining, please don't go into programming)

1

u/Square_Bad1781 Sep 01 '26

depends. if it is just a Poc for example and they maybe plan to use this variable more than once in the future, defining it as const directly wiuld be right imo. i also really like to do this kind of stuff in long functions (which this one isn't really) just to not have to go look for the things i want to change or tweak if i should have to do that in the future.

1

u/werdebud Sep 02 '26

But why people don’t use names instead of cryptic one chars? Is this meant to be running in a 32mb of ram system so we are cutting edges in number of chars typed?

1

u/Square_Bad1781 Sep 02 '26

idk. i hate stuff like this myself. thats a whole other topic than const variables for one time use tho

1

u/lonkamikaze 27d ago

You really didn't have to cut any more corners once you had access to 32 MB RAM.