14 ms·
Source of the famous “Now you have two problems” quote (2006)
- JimWestergren 6y agoEarlier posted in 2015 with 60 comments https://news.ycombinator.com/item?id=10083420 https://news.ycombinator.com/item?id=10083420
- dang 6y agoYup, and 2013: https://news.ycombinator.com/item?id=5187686 https://news.ycombinator.com/item?id=5187686 (with a great top comment) and 2010: https://news.ycombinator.com/item?id=1195704 https://news.ycombinator.com/item?id=1195704
- rotifer 6y agoJeffrey Friedl has recently updated his blog post [1] (mentioned in the "great top comment"), referencing the various HN discussions over the years. It's all oddly satisfying, in a way... [1] http://regex.info/blog/2006-09-15/247 http://regex.info/blog/2006-09-15/247
- seph-reed 6y agoMy relationship with RegExp seems to be against the grain here. They're almost always a quick, simple, clean solution to any text parsing issue I've faced. Perhaps without tools like https://regexr.com/ https://regexr.com/ I would feel different though?
- xwdv 6y agoYou almost certainly would feel different.
- sushshshsh 6y agoI find that I can solve most of my jira tasks in 10 mins with string.length and string.charAt() My estimated time to completion with regex is literally undefined
- Moru 6y agoThat's just unfamiljarity. Whatever works for you is good. Sometimes the hammer does work on the screw, you just have to use it right. Or we might end up with https://xkcd.com/927/ https://xkcd.com/927/
- sushshshsh 6y agoWe're all unfamiliar with assembly and electrical engineering too right, should we all invest the time to learn how to program bare metal? Only when the performance is needed, right?
- Moru 6y agoNo, you completely misunderstood and went off on a tangent. My comment means the exact opposite to what you understood.
- Joeboy 6y agoI've never used tools like that and I feel the same. Regexes provide a simple, well supported solution to a huge number of problems, and I'm not sure what the second problem is supposed to be. The quote is fun, and I've sometimes used variants of it, but I don't get why the target is regular expressions.
- Moru 6y agoThe second problem comes when the regex fails because of the edge cases you didn't think of shows up. :-)
- blacksmith_tb 6y agoIt may have something to do with the complexity/inconsistency of the strings you're matching. I feel like often regexes work fine for me with a little fine-tuning, but I have certainly run into examples in code I didn't write (or even code I did, months or years ago) which took me a lot of time to really wrap my head around.
- pdpi 6y agoHave you tried parsing an email address with a regex? http://emailregex.com/ http://emailregex.com/
- Joeboy 6y agoHave you tried parsing an email address (in an RFC compliant way) without a regex?
- deckard1 6y agoto be fair, the email RFC is a silly document that does silly things. The user part of an email address "may" be case-sensitive. But in practice, no one does that. Because imagine grandma on the phone with her bank not remembering if her email address was Mary123@gmail.com, MARY123@gmail.com, or mary123@gmail.com. The horror.
- layer8 6y agoSome systems (used to) map the local part to local unix usernames, which are case-sensitive. Hence the sender would get a 550 No such user (or similar) if he got the case of the local part wrong.
- andyjpb 6y agoYes! http://wiki.call-cc.org/eggref/4/email-address http://wiki.call-cc.org/eggref/4/email-address https://bitbucket.org/knodium/email-address/src/master/email-address.scm https://bitbucket.org/knodium/email-address/src/master/email... It's a fair few lines of code but most of it comes directly from the RFC. It's also longer than it could be because it covers the entire RFC822 syntax, including groups, lists, routes, comments and To: header styles.
- DonHopkins 6y agoHave you tried parsing a regex with a regex? http://regexregex.com/ http://regexregex.com/ [WARNING: DO NOT CLICK THAT LINK OR YOU WILL BREAK THE INTERNET!]
- corpMaverick 6y agoIMHO. They are very practical as long as they stay simple. But there is a threshold you shouldn't cross.
- SoSoRoCoCo 6y agoYou're not wrong. I think OP is a generalized rant that is a bit dismissive of problem solving diversity. I think OP's gist is: if you don't understand a tool, don't use it. But even that is specious. Normal regular expressions have been around since Kleene, Chomsky and Russell started framing them in the 40s/50s. They are a powerful tool for lexical analysis, PERL showed us that in the early 90's. Dismissing them is just gatekeepy, IMHO.
- DonHopkins 6y agoJWZ> Fourth: I like PostScript, and it’s a safe bet that I’ve written more and hairier PostScript by hand than anyone reading this… but the syntax is as close to “write-only” as in any language I’ve ever used. Anyone who defends PostScript as being “readable” is a monster raving loony. Pththththth.ps! PostScript is too readable. (But he's right I'm a monster raving loony.) https://www.donhopkins.com/home/archive/NeWS/pizzatool.txt https://www.donhopkins.com/home/archive/NeWS/pizzatool.txt Here's a PostScript Pretty Plotter (among other things): https://medium.com/@donhopkins/the-shape-of-psiber-space-october-1989-19e2dfa4d91e https://medium.com/@donhopkins/the-shape-of-psiber-space-oct... https://www.donhopkins.com/home/archive/psiber/cyber/litecyber.ps https://www.donhopkins.com/home/archive/psiber/cyber/litecyb...
- gumby 6y agoDon, you are one of the few people deranged enough to write handwritten Postscript and surely have written more than jamie. Too much time spent reading the NeWS.
- DonHopkins 6y agoLeigh Klotz has written more PostScript than Jamie too, while working at Xerox! But "KLOTZ IS A LOGO PRIMITIVE [BEEP BEEP BEEP]". He wrote a 6502 assembler in Logo! https://news.ycombinator.com/item?id=13524588 https://news.ycombinator.com/item?id=13524588 Leigh Klotz's comment on the regex article: >OK, I think I’ve written more PostScript by hand than Jamie, so I assume he thinks I’m not reading this. Back in the old days, I designed a system that used incredible amounts of PostScript. One thing that made it easier for us was a C-like syntax to PS compiler, done by a fellow at the Turning Institute. We licensed it and used it heavily, and I extended it a bit to be able to handle uneven stack-armed IF, and added varieties of inheritance. The project was called PdB and eventually it folded, and the author left and went to First Person Software, where he wrote a very similar language syntax for something called Oak, and it compiled to bytecodes instead of PostScript. Oak got renamed Java. >So there. >And yes, we did have two problems… >— comment by Leigh L. Klotz, Jr. on June 7th, 2008 at 3:22am JST (12 years, 6 months ago) — comment permalink Arthur van Hoff (the author of PdB and the original Java compiler written in Java) has also written more PostScript than Jamie, especially if you count the PostScript written by programs he wrote, like PdB and GoodNeWS/HyperNeWS/HyperLook. Here's the README file (and distribution) of PdB, Arthur van Hoff's object oriented C to PostScript compiler: https://github.com/IanDarwin/OpenLookCDROM/blob/master/NeWS/pdb/pdb2.1.1-README https://github.com/IanDarwin/OpenLookCDROM/blob/master/NeWS/... Also a paper by Arthur van Hoff about "Syntactic Extensions to PdB to Support TNT Classing Mechanisms": https://www.donhopkins.com/home/archive/NeWS/PdB.txt https://www.donhopkins.com/home/archive/NeWS/PdB.txt Some before and after examples, like menu.h menu.pdb menu.PS: HyperNeWS 3.0 prototype source: https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3.0/src/ https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3... menu.h: https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3.0/src/menu.h https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3... menu.pdb: https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3.0/src/menu.pdb https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3... menu.PS: https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3.0/src/menu.PS https://www.donhopkins.com/home/archive/HyperLook/Turing/hn3... GoodNeWS/HyperNeWS/HyperLook: https://medium.com/@donhopkins/hyperlook-nee-hypernews-nee-goodnews-99f411e58ce4 https://medium.com/@donhopkins/hyperlook-nee-hypernews-nee-g...
- deleted 6y ago[deleted]
- ExcavateGrandMa 6y agoHEYYYYYYYYY GUY I FOUND A NICE SENTENCE lET ME REUSE IT IN MY RECIPE :Ð """ In the Unix Haters Handbook (http://research.microsoft.com/~daniel/uhh-download.html http://research.microsoft.com/~daniel/uhh-download.html) page 206 (as per the pdf) has a quote from jwz dated from 12 Dec 1992. Now at this point I should have remembered that profound truism: “Some people, when confronted with a Unix problem, think ‘I know, I’ll use sed.’ Now they have two problems.” It was from the Unix Haters Handbook that I recognised that quote. """ damn clownz are shameless... PERL is like 30 yo... I trust more perl than any new modern shit! :D You just triggered the gun in a russian rolleta, funny no? :Ð
- corpMaverick 6y agoParaphrasing for my latest favorite pet peeve... Some people, when confronted with a problem, think "I will create a branch." Now they have two problems.
- mellosouls 6y agoI must admit, I find the idea of the origin here (invented by coders) unlikely; it seems far too generic and likely to go back considerably further. The suggestion of a WW2 soldiers origin (a la foo bar) in the article is more believable, though really I don't see why it should have not predated that as well.
- optimalsolver 6y agoRelevant XKCD: https://xkcd.com/1171/ https://xkcd.com/1171/
- unishark 6y agoI have a variation where I start with no problems. But someone thinks I have a problem (in reality they have the problem). So I need to create a bunch of complex debug code to test the situation. Of course the debug code has bugs. Now I have a bunch of debugging to do on my debugging code itself. To prove there's no bug.
- sixstringtheory 6y agoSounds like job security, the opposite of a problem!
- Digit-Al 6y agoI get a 404.
- ColinWright 6y agoIt might not help you, but the link is working for me.
- k0stas 6y agoThe site's https site is broken so those of us who have enabled Firefox's preference for https are getting 404s.
- ColinWright 6y agoUseful to know ... thanks.
- renewiltord 6y agoIt is intentionally so. Go to the site root to see.
- k0stas 6y agoSame here in Firefox. The website configuration is broken. The https site returns 404 but the http site has the content. This breaks Firefox's preferences for https, as I keep get redirected from the http to the https site since the https site responds (albeit with a 404).
- laddng 6y agoI always had a hard time remembering the regex syntax and form until I learned about scanners/lexers/tokenizers and finite state machines. Then it really clicked and made a lot of sense.
- DonHopkins 6y agoJames Clark's compact syntax for Relax/NG XML schema validation language is quite tastefully designed, an equivalent but more convenient alternative syntax than XML, for writing tree regular expressions matching XML documents. It's way more beautiful and coherent than the official "XML Schema" standard. https://www.oasis-open.org/committees/relax-ng/compact-20021121.html https://www.oasis-open.org/committees/relax-ng/compact-20021... RELAX NG compact syntax cheat sheet https://gist.github.com/miikka/b137a8705e88b0b6c164 https://gist.github.com/miikka/b137a8705e88b0b6c164 https://en.wikipedia.org/wiki/RELAX_NG#Compact_syntax https://en.wikipedia.org/wiki/RELAX_NG#Compact_syntax >RELAX NG compact syntax is a non-XML format inspired by extended Backus-Naur form and regular expressions, designed so that it can be unambiguously translated to its XML counterpart, and back again, with one-to-one correspondence in structure and meaning, in much the same way that Simple Outline XML (SOX) relates to XML. It shares many features with the syntax of DTDs. Here is the compact form of the above schema: element book { element page { text }+ } >With named patterns, this can be flattened to: start = element book { page+ } page = element page { text } >A compact RELAX NG parser will treat these two as the same pattern. There's a wonderful DDJ interview with James Clark called "A Triumph of Simplicity: James Clark on Markup Languages and XML" where he explains how a standard has failed if everyone just uses the reference implementation, because the point of a standard is to be crisp and simple enough that many different implementations can interoperate perfectly. A Triumph of Simplicity: James Clark on Markup Languages and XML: https://web.archive.org/web/20130721072712/https://www.drdobbs.com/a-triumph-of-simplicity-james-clark-on-m/184404686 https://web.archive.org/web/20130721072712/https://www.drdob... "The standard has to be sufficiently simple that it makes sense to have multiple implementations." -James Clark
- offtop5 6y agoRegex, like SQL is a black art I'll never understand. At best I tolerate it. Usually easier to split the string into an array and manipulate it then.
- coldtea 6y agoWhat's so strange about regex? Or SQL for that matter?
- Zelphyr 6y agoBasic regex is readable, at a glance, for the most part, with a little practice. Anything marginally complex and you have to stop what you’re working on and really read the regex to try to understand what it’s doing. SQL isn’t hard, but trying to remember all the use cases for the various ways to query something always trips me up. “Wait, do I do a LEFT JOIN here? Ok, now I gotta to look up the different kinds of joins so I can be sure I’m writing the most efficient query.” Again, it’s just a matter of practice. I’d take SQL over a regex any day.
- offtop5 6y agoAs for SQL, I think I just don't put the time into learn it. At the higher levels, it's definitely it's own programing language with a radically different herritage from the JS/C# I'm used to.
- wpietri 6y agoThey're definitely different paradigms of thinking than typical coding. I enjoy regexes, but definitely get how other people would find them bizarre. Personally, I've never liked SQL, though. As with regexes, a little does no harm. But building anything substantial with it always turns into what feel like absurd bank shots to me. I don't just have to cast everything into the relational paradigm, I have to try to guess how a couple million lines of DB server code is going to map that back into operations I actually understand. That said, as with most technologies that I don't personally like, people seem to build sufficiently effective systems and profitable businesses on top of them. So I think it's down to personal cognitive differences and matters of taste. Let a thousand flowers bloom, I say.
- jessaustin 6y agoSome people, when confronted with a danger, think "I know, I'll call the police!"
- jll29 6y ago> ... comp.lang.emacs Wasn't the quote from comp.religion.emacs? But seriously, regular expressions are often ill-advised, as solutions based on them are frequently: - over-matching: they match things in cases where they shouldn't, because a situation wasn't anticipated by the developer - under-matching: not catching some input they should because a regular pattern was formulated to narrowly by the developer - matching the wrong thing altogether because they are hard to stay on top of, even when it's one you wrote - matching something, but you don't understand what and how it works, because regexes are "write only". There is even another case: - They work but they are the wrong instrument, because you try to model something that requires context-free generative capacity (e.g. syntax coloring) Interestingly, at Xerox Research Centre Europe (now Naver Labs) in Grenoble a much more elegant (more powerful yet more readable, and symmetric between inputs and outputs) has been developed as an alternative, mostly to write linguistic rules with it. For more info: * http://users.itk.ppke.hu/~sikbo/nytech/gyak/05_morfo/xfst/book.pdf_1.pdf http://users.itk.ppke.hu/~sikbo/nytech/gyak/05_morfo/xfst/bo... * https://press.uchicago.edu/ucp/books/book/distributed/F/bo3613750.html https://press.uchicago.edu/ucp/books/book/distributed/F/bo36... * There is an open-source implementation called FOMA: https://fomafst.github.io/ https://fomafst.github.io/
- renewiltord 6y agoIt's in the article: alt.religion.emacs
- captaincrowbar 6y agoSome people, when confronted with a problem, think “I know, I'll use floating point.” Now they have 1.999998 problems.
- why-el 6y agoI think the only correct quote here is "Now they don't have two problems."
- kevin_thibedeau 6y agoAnd thus, Javascript was born.
- busfahrer 6y agoThe Java variant of this is "I had a problem so I used Java, now I have a ProblemFactory"
- deckard1 6y agoI think JWZ may be one of the few people that can criticize Perl and I'll be like "fair enough." Most people have never used Perl and just parrot the standard line about it being write-only without actually having used it. > It combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. Believe it or not, I used to be a Perl hater and a Lisp (or Scheme) weenie. But having worked with Perl, Common Lisp, Ruby, NodeJS, and Scheme, I really have to say that I'd take Perl over all of those. The worst aspect of C would be pointers and unsafe memory access, which Perl doesn't have. And the worst parts of Common Lisp would be the massive, inconsistent, designed-by-committee language, CLOS, and macros. Oh, and LOOP (I shouldn't need to dig out a reference book to remember how to do looping each time I need to. Seriously.) S-expressions have also worn their welcome on me. I'm just tired of brace matching (yes, even with your silly fancy IDE). Perl is by no means perfect, but I've found it does more things right than wrong. Blaming Perl for regexes being useful is like blaming a hammer for nails being ubiquitous. What? You're going to hand code a lexer each time you need to parse a phone number or a zip code? If there was a better alternative we would be using it.
- samatman 6y agoThere is! I do! It's Parsing Expression Grammars! There's a reason Rakudo adopted them in its quest to out-Perl Perl (5). Regex is fine as an adequately-powerful shorthand for command-line munging and text editors, where the terseness is useful. It turns on you as soon as you want to use it in a programming language... which is where Perl comes in.
- drran 6y agoIMHO, grammars in Raku are much better than regexps in many situations, except oneliners. https://docs.raku.org/language/grammars https://docs.raku.org/language/grammars
- adrianmonk 6y ago> The worst aspect of C would be pointers and unsafe memory access, which Perl doesn't have. In a practical sense, it doesn't. But it's there if you specifically go digging for it: $ perl -le 'print unpack("p", pack("p", "Hello, world."));' Hello, world. $ perl -le 'print unpack("p", reverse(pack("p", "Hello, world.")));' Segmentation fault (core dumped) $
- BlueTemplar 6y agoLol, "alt.religion.emacs" ?
- DonHopkins 6y agoI know somebody who named their dog Emacs.
- swyx 6y agoare they wrong?
- ColinWright 6y agoI'm old, and I'm finding language drift to be something that I regularly see, and frequently to be baffling. This is an example. To me, "lol" means "laugh out loud". So I ask, and it's a genuine question, did "alt.religion.emacs" really, honestly, make you "laugh out loud"? It may have done, but I'm interested to know. The follow-up is this. If it did make you "laugh out loud", what is it that you found funny? If you didn't "laugh out loud", what do you actually mean by "lol"? I'm interested in language, its uses, and how it's changing, and this is one case where I'm definitely in doubt as to the intended meaning of the comment. Thanks.
- skykooler 6y agoMeaning has drifted over time, and in present usage "lol" usually means something more like "heh" - an expression of mild amusement.
- raldi 6y ago"lol" has morphed into an onomatopoeia, sometimes expressed out loud as an interjection in the same way that "heh" or "ha" might, but with a touch of "I found that droll".
- gerikson 6y agoUsenet, man. You kinda had to be there.
- renewiltord 6y agojwz is oddly everywhere. Netscape Navigator and Mozilla and Emacs obviously, but also owns this nightclub in SF I used to frequent, and he hates HN enough that going to his site with a `Referer` from here will give you a testicle in an egg cup. Fascinating.
- yborg 6y agoWhat is remarkable is that he had a ~12 year career in professional SW development and hasn't really done much in the field apart from Xscreensaver updates since and is still remembered 20+ years later. One of my favorite quotes from JWZ: "“In 1999 I took my leave of that whole sick, navel-gazing mess we called the software industry. Now I'm in a more honest line of work: now I sell beer.”
- bo1024 6y agoI've greatly appreciated his writeup on how to properly thread email conversations from the MIME files. By far the best resource on the subject I was able to find.
- shagie 6y agoThe Codeless Code - Where Angels Fear to Thread - http://thecodelesscode.com/case/121 http://thecodelesscode.com/case/121 > The nun Satou approached Java master Banzen and said: “There is a processing bottleneck which I believe I can eliminate by means of multiple worker threads. Yet I have heard this proverb: If you are confronted with a problem and say, ‘I shall use threads’, you now have two problems.” ... and it goes from there to explore it a bit.
- jdmoreira 6y agoI love that quote and throw it around pretty often to great grievance of my colleagues. I never really got on the regex train, I get the use-case but I think they are abused and most people should be writing some kind of parser instead. We even live in the age of parser combinators so why wouldn't use that? I find that the majority of the people attracted to regexes don't understand parsing. But by all means use them for a quick hack or script.
- jjice 6y agoJeffrey Friedl's regular expression book (mentioned at the top of the article) is fantastic and I highly recommend it. If you want to not only learn regular expressions, but have them be clear upon first glance and now how to optimize them based on your regular expression engine's implementation, then his book is gold. The first half is about using them, and the second half is focused on optimizing. You can skip the second half and still get a lot out of it, but it really is some fantastic stuff.
- rkeniger 6y agoAgreed. I think his book is one of the best technical books I've ever read, it's clear, easy to read and thorough.
- ballenf 6y agoFinite State Morphology was mentioned in the comments and was new to me. It really does look much more useful than regular expressions at the expense of some verbosity. The way that FSM is inherently a forward/backward process seems super elegant and it's more readable (at first read) than regex's. Anyone have insight why they aren't more common? https://web.stanford.edu/~laurik/fsmbook/home.html https://web.stanford.edu/~laurik/fsmbook/home.html
- bwooster 6y agoIt is impossible to parse HTML with a regular expression even in Perl
- hedora 6y agoIt depends on what you’re trying to do with the html. Web scrapers aren’t too bad with perl regexps.