Tuesday, April 18, 2006

Interview with Steve Oualline of Wicked Cool Perl Scripts


Perlcast is back with another interview. This one is with Steve Oualline, the author of "Wicked Cool Perl Scripts".





Transcription



Introduction



Josh




Welcome to Perlcast. This is your host, Josh McAdams, here with another great interview with a member of the Perl community. This interview is with Steve Oualline, the author of numerous books including the more recent, "Wicked Cool Perl Scripts", published by No Starch Press.



As a bonus, No Starch Press will be giving away a few promotional copies of "Wicked Cool Perl Scripts". To be entered the drawing, simply send an email to perlcast+wicked at gmail.com. That's perlcast, the plus sign, wicked, at gmail.com. Get those entries in by May 1st 2006 to be eligible for the drawing.



Interview



Josh




Welcome to Perlcast. Today I have Steve Oualline. Steve is the author of "Wicked Cool Perl Scripts". And, welcome to Perlcast Steve.



Steve




Thank you very much.



Josh




Well, first of all, I guess we'll start by asking, judging from your history of authorship you're a C and C++ programmer, as well as, a Perl programmer. How did you find Perl?



Steve




Well, I'm tempted to answer "I just looked in /usr/bin/ and there it was". But, what happened is, is that I'd been looking at scripting languages for a while and Perl seemed to rise to the top for dealing with things you don't want to write a formal program for. And, just want to get something written fast that works and is fairly simple. And the most selectable language to do that.



Josh




Well, the book is written assuming that the reader already knows Perl. So how much of a Perl expert should you be to actually use this book?



Steve




I think you should have a working knowledge and be able to do the basics. Know how to write a basic program. Know how to download something from CPAN. Which is actually one of the strengths of Perl is you can let somebody else write most of the work and put something together. We don't try into some of the tricky stuff, but just show you how to do the everyday work that you do. It's more of a working-class book than anything else. So if you've done enough Perl that, you know you can write a subroutine, you can do the basics, you can go from there.



Josh




There is a huge range of scripts that you cover in this book. And that goes from website management to CGI programming, system administration, games, photos, development, and even a little bit of mapping. Is there any audience in particular that you were trying to address or were you just going for everybody with this book?



Steve




I was mostly just trying to show people the wide range of problems that Perl can solve in a way that's rather interesting, because, you know, you've got some things there that, oh it was designed for system administration. Well, we do system administration. But there is so many things that you can put together fairly easily, fairly quickly, such as the time I used it to make maps from my Grand Canyon hike. And, found all that information on the web that could easily be downloaded and displayed. And the real interesting thing now is I've got a two-year old daughter is learning computers and Perl has helped her with the basic keyboard use and now is even taught her now how to find letters on the keyboard. She's working her way up. So, it's just fun.



Josh




I thought that was really impressive. The a, the scripts that you had actually written for your daughter that you had in that book. Whenever you went to originally write the book, did you already know that you were going to cover all of that or did it just kind of come about?



Steve




Well, I had a number of things that I'd been using it for already and, as for my daughter, that sort of came about during that. She was learning about the keyboard the hard way at that time because she would see me typing and insist on typing and was very upset that I wouldn't let her write the book too. So, we had to get her to play in a nice way with the computer and that's how the, that's how the first script came about. And, now she's on her second one. And we're going from there.



Josh




There seems to be quite a few UNIX and Linux specific commands embedded in some of those scripts. Would you consider UNIX to be a necessity for readers of this book?



Steve




I would say it is mostly a necessity. You can take some of things, a lot of the things, and move them to Windows, but I designed it with Linux or UNIX in mind. Mostly because, that's where the real adventure comes in. I found that people that are using Linux and Windows [means to say UNIX] are sort of push, they use the technology to push their work forward. And, most of the people I found that are using Microsoft Windows, you're spending your time programming things around the limitations that Windows has set up for you.



Josh




In one section of the book you write a comic spider. And, has the website that you spidered changed since writing the book. Because, I know Randal Schwartz had an issue with that. Like, just after he had published a print spider, that the website went and changed like a day after the print.



Steve




I don't know because I haven't been using that particular program a lot. I know that they've done some new stuff and some old, those are editorial cartoons and they are constantly changing the artist on that. But the whole thing is designed to show you how you can adjust the spider to pick out exactly what you want. And that was the main thing. And yeah, I expect the people to be able to go down and if somethings not working, to fix it. I mean this is for, the audience I consider are not dummies, they are people that, yes, we don't have everything in there, we don't have slick GUI, this is something that works and what doesn't work, you can tweak it a little bit.



Josh




