i concur, i work with a mathematician and their code is full of variables named named by a single character, zero comments, and zero spacing/indentation (we don’t write python).
This is essentially a custom string fingerprint/hash function disguised as a parser. It takes a string and deterministically turns it into an integer. It does not parse or extract useful structured data.
I don't know if JS sports this, but the recursion qualifies for tail call optimisation, i.e. there is no stack pushing, popping. The return comes at the price of a goto and the result is just as efficient as a loop.
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)
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.
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?
I don't see anything "malformed", but pretty sure (?:\w|[^\w\s]) is just .
Yes, almost. It's any single word character, or any single character that's neither a word character nor a space. So it's simply "not a space character", or [^\s].
Regex is powerful, but for anything except the simplest matching unless you work with it every day, totally unusable for anything complicated in my opinion. Right up there with the language APL for programming (and lisp isn’t far behind).
I wish there was a language that allowed you to express text parsing/processing in a more readable language (like a pascal for text or something). It can translate into anything it wants internally but there is no reason the human readable input should be any more obscure than C.
Because I started my career by working with embedded C, I thought at some point that I knew pretty much everything about handling bits. Years later while fixing a bug, I was pretty shocked learning that JS has a separate >>> operator.
286
u/LapidistCubed Aug 28 '26
My first thought is a mathematician wrote this
86
u/madam_zeroni Aug 28 '26
Wtf does this do
16
u/lonkamikaze Aug 29 '26
I don't know if JS sports this, but the recursion qualifies for tail call optimisation, i.e. there is no stack pushing, popping. The return comes at the price of a goto and the result is just as efficient as a loop.
22
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 ris 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)5
u/flafmg_ Aug 29 '26
Wtf my eyes are seeing
4
u/OhMyGodItsEverywhere Aug 29 '26
Pretty sure the regex is malformed. I didn't even think you could split a regex over multiple lines in JS like that.
Assuming this is the text version of it:
/(\((?:[^()]|\([^()]*\))*\)|(?:\w|[^\w\s])){1,3})/; very easy mistake to spot /s...1
u/questionabl3_dude Sep 02 '26
Which language is this?
2
u/stilldebugging Aug 29 '26
Something something pumping lemma something
2
u/oweiler Aug 29 '26
Performance gonna bet great /s
2
u/RandalSchwartz Aug 30 '26
JSON Parser as a single Perl Regex: https://perlmonks.org/?node_id=995856
2
u/Perahoky Aug 30 '26
terrible code. way to many instructions per space and bad naming and no comments
2
u/AnArmoredPony Aug 30 '26
im not reading allat
2
u/BussyEnthusiasts Sep 01 '26
Does your codebase have a character limit or something? Why are all the variables a single char?
2
u/hongooi Aug 28 '26
This is just the logical conclusion of the jwz quote 🤷♂️
1
u/thejozo24 Aug 30 '26
If there ever was a need for almost per line comments, this would be it
1
u/FedUp233 Aug 30 '26
Regex is powerful, but for anything except the simplest matching unless you work with it every day, totally unusable for anything complicated in my opinion. Right up there with the language APL for programming (and lisp isn’t far behind).
I wish there was a language that allowed you to express text parsing/processing in a more readable language (like a pascal for text or something). It can translate into anything it wants internally but there is no reason the human readable input should be any more obscure than C.
0
u/Ariquitaun Pronouns:This/Self Aug 29 '26
This is almost certainly ai generated. Or a mathematical savant.
0
u/[deleted] Aug 28 '26
[deleted] — view deleted comment
122
u/[deleted] Aug 28 '26
[removed] — view removed comment