News for hackers. Stuff that matters.
Re:Coconut: Simple, elegant, Pythonic functional programming by sweezyjeezy on Thursday November 04, 2021 @09:41AM (#29107047)
> Regex has a reputation for being "write once read never". It's primarily because it doesn't have any structure or "modularity"

I don't think this is true - it's because people don't write regex every day - I used to write a lot of web-scrapers which involved getting pretty handy with regexes, it's fine, trust me. If a regex is REALLY hard to read - it's normally because it's badly written, or because it's trying to do something genuinely complicated.

Also how are they not modular? You always build up a regex from smaller regexes, maybe the modularity isn't always easy to follow, but it is there. e.g.

{regex1}{regex2} = regex1 followed by regex2 (concatenation) ({regex1}|{regex2}) = regex2 OR regex2 (OR operator) etc.

Your URL example can be broken down into smaller modules - e.g. there's a 3-way OR block at the start that cover http(s)://, www(123)., abc.aa/ (don't understand the last one..)

Re:Coconut: Simple, elegant, Pythonic functional programming by jimsimmons on Thursday November 04, 2021 @10:45AM (#29107833)
Modularity exists but it's not made explicit. I need to mentally track the level of nesting, column number, suffixes (*+?) etc. If the structure was made explicit, it would be a lot more readable. And expressing the composition gradually, bottom up, comes very close to the procedural specification.
Re:Coconut: Simple, elegant, Pythonic functional programming by sweezyjeezy on Thursday November 04, 2021 @11:35AM (#29108487)
There's no chance you're going to convince me that throwing out regexes in favour of writing EVERYTHING procedurally is a good idea. I fully agree that they should often be built programatically to improve readability and reduce duplication. But capture groups, lookahead operators, kleene stars - these are a drag to do manually, not to mention you lose regex compiler optimisations - regex is the way.
Re:Coconut: Simple, elegant, Pythonic functional programming by renewiltord on Thursday November 04, 2021 @06:05PM (#29113068)
Actually, what is the modularity concept in regexes? Is there a regex extension language where I can say "first match this then match that" but where I can name each part appropriately?
Re:Coconut: Simple, elegant, Pythonic functional programming by ModernMech on Thursday November 04, 2021 @06:55PM (#29113451)
At some point, you’re probably better off using an actual parser. Parser combinator libraries make writing such things very easy.