In looking through some of your code examples, I noticed that your regular expressions had just a very interesting and verbose way of commenting them. Where did you pick that up?



Steve




I have been in the, working in the area of, what do I want to say, literate, not literate programming, but trying to make programs clear for about, oh, twenty-five years now in various forms and various languages. So I'm always picking up techniques for making things better. And one of the things that happens is, I have learned how to use ASCII to draw pictures and do other graphic things. And so this is a natural fallout of that. Is to have to draw lines to annotate things in order to make something clear. And, regular expressions are a particular challenge because it an extremely compact language for the expressions themselves and you've gotta get something in there to explain it. And that just seemed to be the natural fallout of that.




It's interesting because when I first started working in programming in programming about twenty-five years ago, they said the next great thing that was coming was marrying the word processor to the compiler so that you'd embed graphics and fonts and other things and make your programs look pretty and you wouldn't have to be stuck with this monospaced courier type font. And, I'm still waiting for the day that they do that to make our programs clear because we're still stuck with that silly type font. Till then I'm gonna make due the best I can with all sorts of techniques and that's just one of them. I mean, some other things that I wind up doing are underlining words with equal-signs to make a level-one heading in a, in a comment, or using stars to try to make something look semi-bold. And, just get around the limitations of that silly font we're stuck with.



Josh




It is amazing that programmers still are the few people that use plain-text files for everything, so.



Steve




Yeah.



Josh




On that note, and this is just kind of a side comment. Have you seen or read Damian Conway's "Perl Best Practices" yet. Because he mentions something else there that seems cool also, and that's the x-modifier on regular expressions. I think that mixed with your commenting would be a, you could really explain what was going on.



Steve




In a previous book called "Perl for C Programmers", I actually show what happens, what it takes. You take a very messy regular expression and you you comment it my way and then you use the dash-x so that you can comment it the way that Damian has. And, what happens is, is that with my way you get this very very vertical big mess. And with Damian's way, you get this horizontal big mess. And the conclusion I've got is is that, if you're gonna start out with a big mess, even commenting it is still a big mess unfortunately. And, really it has to do with just trying to figure out which better. Either the vertical way that I've done or the horizontal way that can be done with the dash-x. My best is to try to avoid some of those regular expressions if I can help it.



Josh




I also noticed that you use CGI::Thin instead of the CGI module. When and why should programmers use CGI::Thing instead of CGI?



Steve




What I was looking at was a rather simple interface to the CGI stuff. And, in general I, I tend to not like CGI itself because it is so much stuff stuffed in there. Especially when it comes to the generation of the HTML. I sort of consider that overkill because, if you know HTML, then you can write it directly. And, if you don't know HTML, the functions provided by CGI aren't going to help you. So, why not just, instead of hiding the HTML inside of function layers, just write it yourself.




You also don't need so much of an object-oriented interface for something that is not going to have multiple instances. There is no way in the CGI basic infrastructure to support multiple connections for a single CGI program. It sits there and runs, it does it's job and it stops and that's it. And, that's what you have to deal with. So, I always felt like, that CGI itself was overkill and I was just looking for something that was simple to use, didn't, and fairly fast loading, and that seemed to be the CGI::Thin module.



Josh




In your CGI scripts you also always used taint mode. How important is it to actually use that?



Steve




I consider sort of the three things necessary for any Perl program, and that is 'use strict', 'use warnings', and if you, if you're running CGI, 'use taint'. And, the taint is of absolute importance because it prevents the user from injecting bad data and just really causing all sorts of problems with your system. Because, a lot of what CGI programs do is pass parameters off to outside programs. Well, if you wind up crafting those parameters, the answers to a lot of the stuff that you have on the form, in a malicious way, you can cause all sorts of trouble. And, so taint mode prevents you from taking anything from the user and passing it directly to a program without checking it for sanity or sanitizing it. And, so it hopefully prevents a lot of problems, and that's why they put it in there, was to prevent this stuff from coming in.




So, it's a basic security check I consider about as important as locking your front door when you leave the house every morning.



Josh




There was one thing that I never heard before that I thought was really interesting and that was just a side-bar you had about the history of the carriage-return and line-feed. Was that a true story or was that just for entertainment purposes?



Steve




