Live data from Hacker News

Learn Regex The Hard Way

regex.learncodethehardway.org

41–50 of 64 posts

Re: Learn Regex The Hard Way

#41
post #37
post #36

Earlier quoted context omitted.

I agree with the GP -- http://codepad.org/YmsaEtJS

Great, another example of regex engines not doing anything you tell them. I'll look at changing it but () isn't going to work there it has to be taught later.

the solution seems pretty easy. simply leave out the beginning/end-of-line assertions. [0-9]+|[A-Z]+ would suffice for that example. i agree that introducing capture groups IS too early, but you can add the parentheses without mentioning capture groups, even if they do capture. grouping still has great value as a precedence indicator which is taught in gradeschool arithmetic.

it's rather unfortunate that the syntax to capture is "(" while the less complex no-capture is "(?:", i'm not sure who thought that through, but here we are.

Re: Learn Regex The Hard Way

#42
post #38

Thats pretty awesome. Regex's the tool (vs. the concept of "regular expressions" that comes up in interpreters/compilers) is a supremely useful utility when used sparingly, and surprisingly portable between languages. Regex's are in a (not-)sweet spot of practical languages that aren't taught in school. For all the hype of ruby, et al. being able to make "DSL's", its surprising how mystical an _actual_ DSL, that is p…

What are some other examples of DSL's that are useful in the same way as regexes?

I am thinking LINQ might qualify. Also, JQuery is strictly not a DSL, but it kinda feels DSLy.

Re: Learn Regex The Hard Way

#43
post #5

What do you guys think of Zed Shaw's teaching style? As I'm not a beginner programmer, I can't really evaluate correctly — to me it seems like a odd approach to programming pedagogy, but perhaps it works. Any non-programmers want to shed light on why his style works?

I started doing Ruby yesterday (have done about 8 exercises) and it's been fun so far. The approach is new and it seems very well thought out.

Re: Learn Regex The Hard Way

#44
post #42
post #38

Thats pretty awesome. Regex's the tool (vs. the concept of "regular expressions" that comes up in interpreters/compilers) is a supremely useful utility when used sparingly, and surprisingly portable between languages. Regex's are in a (not-)sweet spot of practical languages that aren't taught in school. For all the hype of ruby, et al. being able to make "DSL's", its surprising how mystical an _actual_ DSL, that is p…

What are some other examples of DSL's that are useful in the same way as regexes? I am thinking LINQ might qualify. Also, JQuery is strictly not a DSL, but it kinda feels DSLy.

Personally, I classify any sort of sequence comprehension as a DSL, including LINQ and python's list and generator comprehensions. JQuery is basically as close to a LINQ-like DSL as you can get in a language like JavaScript that doesn't have metaprogramming support. Related to sequence comprehensions, there is Common Lisp's controversial LOOP macro, which is basically an iteration comprehension DSL.

I'm somewhat on the fence about whether format control strings qualify as DSL's. They don't as much, but they tend to have very complicated and specialized syntax.

I feel that Monads are a DSL in Haskell, but whenever I see "Monads in Blub!" I don't feel the same way about them. Part of it is probably that Haskell provides not only infix operators, but do-notation for supporting monads. Part of it is also that monads don't do as much in other languages, because their type systems aren't rich enough to fully express them, nor restrictive enough that their capabilities are useful.

Re: Learn Regex The Hard Way

#45
post #30

The regex shell is a neat idea. In many situations I'd like to generate strings accepted by the regex, to check that my regex is tight enough. I know this is hard in general (for lots of reasons, basically all reducing to "there are a lot of strings and no easy way to iterate through them in a satisfying way"). But, has anyone made any progress on this for the "easy" cases?

Your wish has been granted: http://txt2re.com/

I use this all the time. No wonder I don't know to hand write a Regex.

Re: Learn Regex The Hard Way

#46
post #37

Earlier quoted context omitted.

Great, another example of regex engines not doing anything you tell them. I'll look at changing it but () isn't going to work there it has to be taught later.

the solution seems pretty easy. simply leave out the beginning/end-of-line assertions. [0-9]+|[A-Z]+ would suffice for that example. i agree that introducing capture groups IS too early, but you can add the parentheses without mentioning capture groups, even if they do capture. grouping still has great value as a precedence indicator which is taught in gradeschool arithmetic. it's rather unfortunate that the syntax t…

Yes, I hate that (?:) syntax. Who the hell thought that crap up.

But, I will point out that you attributed the error to NL/EOL assertion, when actually it was order of precedence of | being greater than $ and ^. It's a simple nearly 1-2 character mistake, not a "novice" mistake that discredits the entire book.

Re: Learn Regex The Hard Way

#48
post #24
post #10

Earlier quoted context omitted.

as a Python dev I scanned the python book and I thought it dwelled too much on string formatting, focused on teaching syntax and not programming, and the language was a bit terse. but then a friend of mine told me that he and a few other people he knew learnt python from that book, so either later revisions got better or my opinion is shit.

I don't think your opinion is shit, I just think your perspective has changed because you actually can code. The hardest thing for a beginner is just the syntax. If you've never written code before then the symbols in programming are alien as hell. By focusing on seemingly repetitive syntax drills I get them skilled progressively until syntax isn't a problem. Another thing you might be missing is under each exercise…

I agree that syntax is the hardest thing. Based on my experience tutoring, I would add the following (which was surprising to discover at first): the second hardest thing is the order of evaluation. I've seen students write down

    a = do_something1(do_something2())
and be unable to explain that do_something2() actually happens before do_something1(), and to see that the code is loosely equivalent to

    b = do_something2() 
    a = do_something1(b)

Re: Learn Regex The Hard Way

#49
post #44
post #42

Earlier quoted context omitted.

What are some other examples of DSL's that are useful in the same way as regexes? I am thinking LINQ might qualify. Also, JQuery is strictly not a DSL, but it kinda feels DSLy.

Personally, I classify any sort of sequence comprehension as a DSL, including LINQ and python's list and generator comprehensions. JQuery is basically as close to a LINQ-like DSL as you can get in a language like JavaScript that doesn't have metaprogramming support. Related to sequence comprehensions, there is Common Lisp's controversial LOOP macro, which is basically an iteration comprehension DSL. I'm somewhat on t…

A DSL doesn't have to be Turing-complete IIRC so format strings could probably qualify.

Re: Learn Regex The Hard Way

#50
post #5

What do you guys think of Zed Shaw's teaching style? As I'm not a beginner programmer, I can't really evaluate correctly — to me it seems like a odd approach to programming pedagogy, but perhaps it works. Any non-programmers want to shed light on why his style works?

I like Zed Shaw's style. I feel it really helps things stick with the way it is taught. I also feel the 'go find out yourself' methodology sets you up well going forward as you learn to depend on yourself to solve problems instead of the author of the book.
Post reply on HN