5 ms·
If you have a single CS bone in your body, you should be able to grok at least the basics of regex. If you don't, then go back to designing* I guess, and ask f
by pmarreck 8y ago
If you have a single CS bone in your body, you should be able to grok at least the basics of regex.
If you don't, then go back to designing* I guess, and ask for a programmers' help
* I only say this because I recently saw a tweet from a frontend designer person who said she thought regex was the worst technology ever invented and she absolutely hated it.
Disclaimer: For whatever reason, I'm a big fan. Concisely describe patterns in text and match on them? Plus the puzzle-fun of figuring out how to match on what you're looking for? Yes, please. (And yet, on certain programmer teams, I've had to scale back my regex usage because of you folks who refuse to just learn it, sigh)
- simonrobb 8y ago> If you have a single CS bone in your body, you should be able to grok at least the basics of regex. Sure, but I don't think the existence of this lib implies the author disputes that, and I can only imagine they're pretty familiar with regex themselves. I think they're trying to fill a legitimate need in frontend dev, which is: if you're only touching regex a few times a year, it's pretty intimidating, and not at all maintainable. SQL can also be difficult to grok if you don't write it often, and ORM interfaces make it easier. Would the world be a better place if everybody knew regex perfectly? Yeah ok it would, but investing a bunch of time learning something you will only occasionally use is a poor investment IMO. > If you don't, then go back to designing* I guess, and ask for a programmers' help This seems to be needlessly condescending? You can be an excellent programmer (particularly in frontend) for years while avoiding regex. It's not a make-or-break thing.
- stevew20 8y agoIt's only condescending if being a designer is "lesser" than being a front end developer.
- dgritsko 8y agoI agree with you. They can certainly be abused, like anything else ("now you have two problems!"). But crafting a beautiful regex when it's exactly the right tool for the job is extremely satisfying. I think if more people took the time to understand them and practice writing them (when appropriate), they wouldn't have such a stigma.
- valarauca1 8y agoI think if more people took the time to understand them and practice writing them (when appropriate), they wouldn't have such a stigma. I think this is part of the movement to a more "ide/web centric" development model. The chances to interaction with regexes on CLI are endless. Grep, git-grep, vim, sed, etc. Even bash has some limited regex integration. As a person who still does most their development in the cli with vim regexes are a massive part of my work flow I actively use them several times per day. When people move away from this model there are a lot opportunities to practice regexes. I've noticed this my own workflow when working Java-centric languages (who's IDE's often have poor regex integration).
- ken 8y agoWhy is this level of brevity desirable, and only with regular expressions? Are you writing APL? Why not?
- giantsloth 8y agoYou are putting forth the logical fallacy of "no true scotsman", ie no TRUE CS person dislikes or doesn't understand regex. You are are also straw-manning her tweet, by suggesting that she is unable to grok the basics of regex, when in fact, she actually seems to have stated that it's the worst and she hates it, not that she doesn't understand it. From a "good for business" perspective, you also seem like you might be an overall drain on your team, as you elevate puzzle-fun and brevity over understanding your audience, ie that other people on your team don't know regex (or "refuse to learn it") and that you have to scale back your regex usage. I also wouldn't say that I use my CS chops (which I will define as my ability to discern algorithms and design patterns out of bits of code that I write), but rather my ability to put up with the tedium of sitting in a repl and slowly figure out how to write the arcane incantation necessary in as few esoteric characters as possible to perfectly search out the text I want. Also, it's hard for me to understand how you are writing code with regex that you have to tear our, because your coworkers don't understand it. Whenever I write regex, I hide them behind function calls that are easy to grok: const hasFirstName = (blockOfText) => /some-ugly-regex/.test(blockOfText) ... if (hasFirstName(uglyButUniformBlockOfText)) return `has firstName!`
- pygy_ 8y agoThe regular formalism is very neat and I like to use it, but the RegExp syntax doesn't do it justice. They are pretty much write-only, and there's no way to compose two regexps safely (new `RegExp(a.source, b.source)` breaks for `/a|A/, /b/, for example). Rex is a good attempt at solving this. I wrote a similar lib a while ago (more functional and tighter in design, see my other comment on this page).
- viggity 8y agoI think one reason why most people have a hard time reading regex is because they don't use any indentation or linebreaks. Honestly, if a buddy came to you and asked you to help him debug a javascript method and all 15 statements were on the same line, would you offer to help him, or tell him to fix his shit first so you can read it? What if it was all on one line and his variable names were all "v1", "v2", etc. Would you help him then? fuck no. And yet, this is standard operating procedure with regex, except you don't even get "v1", "v2" because nothing is labeled at all. v1/v2/... would be an improvement! This is how most people write a simple date regex: \d{1,2}/\d{1,2}/(\d{4}|\d{2}) And mind you, this is a very simple scenario. Here is how you would write it if you treated it like actual code: (?<month>\d{1,2}) / (?<day>\d{1,2}) / (?<year>\d{4}|\d{2}) First off, you can know what my intent is when I'm capturing each group. Maybe this code gets used by a european where the month and day switch places. They can figure out how to fix it in like two seconds. Secondly, the forward slashes are not lost in a sea of characters anymore because we use whitespace like a civilized developer, not a regex savage.
- pmarreck 8y agoI also use this form but it’s even more complex to some people than the one-liners, which I guess doesn’t help the impediment-factor
- komali2 8y ago>If you don't, then go back to designing* I guess, and ask for a programmers' help Was this actually necessary to say? It's not only insulting to people who don't need/care about/currently know regex, while simultaneously insulting of designers' intelligence.
- pmarreck 8y agoProbably not. As I said I recently read a tweet from a designer so it was fresh in my mind.
- bhengaij 8y agoI'm a CS guy through and through. Regular languages, cfl, ..... Np complete, what was the books name again? But I gotta say, regex isn't the best way to show things. Hard to verify, hard to maintain and what not. Computer sciency, sure. But not well "designed". Now I have no love lost for people who talk about stuff without understanding the fundamentals or the basics even. So I don't doubt that the person was "whatever". But I do feel that regexes need an overhaul Ps: I'm a fan too when I have to do quick stuff in shell. But not so much when I save it to a file to be read by me and multiple people weeks later. Regex is one thing that is way easier to write than read.
- pmarreck 8y agoWhich is why I use expanded regex with each section commented.
- bhengaij 8y agoWhat is expanded regex?
- grzm 8y agoThey're likely referring to the \x modifier, also called extended regular expressions: https://stackoverflow.com/questions/24642616/what-are-extended-regular-expressions https://stackoverflow.com/questions/24642616/what-are-extend...
- bhengaij 8y agoI had not known about this- makes things so much easier to maintian