No, that's actually a true story. When I first started working, the first computer I had was connected up with a ASR33 teletype, which was state of the art communications back in 1930. I mean that's when they considered ten characters per second high-speed. And, if you look at the history of that, soon after they first made the telegraph they realized that one of the problems that they had is people had to understand Morse Code and they spent years trying to make things so you didn't need that. And the teletype was one of those that fell out of that and was rather successful. And, the teletype was a mechanical beast. It's a very interesting thing if you ever take a look at it because the keyboard ROM is made out of, entirely out of levers. The shift register that is used to transmit the character looks like a distributor cap on a car. And, it's entirely electromechanical. No transistors in it. And it works if you ever keep it in adjustment, which my boss at the time did. But, he said the teletype is made out of adjustments it's not made out of parts. And I saw what happened once because we had a teletype set up that carriage-return, did a carriage-return line-feed. And, you had to put a null character after the carriage-return or it tried to print a character on the fly going back, actually doing the carriage return you get a blob right in the middle of the page.



Josh




One of the scripts you'd done was a regular expression grapher. And, that was just insane how much work it seemed like that took. How long did it take you to write?



Steve




I don't know how long it took me write because it was written somewhat piecemeal. I would use redebug to get some raw data for the regular expression grapher and then just graph those nodes. And, although it looks very very complex, the guts of it are fairly simple. It's just that each different type of regular expression has to have different subroutine for graphing it and it just sort of grew over time.



The only thing I remember about that was is that drawing arcs is a real pain in the ass and I've got them wrong about eight different ways before I finally got them right. And this actually goes back to the regular expression commenting you were talking about earlier because if you look through that, one of the things you see is for each one of those nodes where I've got like three or four arcs that are pointing to a regular expression, I've actually tried to draw it in ASCII above the subroutine itself so I could understand what I was doing. And, yeah, drawing, drawing arcs in ASCII is a real fun thing but, I did the best I could.



Josh




Impressed me. I was shocked to see that in the book.



And, there at the end of the book there was also, there was a page dedicated to the Electronic Frontier Foundation. Was that your doing or is that the publisher?



Steve




I believe that was my doing because I'm a strong believer in what they stand for. And, especially considering some of the silliness that goes on here right now with the criminalizing of what used to be 'fair use'. And, I think that, you know, it gets to the point now where, on this podcast I can tell you that you can encode letters by writing down the alphabet A through Z and shifting the letters thirteen spaces to the right and writing them down. Now that will create an encoding system. I can't tell you how to decrypt that thing, because if I did tell you how to decrypt that thing, I could be subject to five years in jail and have to pay a half-million dollar fine. Because that encryption, even as stupid as it is, actually does protect some copyrighted works. And, it's against federal law to tell me that. Now, any seven year old can figure it out, but you can tell anybody that because it's criminalized. And it just gets, some of the stuff our government does, it's just insane.



So, every once in a while, somebody has to ask the question of the government, you know, "What do you think your doing and how crazy is it?". And, EFF is doing that. Especially in the area that I'm interested in, which is the technology.



Josh




Thank you for putting that in the book. I think you've already covered the other question about the book's more about getting the job done than theory. That's definitely a fair statement for this, I believe?



Steve




Yeah, I mean, I consider myself not at the bleeding edge and not figuring out all of the little obscure things. I just want to beat down the language and get something done. And, the other books that I've done have the word 'practical' in their name, which is, is pretty much how I'm at. It's just get the job done, get it done as simple as possible and as clear as possible and make it work. I mean I work for a living. I have to deal with this stuff on a day-to-day basis. So, you do the best you can.



Josh




I didn't cover that. I know you've mentioned one so far, and that was "Perl for C Programmers". What other titles have you done?



Steve




"Perl for C Programmers" is the big one for the Perl users. And, in a lot of cases my books are competing with several books of the same level. "Perl for C Programmers", I consider one of my strongest books because it really takes Perl and approaches it a way I haven't seen other books do. Other books seem to be Perl for Perl programmers, which to me is a little bit hard to learn Perl unless you already know it. Where as mine starts out with an entirely different thing.



The others that I've done in the C and C++ area have been "Practical C Programming", "Practical C++ Programming". One of the latest from No Starch is "How Not to Program in C++", which is one hundred and one broken programs and a couple of working ones. And that one is rather fun because I manage to break "Hello World" in a couple of ways. Well, those pretty much are the main ones. I've got a number out there that are not in print any more which I don't even remember. And, I don't know.



Josh




That's all the questions I have about "Wicked Cool Perl Scripts" and is there anything else that you'd like to leave us with?



Steve




That's about it. The scripts are downloadable, and the are downloadable from either the No Starch website or my website, which is www.oualline.com.



Closing



Josh




Thanks once again to Steve for allowing me to interview him and thank you for listening to Perlcast. Don't forget to enter the drawing for a promotional copy of "Wicked Cool Perl Scripts", just send an email to perlcast+wicked at gmail.com by May 1st 2006.



The GarageBand.com artist that is featured in this podcast is A Thousand Cures with the track Motions.