5 ms·
> which matches things like -.2, 0.123, +0.1, etc. (floating point numbers, basically). This likely has bugs, since I haven't tested it ;) The fact you can't c
by hcarvalhoalves 13y ago
> which matches things like -.2, 0.123, +0.1, etc. (floating point numbers, basically). This likely has bugs, since I haven't tested it ;)
The fact you can't come up with a regex and be sure it's correct answers your first two questions.
Regexes are incredibly useful, but the syntax is just a bunch of noise. This library turns it into self-docummenting code, which is incredibly valuable. Novices might prefer showing their regex-fu, but after you've spent a good chunk of your life reading and writing code, you value clear code more.
- fendrak 13y agoUnder the hood, what's being generated is still a regex though. How can you be sure ANY code is correct, aside from testing it?
- misterbwong 13y agoTrue, but your argument can apply to any sort of abstraction (e.g. using C instead of assembly or even assembly over 1's and 0's). He's arguing that the nicer syntax is a valuable abstraction over regex's overly-complicated syntax, not that the syntax will be 100% the same as regex 100% of the time.
- hcarvalhoalves 13y ago> How can you be sure ANY code is correct, aside from testing it? Apparently, we can't. So, you really want to improve your odds of writing correct code at the first attempt by making the language work with you rather than against. Replacing a bunch punctuation with code that reads like prose is one way.
- saidajigumi 13y ago> This library turns it into self-docummenting code, which is incredibly valuable. The problem is that for anyone who knows how regexps work, this library provides an obfuscation layer. I personally prefer the free-spacing regexp support[1] found in a number of popular parsers. It lets you write a complicated regexp in small and/or indented chunks across multiple lines, including comments. This provides as much or more documentation than this "self-documenting" form and allows the full power of the regexp engine (which big regexps often seem to need). I've occasionally had to work out some pretty gnarly regexps, but when written in two-column code/comments form they end up being pretty understandable and maintainable. [1] Example from the Ruby docs. IIRC, Python and a few other parsers have similar support: http://www.ruby-doc.org/core-1.9.3/Regexp.html#label-Free-Spacing+Mode+and+Comments http://www.ruby-doc.org/core-1.9.3/Regexp.html#label-Free-Sp...