Live data from Hacker News

How "junior" developers can become regex wizards

joshuakemp.blogspot.com

21–30 of 46 posts

Re: How "junior" developers can become regex wizards

#21
post #9

ugh. do they really need to be good at regex? we don't all work on the internet you know... regex is basically pointless for most application development. most programmers i consider to be exceptionally talented can not write a regex without reference (although they will do it when necessary by using reference - and very well too). on the other hand the general approach to problem solving advocated here is quite soun…

we don't all work on the internet you know...

And the author didn't say that you must know regex to be a good dev. He said that he was learning it, and that he was putting more effort into it and finding it was paying off.

"I want to be a good developer one day, and I think as a young developer we should put in the extra time to try and really understand something and not just always do what is the quickest."

Re: How "junior" developers can become regex wizards

#25
post #22
post #20

Earlier quoted context omitted.

so how do you e.g. remove trailing whitespace?

Is that a serious question? Almost every major language has some kind of string trim/strip function for that purpose.

good point. missed that. but does your text editor have a trim function, too?

i've thought of a case i used a regex the last time. and it was removing whitespace in some code file.

Re: How "junior" developers can become regex wizards

#26
post #23
post #18

Please don't use regexes.

Ever? For any purpose whatsoever? That seems overly prescriptive.

Sure, for scripts, adhoc analysis, command line hacking and whatnot, go ahead.

Regexes should be seen more like a last resort than a good software engineering choice. They're a code smell. I have seen so many incorrect, slow regexes from people who don't know what they are doing that I have to recommend as a best practice that you don't use them unless you are going to study automata, read Friedl's book, the Dragon book, and study with Tibetan regex monks for years, and mentor everyone who has to maintain your code until you die.

Re: How "junior" developers can become regex wizards

#27
Regular expressions were simple and straightforward tools until Perl. They were originally intended to be equivalent to finite state machines, but, thanks to Perl, you can write regexes that may or may not halt, and no one can can ever prove one way or the other. If you want to take the best parts of regexes and leave the rest, don't bother with all of the Perl extensions and just study the basics.

Re: How "junior" developers can become regex wizards

#28
During University one of the projects we were given was to write a regular expression parser and evaluator. From the moment that project was complete I have never had trouble understanding regular expressions. I thought it was an excellent way to learn them.

Re: How "junior" developers can become regex wizards

#29
post #13
post #2

How to become a regular expression wizard: 1. Write a bunch of regular expressions. 2. Fix them when they break. Anybody can do this, however junior they may be. (And yes, it does grant you a superpower.)

3. Write tests. Don't change your existing regular expressions without tests, or Bad Stuff happens.

I don't usually write regular expressions that are complex enough to need maintenance. If you are writing one that is enough effort that it isn't disposable, then you might want to reconsider whether you're using the right tool.

Re: How "junior" developers can become regex wizards

#30
If you really want to master Regular Expressions in a way you are not likely to forget do what I did in the '80s. Write a regex interpreter and then a compiler. I was doing a contract for an embedded controller and found a great use for compiled regular expressions within it (I remember every nuance of regular expressions but can't for the life of me remember what my use case was.)

Debugging it was the really fun part but my earlier career with IBM had taught me how to test software effectively and some embedded work with PAL's (an early form of programmable logic) taught me how to really use state machines. I was surprised how little time it took to write and debug. I don't think you can really appreciate the elegant logic of the regular expression language without implementing it.

Post reply on HN