Live data from Hacker News

Learn Regex The Hard Way

regex.learncodethehardway.org

21–30 of 64 posts

Re: Learn Regex The Hard Way

#21
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?

My 13 year old son is working through Learn Python the Hard way. He likes it a lot and is building things that interest him. He will spend the whole day fiddling with Python working on a text based choose your own adventure game that one of the chapters had him build. He's approached programming a couple of times before, but LPTHW is the first time he's really stuck with it. In that regard, I think Zed is doing an aw…

That's awesome. It's funny because I didn't even try to write the book for kids, but happy it seems to work well for them.

Re: Learn Regex The Hard Way

#22
post #3

Not to sound like a pretensions CS guy ... but how can you have a book on regular expressions without even mentioning DFA/NFA? Maybe its just me, but (back in my day) I found learning about finite automata made regex just click. Edit: ahh, I see now mentioned in intro that "I'm going to be very practical and straight forward about it. No NFA to DFA conversion. No crazy explanations of push down finite state automata.…

I imagine that sort of implementation issue is only relevant to the typical user if that user comes across a case where the potential inefficiency of NFA->DFA conversion (or NFA simulation) actually does happen. I'm not sure how common it is to encounter this.

I'd be more concerned about making sure there is some discussion of nonregular languages; this appears to be in the works (I'm curious to see what exactly it turns out to be).

Re: Learn Regex The Hard Way

#23
post #20

Earlier quoted context omitted.

I'm about 75% through his Python book, and I have to say I like it. He assumes you're an absolute beginner, and I'm not, so I can't really give it a fair appraisal from the perspective of its target audience. That said, the book definitely makes learning fun. For the first half of the book, you have a really quick learn-reward cycle. The exercises are short and to the point, and he makes you type in the lesson and ru…

> It very much reminds me of when I was in grade 10 and we were doing simple stuff in QBasic. That's pretty much the feel I was going for when I wrote it.

It really shows. A friend of mine asked me about it, and my abbreviated review was just "it makes programming fun again."

I hesitated to use that in my earlier comment because some might use it to paint a bad picture of me, contrasting it with the idea that all good programmers love their craft and are always writing code because it's always fun for them. I just think that as you get into meatier works and start architecting larger applications, there's always going to be some hair pulling and you're going to fight wars with your compiler/interpreter/whatever. LPTHW isn't like that. You just sort of cut through the bullshit and get on with the fun stuff, and it makes the learning process easier.

So thanks. I look forward to reading your other works as they finish.

Re: Learn Regex The Hard Way

#24
post #10
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?

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 is a real piece of programming they're learning. For example, with string formatting I'm actually teaching the concept of named variables. Later on I use the fact they've actually been using named variables to then teach the concept explicitly and then they get it quicker.

Re: Learn Regex The Hard Way

#25
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?

It's just like teaching anything: nothing is really fun until you can do something.

I teach guitar, so let me use that as an example: it's my job as a teacher to get students to love the guitar so they (1) continue with it, and (2) come to the next lesson. the only way I can make sure students get excited is if they can do some thing. So I could bog them down with a bunch of theory and stuff, or explain the mechanics of hand movements in very technical detail.

But those things really don't matter. What does matter is reducing the essence of a few things into a simple exercise that the student can do and that sounds good. If you took a guitar lesson from me, you'd probably leave the first lesson able to strum a few chords in time. Of course, you just learned a ton of stuff: how to use your fingers on the fretboard, how to keep the beat, how to strum, posture, hand positions -- the list goes on.

All you care about, as the student, is that you can do something. You feel successful. You have something to practice. As you progress, you become more interested in the finer details (or you quit) and we go deeper -- explaining music theory, patterns, technique and mechanics, etc.

Zed teaches programming the same way. Give the student something to do where they can see immediate results. The ones that stick with it are going to be naturally curious about how things work and will keep going further.

I used "Learn Python the Hard Way" as my introduction to programming. It was awesome.

Re: Learn Regex The Hard Way

#26
post #6

just decided to randomly click a chapter. in 12.1 wouldn't ^[0-9]+|[A-Z]+$ in fact need to be written as ^([0-9]+|[A-Z]+)$ or non-capturing ^(?:[0-9]+|[A-Z]+)$ i doubt the intent was to alternate NL/EOL assertion. seems like a novice oversight and does not instill confidence in the rest of the material. or am i missing something?

Hmm, well the book is being written so there's potential for some errors, but I believe you are wrong here. You're confusing match with search semantics. Your above works because by default Regetron searches. If you turn on match it doesn't match your proposed test below. Try this:

http://codepad.org/uPpwKPJS

Notice when you turn on !match it doesn't find your test.

Also, keep in mind that this is just introducing the concept of alternating. Captures are covered later.

Re: Learn Regex The Hard Way

#27

Earlier quoted context omitted.

I'm about 75% through his Python book, and I have to say I like it. He assumes you're an absolute beginner, and I'm not, so I can't really give it a fair appraisal from the perspective of its target audience. That said, the book definitely makes learning fun. For the first half of the book, you have a really quick learn-reward cycle. The exercises are short and to the point, and he makes you type in the lesson and ru…

Speaking as someone who isn't a programmer at all and needed (still needs, actually) to learn a language for dealing with a massive amount of data for a school project, I decided to have a stab at Python and have been working my way through his book. Overall I'd say it's pretty great. The good is that, as you mentioned, the early chapters (really the whole first half) are quick, repetitive exercises which I feel gave…

> I sometimes feel a bit more explanation from him on how or why certain things work would be nice, or maybe a few hints for where to start looking for answers in the extra credit would be good, but for the most part I think he's effectively covered enough of the basics needed to land me on the ground running.

There's the Python documentation[1], but coming from working mostly with PHP, I've had a hard time adjusting to them. PHPs documentation seems a lot more straightforward, so I've had to lean on StackOverflow[2] a lot more when I run into roadblocks (again, almost entirely as part of the "long list of things to research" exercise).

[1] http://docs.python.org

[2] http://stackoverflow.com

Re: Learn Regex The Hard Way

#28
post #11

Earlier quoted context omitted.

The point is not to have the best or most efficient regex expression, but rather to do the exercises and to highlight by this process misconceptions you may have about how the regex engine operates. You enter what is given, you run it, see what the console returns, ponder about the implications for a few minutes and then scream "aha!" What do you expect ^[0-9]+|[A-Z]+$ to return when matched against the various lines…

unfortunately this is not an efficiency optimization. the intent appears to be to match EITHER all-alpha OR all-numeric strings. the regex, as given, would match both "& ()ABC" and "5673 %$^#" and "123ABC" but NOT "ABC123" what should be a simple concept is defeated and confusion ensues. the correct formulation should have been ^[0-9]+$|^[A-Z]+$ or (judging from the example input and output samples) [0-9]+|[A-Z]+

Uh, no, the intent is not to match all-alpha or all-numeric strings. It's to search for all alpha or all numeric. As I mentioned above, you're confusing search with match semantics.

Re: Learn Regex The Hard Way

#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?

Post reply on HN