Beta

Slashdot: News for Nerds

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Data Crunching

timothy posted more than 9 years ago | from the constructive-critique dept.

Data Storage 94

Vern Ceder writes "I really expected to love Data Crunching. The Pragmatic Bookshelf has come up with some very good and, well, "pragmatic" texts in the past so I was looking for more of the same. Even better, the subject of the book was the routine data extraction, massaging and formatting that I (and a lot of other coders) spend so much time on. I was really looking forward to adding a couple more pragmatic tools to my coding toolbox. Unfortunately (as you may have guessed), I really can't say I love Data Crunching. It's a good book, but there are several minor points that keep if from being a truly great book." Read on for the rest of Ceder's review.

On the positive side, there is a lot of good stuff in this book. I would even go so far as to recommend it to everyone who writes code to extract or manipulate data, particularly those less experienced. Greg Wilson should be praised for taking the idea of data crunching seriously and for systematically dealing with its patterns and pitfalls. A lot of important work gets done every day with one-off programs and behind the scenes scripts and Wilson is right that the techniques that go into this sort of coding are different, but just as important, as those that go into full-blown application development.

The strength of this book is that it offers useful approaches and patterns for dealing with a variety of common programming situations and types of data, while also pointing out their common traps and pitfalls. Wilson starts with techniques for crunching text data, moves on to the use of regular expressions, XML, binary data, and SQL databases before concluding with a special section on "horseshoe nails," various little techniques which just might save help save the day. Quite often he uses examples in both Python, which he calls an "agile" language and Java, a "sturdy" language. The basic advice offered is sound, if not shocking -- keep things simple, test as you develop, don't duplicate code, use existing scripts and utilities when possible, and so on. The combination of such sound advice with a wealth of practical examples is makes for a very effective handbook, particularly for someone new to data crunching.

So is Data Crunching a good book? Definitely. Should you read it if you regularly do routine data manipulation and extraction? Absolutely. And yet...

And yet there are number of things that just aren't quite right. The text and binary sections are the best, while I would say that the XML and SQL sections are the weakest, partly because those topics are too broad to cover in a single slim chapter. If you already have an idea of how you might want to use XML or how to extract data from a SQL database, you're likely find something handy in those chapters. On the other hand, if you're unfamiliar with them, this book probably doesn't have enough detail to get you writing useful code. I should say it doesn't have enough detail to get you writing useful code knowing what you're doing. And data crunching without knowing what you're doing is a bad idea. Trust me on that one.

I have another problem with the section on SQL. Several of the slicker SQL recipes rely on nested queries (page 147-151). MySQL, clearly a very popular SQL database, has nested queries only in its latest versions, so many, if not the majority, of MySQL installations do not yet have that capability. Yet the text carries on as if nested queries were universal, without so much as parenthetical mention that some things might not work on all SQL implementations. It seems to me that this is exactly the sort of pitfall a book like this should inform the reader of.

There are also several coding examples that bother me. Since I tend to both learn and teach by paying close attention to examples, I get uncomfortable with examples that seem to suggest something other than what they should.

For instance, the very first pieces of sample code (pages 9-10) in the text chapter are Python and Java programs to reverse the order of lines in a text file. I don't have a problem with the exercise itself, I've often assigned it to beginning programmers. However, this book is about quick and reliable solutions to common data handling problems, not leading people through basic programming exercises. Ironically, the very same chapter discusses the advantages of using the Unix command-line and its wealth of little tools. So wouldn't it be reasonable to expect at least a brief note or example showing that the REALLY easy way to solve the problem is with a single line: $ tac filename > filename2? Yet tac is not even in the list of "Useful Commands" on page 24. If reversing lines is just a programming example, it shouldn't be the lead example in a book like this, and if it is important, then you should mention that the problem has already been solved.

In the same vein, Wilson spends a fair amount of time in the text chapter illustrating code to parse command-line parameters, before admitting that libraries for the task abound in most languages. Granted, being able to snag a parameter or two off of the command-line without using a library can sometimes be handy; but implementing a more involved command-line parser is a problem that has already been abundantly solved.

Similarly, one of the examples in the chapter on regular expressions uses a regular expression to check to see if a string contains a valid IP address (pages 65-66). After showing how to use a regular expression to scan a dotted quad of digits, the text then admits that using a regular expression alone would lead to too much complexity, since it's hard to use a regular expression to check to see if a 1 to 3 digit number is less than 255 (or 127, which is what he uses in his code). So the example on page 66 ends up compiling and matching a regular expression like this:

pat = re.compile("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\ .(\\d{1,3})")
. . .
m = pat.match(text)
for g in m.groups():
. . .
when a Python coder would more naturally just use:

quads = text.split('.')
for number in quads:

Sure, it's a good example of how to extract matched items, but the implication is that using a regular expression is the best way to extract extract numbers separated by dots, when in fact the Python has a simpler, easier and more reliable way to deal with it. Again a quick mention of the "easy" way to solve the problem would have been appropriate.

These kinds of issues are what keeps Data Crunching from being a great book. In spite of them, it is still a very good and useful book and Mark Wilson has done a good job with a topic all too often ignored. The general idea is great, and the principles, problems and solutions are well-explained and relevant. If data crunching is something you do, I would certainly recommend that you read this book, but with a somewhat critical eye.


You can purchase Data Crunching: Solve Everyday Problems Using Java, Python, and more. from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

cancel ×

94 comments

Fps are crunchy too (-1, Offtopic)

princemackenzie (849396) | more than 9 years ago | (#12866345)

Like FP brand tater chips!

Re:Fps are crunchy too (0)

Anonymous Coward | more than 9 years ago | (#12867057)

Fuck Slashdot.

Sounds like it's missing something (0)

copeland3300 (889992) | more than 9 years ago | (#12866349)

sounds like even though this book gives a good idea of how to do certian things, there's a lot of little, yet very useful tips and tricks that it leaves out

Re:Sounds like it's missing something (1)

JamesOfTheDesert (188356) | more than 9 years ago | (#12869422)

I read the sample chapter online, and got the impression that the author was spreading himself too thin. While the content was more or less correct, it demonstrated a lack of real understanding, with a few clear mistakes.

1992 Called.... (1, Redundant)

Asshat Canada (804093) | more than 9 years ago | (#12866353)

They want their crappy book back.

Re:1992 Called.... (0, Troll)

Rosco P. Coltrane (209368) | more than 9 years ago | (#12866644)

Your two last posts, combined with your high Slashdot ID and the general trollishness of your comments lead me to think you were born in 1992. Did I guess right?

1992 called, they want their spermatozoid-turned-spotty-teenager back...

Re:1992 Called.... (1)

heauxmeaux (869966) | more than 9 years ago | (#12866809)

Verily thou hast painted a hauntingly accurate portrait of my oily companion.

I kneel before your cola-soaked yankee corpulence.

Richard Cranium.

Re:1992 Called.... (0, Flamebait)

hobbesx (259250) | more than 9 years ago | (#12867221)

1983 actually... There's the 60% exchange rate on Canadian Asshats.

Save Some Money! (-1)

Anonymous Coward | more than 9 years ago | (#12866355)

Save more than $7 here: Data Crunching [amazon.com]

Amazon referral whore, mod down (2, Interesting)

Anonymous Coward | more than 9 years ago | (#12866495)

Link contains redirect to kaleidojewel's referral account. Don't encourage his spamming by rewarding him with payoffs.

Re:Amazon referral whore, mod down (1)

JUSTONEMORELATTE (584508) | more than 9 years ago | (#12867212)

Link contains redirect to kaleidojewel's referral account. Don't encourage his spamming by rewarding him with payoffs.

True, but it is indeed more than $7 cheaper than the bn.com link in the review.
I'm not 'kaleidojewel' nor do I know him/her, I'm just sayin...

Reviewer catches himself. (4, Insightful)

juuri (7678) | more than 9 years ago | (#12866360)

Don't berate the author for his examples using nested SQL when a paragraph later you call him out for not using "tac" because you assumed it is universal.

Like nested queries, tac, isn't standard across all unix platforms.

Re:Reviewer catches himself. (3, Interesting)

FriedTurkey (761642) | more than 9 years ago | (#12866532)

Isn't nested SQL part of the ANSI standard? MySQL is a great database for certain purposes but every other modern database has nested SQL. I don't think an author should not use a technique native to most databases because one database's older versions don't have it.

Re:Reviewer catches himself. (0)

Anonymous Coward | more than 9 years ago | (#12867859)

No one complies with the ANSI SQL standard. No one. The ANSI SQL standard is a fantasy.

Re:Reviewer catches himself. (0)

Anonymous Coward | more than 9 years ago | (#12869353)

True... but some are (much) farther away than others.... like MySQL. Learning SQL on MySQL just sets you up for looking like an idiot later when you have to use, well, pretty much anything else.

Re:Reviewer catches himself. (0)

Anonymous Coward | more than 9 years ago | (#12866534)

Can we review reviewers? I have no interest in this book, but this review was downright horrible.

Re:Reviewer catches himself. (1)

hubie (108345) | more than 9 years ago | (#12883363)

I disagree. I thought it was a very good book review because he described the scope and contents of the book, then talked about what in particular was good and bad supported with specific examples. Usually what gets passed off as a book review here (and elsewhere) is more a synopsis of the type you'd find from an "Amazon top 100" reviewer: a brief description similar to what is on the dust jacket, then a sentence or two talking about what is in each chapter, and if you're lucky maybe a comment or two about how it was written too dry or folksy.

One might take issue with the reviewer's comments or opinions (e.g., whether the statements about MySQL are accurate), but he at least has comments and opinions to discuss.

Re:Reviewer catches himself. (0)

Anonymous Coward | more than 9 years ago | (#12866713)

rev(1) is a more universally available command

Re:Reviewer catches himself. (3, Informative)

helixblue (231601) | more than 9 years ago | (#12866787)

FYI: It's worth mentioning that rev is not very close to being universal either, existing only on Linux and BSD boxes as best as I can tell. tail -r is more universal in that it works under both SYSV and BSD variants, but oddly enough: not Linux.

The GNU tail folks were pretty stubborn about keeping their file reversal in the tac command, wreaking havoc with cross platform scripts everywhere. :)

Re:Reviewer catches himself. (1)

kayumi (763841) | more than 9 years ago | (#12867891)

rev and tail -r do different things.
rev reverses each line.
tail -r reverses the order in which lines are read

Re:Reviewer catches himself. (1)

Profound (50789) | more than 9 years ago | (#12868662)

perl -e "print reverse " filename

Re:Reviewer catches himself. (2, Informative)

Profound (50789) | more than 9 years ago | (#12868687)

perl -e "print reverse <>" filename


(next time I'll use preview)

Astroturf @ /. (-1, Troll)

SunPin (596554) | more than 9 years ago | (#12866383)

The submitter expected to love the book but the book has problems. HOWEVER, since the publisher paid good money for this review, the drawbacks are certainly not enough to prevent this from being a great book. GO BUY IT..

Re:Astroturf @ /. (1)

MisanthropicProgram (763655) | more than 9 years ago | (#12866456)

...since the publisher paid good money for this review...

Dude, I like to start controversy as much as the next Tr...errr...guy, but you need to give some evidence.

quads = text.split('.') (5, Insightful)

Evro (18923) | more than 9 years ago | (#12866398)

quads = text.split('.')
This assumes valid data and not something mangled like "1.2.3" or "U.S.A.". Using the numeric regex match that the book's author suggested would be more reliable in matching IP addresses only.

Re: quads = text.split('.') (4, Informative)

abigor (540274) | more than 9 years ago | (#12866513)

quads = text.split('.')
if len(quads) != 4:
raise NotAnIPAddress
for member in quads:
try:
quad = int(member)
if quad < 0 or quad > 255:
raise NotValidQuad
except:
raise NotValidQuad
.
.
.
etc.

Re: quads = text.split('.') (2, Informative)

Anonymous Coward | more than 9 years ago | (#12866671)

Ummm... is receiving a number less than 0 or greater than 255 an exception? No, it's abnormal input sure, but that is a nasty and poor use of exceptions.

You get an F on programming style :(

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12866711)

What are you suggesting then? It's the programmer's responsibility to catch exceptions as they are thrown back to him. Would you like to open a message box instead? And what if it's a command line program? Exceptions can be ignored...

Re: quads = text.split('.') (3, Informative)

abigor (540274) | more than 9 years ago | (#12866728)

Jesus, it's just a demo to show that calling split isn't particularly unsafe. How you handle the errors is up to you. Consider the raise statements to be pseudocode.

Ah, but your last line explains everything: you teach programming. You don't do it for a living. Makes sense now.

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12867007)

Ah, but your last line explains everything: you teach programming. You don't do it for a living. Makes sense now.

You are a complete dipshit. People who program for a living know that handling a thrown exception can cause a major performance hit. Don't use exceptions to control program flow.

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12867366)

And you don't write code for a living. So go fuck yourself.

If you did, you'd realise two things: one, that error severity depends on the situation (as the grandparent pointed out, the raise is just pseudocode, but it is a valid thing to do). Two, maintainability is key. Python provides exceptions as a core language feature; use them to handle exceptional conditions (errors).

Now fuck off, junior.

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12866874)

It's considered good Python style to use exceptions for flow control.. I shit you not.

Or at least, it was when I used it many years ago. The great thing about Python is, "there's more than one way to do it". ;-)

Re: quads = text.split('.') (2, Informative)

PatrickThomson (712694) | more than 9 years ago | (#12867467)

THe whole point of python is to raise and catch exeptions instead of fucking about trying to make it all nice. So the parseing program might be called by

ip = getuserinput()
try: DoShitFromGrandparent()
except NotAnIPAddress:
print "Not an IP address, dumbass"
except NotValidQuad:
blah blah etc.

Re: quads = text.split('.') (2, Informative)

feronti (413011) | more than 9 years ago | (#12867903)

Actually, that would depend on where this code lives... if it's in the user interface, sure, using an exception is probably not the right way to do it, since you know right there how to handle it. But what if it's deep in the bowels of a library? A library should validate that its callers are following the contract, but has no way of knowing how to handle the error when the value is out of range, so it should fail early and throw an exception so the higher layers can do something about it.

Besides, as another poster mentioned, using exceptions for flow control is an actual pattern in Python. The Python philosophy is 'it's easier to ask for forgiveness than to ask for permission.' Though, the truly python way would be to build the address and just pass it on, and let someone who knows better validate it.

Re: quads = text.split('.') (1)

Wavicle (181176) | more than 9 years ago | (#12870208)

Ummm... is receiving a number less than 0 or greater than 255 an exception?

In this case, it probably is.

No, it's abnormal input sure,

abnormal input is an exceptional condition by definition. Normal input is expected.

but that is a nasty and poor use of exceptions.

No it isn't.

You get an F on programming style

Your teaching credential needs revoking. As anybody worth their salt as a programmer would know that whether or not to handle something as an exception depends on the severity of the problem, the frequency of the problem, and the time critical nature of the code in question. Validating an IP address is something usually done infrequently, often in response to a user action, so any performance hit from exception handling is insignificant compared to the additional processing that will occur popping up some sort of dialog to let the user know something is wrong.

Re: quads = text.split('.') (1)

Evro (18923) | more than 9 years ago | (#12866927)

Well, sure, that'll work, but that's not what the reviewer included as an alternate example. The \d{1,3} syntax would do a lot of sanity checking right off the bat. But if there's one thing I learned from Perl, it's TMTOWTDI. If you're guaranteed that the data being passed to you is valid and clean, using a simple split on the '.' character would suffice. I usually prefer to err on the side of "never trust the data," especially when designing modular stuff, as you never really know who's going to be passing you the data. Better to check twice than not at all, to me anyway.

This may or may not work... typing code in an HTML textarea is annoying.
function parseData($stuff) {
....
if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3\.\d{1,3}$/ ',trim($stuff)) {
log_ip_address($stuff);
}
...
}

function log_ip_address($ip) {
$ip = preg_split('/\./',$ip);
foreach ($ip as $q) {
if (is_int($q) && ($q >= 0) && ($q <= 255)) {
continue;
}
else {
return FALSE;
}
}

// It is a numeric IP address... If we were cool we'd check to make sure it
// wasn't in a reserved ip block and other sanity checks.
log($ip);

return TRUE;
}

Re: quads = text.split('.') (3, Informative)

Pete Brubaker (35550) | more than 9 years ago | (#12867018)

"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5 ]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0 -9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[ 0-9][0-9]?)\b"

This will match a valid IP address.

--Pete

Re: quads = text.split('.') (1)

Hercynium (237328) | more than 9 years ago | (#12871268)

Maybe he's trying to be helpful... but as a perl programmer, I say, mod parent funny!!!

My philosophy (yes, everybody seems to have one these days) is this:

1. Define the rules for valid data.
2. Classify types of invalid data.
3. Break the rules down into a series of discrete steps.
4. Write the validation code, using the simplest semantics possible.
5. If data validation fails, try to match the problem to one of the invalid data classifications and throw an exception.

Yes, it sounds complex, but for the type of work I do, we need to:
1. Check our data for correctness.
2. Reject invalid data.
3. Identify what went wrong
4. Be able to quickly understand the rules by reading the code, for future maintenance.

okay, back to work. gotta mung a list of ATM PVCs

Re: quads = text.split('.') (1)

thor (3901) | more than 9 years ago | (#12868065)

or using Perl:

if((@quads)=m:(\d+)\.(\d+)\.(\d+)\.(\d+):)
{
# do stuff
}
else
{
warn ( "bad address" ) ;
}

QED

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12882354)

I think QEF is appropriate here instead of QED.

Re: quads = text.split('.') (0)

Anonymous Coward | more than 9 years ago | (#12868883)

Pfft. Regexes work fine... if you know how to use them.

To match a number 0-255, the easiest pattern to see it with is this:

(\d|\d\d|1\d\d|2[0-4]\d|25[0-5])

[Which matches any one digit (0-9), or any two digits (10-99), or a 1 followed by any two digits (100-199), or a two followed by 0-4 and any digit (200-249), or 25 followed by a 0-5 (250-255).]

So use that pattern 4 times, with 3 literal periods between them. Want to shorten that? Well, the 0-199 bits can always be made into:

(1?\d?\d)

Which is an optional '1' followed by an optional digit, followed by a required digit (we don't want any part of our pattern to have a possibility of matching nothing at all). Merging that in will give us merely:

(1?\d?\d|2[0-4]\d|25[0-5])

And the whole IP address, over all, would then be:

$input =~ m/(1?\d?\d|2[0-4]\d|25[0-5])\.(1?\d?\d|2[0-4]\d|25 [0-5])\.(1?\d?\d|2[0-4]\d|25[0-5])\.(1?\d?\d|2[0-4 ]\d|25[0-5])/;

Which is a tad ugly, but works just fine. Yes, I'm using Perl style regexes here, but Java uses the Perl syntax within the regexes (mostly--you still have to escape all the backslashes with a second backslash).

Or, yeah, split on '.' and just make sure each number is greater than 0 (lest some idiot try to give you a negative IP address somehow in user input) and less than 255. If you want to get really clever, you might exclude 127.*.*.* and perhaps other RFC defined ranges from certain applications for some purposes. You can also do that with a regex, but it's a tad more contorted. I'd probably use the version that was a bit more split up and split it into 100-119, 120-126 & 128-9, 130-199 with something like:

(\d|\d\d|1[01]\d|12[0-68-9]|1[3-9]\d|2[0-4]\d|25 [0 -5])

Using that for the first digit, then the normal pattern on the remaining 3 (because all we care there is that the first digit isn't a 127--if it's not, and it matches the rest, we're fine). That gives us this pattern:

(\d|\d\d|1[01]\d|12[0-68-9]|1[3-9]\d|2[0-4]\d|25 [0 -5])\.(1?\d?\d|2[0-4]\d|25[0-5])\.(1?\d?\d|2[0-4]\ d|25[0-5])\.(1?\d?\d|2[0-4]\d|25[0-5])

I think that the O'Reilly regex book has a more detailed example of doing this, and a few ideas on other clever ways to split the pattern up.

Me? I focus on pattern readability and sometimes efficiency, not pattern length. The irony is that long, specific patterns can be more efficient (if hideously ugly--see the RFC compliant 'email address' matcher in the back of the regex book I mentioned) provided they don't make a huge morass of crap for the automaton to have to backtrack through.

nested queries are a problem? (4, Insightful)

stoolpigeon (454276) | more than 9 years ago | (#12866401)

If a book uses nested queries and some rdbms doesn't -- the problem lies with the rdbms. I've never used mysql and I've avoided the flames about it not being a real database.... but come on. That is weak.

Re:nested queries are a problem? (2, Insightful)

jthayden (811997) | more than 9 years ago | (#12866447)

Granted the ANSI SQL standard isn't followed as closely as perhaps other standards are, but if Nested Queries are in the standard, then I would have to say the RDBMS is at fault and not the book.

Re:nested queries are a problem? (0)

Anonymous Coward | more than 9 years ago | (#12867239)

the reviewer is just a gnu-shit-centric knowing-linux-and-nothing-else mysql-is-a-real-db yadda yadda hippie.

Re:nested queries are a problem? (0)

Anonymous Coward | more than 9 years ago | (#12867654)

lol

subqueries not a problem. (0)

Anonymous Coward | more than 9 years ago | (#12866641)

>I've never used mysql and I've avoided the flames about it not being a real database.... but come on. That is weak.

13.1.8. Subquery Syntax [mysql.com]

HTH. HAND.

Re:subqueries not a problem. (1)

stoolpigeon (454276) | more than 9 years ago | (#12866729)

which makes the criticism even weaker. If it is only old versions of the db that don't support it, the point is what?

Re:nested queries are a problem? (2, Insightful)

poot_rootbeer (188613) | more than 9 years ago | (#12866959)

I may be wrong, but I believe that an RDBMS must support nested subqueries to be conformant to the ANSI SQL92 Entry-Level specification (maybe even SQL89?).

Not to fan the flames of another advocacy flamewar, but if MySQL hasn't caught up to a 13-year-old standard yet, it shouldn't be treated as a fully-functional SQL RDBMS.

If you're running MySQL you should be aware of its limitations yourself; it's not the book's job to bring them to your attention for you.

MySQL and data crunching (2, Insightful)

angio (33504) | more than 9 years ago | (#12869111)

MySQL's lack of support for some of the ANSI SQL features is annoying. But, that said, I do a lot of data crunching on a terabyte or so of Internet measurement data, and MySQL remains my database of choice. In a data-mining application like mine, I need speed and a compact on-disk representation of the data and the indices before anything. Our inserts are batched a couple of times a day; having them fast is important, but having them run concurrently with queries isn't. I don't need transactions, I can deal with table-level locking, and I'm willing to give up a couple of things like nested selects to get that speed.

Given that MySQL is the best fit for some types of data crunching applications, the earlier comment about assuming nested queries has merit.

My requirements arise in a research setting, so perhaps they're less common. Companies like wal-mart can afford big iron on which to do their data mining. Smaller data crunching tasks don't make the same kind of performance demands on their RDBMS. Of course, one thing to consider is that the standard RDBMS model isn't all that well suited to huge-scale data-mining in general, so there may be no silver bullet here for any of us to get religious about yet.

I really expected to love Data Crunching. (3, Funny)

dfn5 (524972) | more than 9 years ago | (#12866418)

I also expected to love getting my teeth pulled. Trust me. It wasn't that great.

Re:I really expected to love Data Crunching. (0)

Anonymous Coward | more than 9 years ago | (#12866645)

Well trust me your lucky, I read that as Data Crusher and thoughts raced in my head at the implications for all StarTrek fans.

Re:I really expected to love Data Crunching. (1)

GecKo213 (890491) | more than 9 years ago | (#12866718)

I really expected to love Data Crunching. Mmmmmm... Data Crunching. *Drool* Tastes like Chicken.

Matching a dotted quad (1, Informative)

Anonymous Coward | more than 9 years ago | (#12866428)

Shouldn't be too hard if we can use ereg() or similar. How about checking for 0-255 like so: "([1-9][0-9]{0,1}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]| 0)", then it's just a matter of checking for those between dots?

Correction. (0)

Anonymous Coward | more than 9 years ago | (#12866531)

(okay, so it's 1-255, but you get the idea, and slashcode broke the string so I'll blame any further problems on that, just like I would have posted this 5 seconds following the parent if it weren't for the b0rken time limit... you'd think it would be possible to adapt this so that users who are good citizens get to wait a shorter period, or not at all? Maybe that's patented :-\)

"It's been 7 minutes since you last successfully posted a comment"

Oh, I'm not giving up. I can wait a week if that's what it takes.

Just parse it already (1)

Urusai (865560) | more than 9 years ago | (#12870329)

Might as well use yacc/bison to generate a LALR parser while you're being stupid about it.

Re:Just parse it already (1)

sinserve (455889) | more than 9 years ago | (#12889634)

You mean Lex/Flex. Yacc is a parser generator, Lex is a scanner generator. Two different things.

Regex method is better (2, Insightful)

Anonymous Coward | more than 9 years ago | (#12866478)

Your oversimplification of his solution for validating ip addresses is a fine example of a poor review by someone who thinks he knows more than the author.

Try passing in a string such as "I.like puppies!!!". A regex like the one the author provided will easily reject this, so there's no need to worry about checking for numericness, or any other strange characters at all. The regex in fact filters out EVERYthing so that all that has to be done is to check the actual numeric values for the right value range. I would not like to see the remainder of the alternate example (I'm sure it wouldn't be simple)

I'm all for KISS but there is definitely is such a thing as too simple.

Re:Regex method is better (1)

computational super (740265) | more than 9 years ago | (#12869324)

Try passing in a string such as "I.like puppies!!!". A regex like the one the author provided will easily reject this

So... you're saying that the author doesn't like puppies? Wow. What a scrooge.

MySQL (0, Troll)

imgumbydammit (879859) | more than 9 years ago | (#12866488)

MySQL, clearly a very popular SQL database, has nested queries only in its latest versions, so many, if not the majority, of MySQL installations do not yet have that capability. Yet the text carries on as if nested queries were universal, without so much as parenthetical mention that some things might not work on all SQL implementations.

The fact that MySQL sucks is not a limitation of the book, as far as I'm concerned. Stumbling across the bits of SQL that some particular version of MySQL does not support (e.g. UNIONs, inline views, etc etc) is just one of the great treats in life.

Reviewing the book or showing off geekiness? (4, Insightful)

zanderredux (564003) | more than 9 years ago | (#12866496)

Similarly, one of the examples in the chapter on regular expressions uses a regular expression to check to see if a string contains a valid IP address (pages 65-66). After showing how to use a regular expression to scan a dotted quad of digits, the text then admits that using a regular expression alone would lead to too much complexity, since it's hard to use a regular expression to check to see if a 1 to 3 digit number is less than 255 (or 127, which is what he uses in his code). So the example on page 66 ends up compiling and matching a regular expression like this:

pat = re.compile("(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\ .(\\d{1,3})")

Actually, that example is safer than just invoking text.split, as that long regex can shield you from injection attacks and help you enforce numeric IPs in one single command.

In the end, it is a matter of style, but just invoking text.split and trusting user input is... naive?!

Re:Reviewing the book or showing off geekiness? (1)

owlstead (636356) | more than 9 years ago | (#12867741)

I most agree with you. You should use regex for what it is for: checking if the structure of the input is correct. Leave the checking of the actual values to the program. His comments just split at '.' characters. So this means that e.g. +23.-56. 255.1e34 might evaluate to a "correct" IP address.

The book shows the exact way I would do it; check for the maximum amount of structure in the IP adress, allowing only digits and dots, and then proceed to make sure 344.344.344.344 is not accepted. There is nothing wrong with that. Obviously, the book should explain why to choose the most restrictive regex as well as when to use regex, and when not.

Learning concepts...bah! (3, Funny)

Anonymous Coward | more than 9 years ago | (#12866526)

Wilson spends a fair amount of time in the text chapter illustrating code to parse command-line parameters, before admitting that libraries for the task abound in most languages.

You know I had that same problem with my Operating Systems class. That text by Tannenbaum goes through countless examples of what makes a good system, and then at the end he FINALLY admits that there is something called Unix that I can just go and install. What a waste learning all of those concepts!

Re:Learning concepts...bah! (0)

Rosco P. Coltrane (209368) | more than 9 years ago | (#12866568)

Come on, silly...

There are perfectly good calculators for a dollar at the thrift store, yet you learn how to add, subtract, divide and multiply by hand at school. Why is that? Because it gives you a better understanding of what an addition, subtraction, division or multiplication are and involve mathematically.

Same for this book. As a matter of fact, I love technical books that explain the workings of whatever subject they cover, and not just "you can get library X at http://xyz/ [xyz] and use it, don't worry about how it works".

Re:Learning concepts...bah! (0)

Anonymous Coward | more than 9 years ago | (#12866674)

Come on, silly...

I did that last night, all it got me was a slap in the face.

Re:Learning concepts...bah! (4, Informative)

despik (691728) | more than 9 years ago | (#12866986)

Boy, did someone just miss the joke...

Note really fair (1)

amorico (40859) | more than 9 years ago | (#12866548)

It's not fair to criticize the book because you use a tarted up text file instead of something like postgres or oracle or db2 or any number of other rdbms's that managed to support subqueries and foreign keys within 30 years of their invnetion.

Perl and a new Mac (0)

Anonymous Coward | more than 9 years ago | (#12866564)

That's all you need for the perfect Data crunching machine.

Especially when the new Mactels come out !!!!

Good Advice (1)

pinkythecat (879883) | more than 9 years ago | (#12866667)

"read this book, but with a somewhat critical eye." Blindingly obvious but good advice.

Re:Good Advice (3, Funny)

Rosco P. Coltrane (209368) | more than 9 years ago | (#12866685)

"read this book, but with a somewhat critical eye." Blindingly obvious but good advice.

Indeed, having a critical eye can obviously make you blind.

Data "massaging"? (1)

Kirby-meister (574952) | more than 9 years ago | (#12866678)

Sounds like you're having a little too much fun with your database...

Re:Data "massaging"? (3, Funny)

de Bois-Guilbert (807304) | more than 9 years ago | (#12866750)

"SQL like a pig"?

Re:Data "massaging"? (1)

uberslack (5984) | more than 9 years ago | (#12869168)

that's the funniest fucking thing i've read on slashdot in a long time... kudos...

Re:Data "massaging"? (0)

Anonymous Coward | more than 9 years ago | (#12872441)

And I thought such subtlety was lost on /.
At least one person got it. :)

price... (0)

Anonymous Coward | more than 9 years ago | (#12866735)

the pragprog books only have IMHO one problem:
the price/page ratio is not right

Not mentioning tac is not a dealbreaker (3, Insightful)

illumin8 (148082) | more than 9 years ago | (#12866977)

I don't fault the author for not mentioning tac. It is part of the GNU textutils package, and although it might be standard on every Linux distro, it's most likely not in ANY enterprise Unix. I just checked my Sun boxes and it's not installed there, except for the ones that I've installed GNU textutils on.

I really wish a lot of Open Source developers would stop assuming that all of us have every GNU utility ever invented on our system. I can't tell you how difficult it is to get the average GNU autoconf program to compile correctly on Solaris or any flavor of enterprise Unix, simply because most authors assume they're writing platform-independent code, without realizing that GNU's M4 is different from System V M4. Also, differences between lex, flex, tar, and GNU tar abound. Please, for the love of god, don't assume that the tools you know and love on your Linux box at home are available or even installable on enterprise kit at work. Most company policies prevent the installation of these type of tools.

Re:Not mentioning tac is not a dealbreaker (1)

civilizedINTENSITY (45686) | more than 9 years ago | (#12867829)

Not installable by you, of course. But not installable? You seem to suggest that it is more difficult to install for Solaris. Doesn't Sun have a GNU toolchain site? I always thought that:
It is a vital component in Linux kernel development, BSD development and a standard tool when developing software for embedded systems. Parts of the toolchain are also widely used in the Solaris Operating Environment (which, in the opinion of many, needs the GNU tools for reasonable usability) and Microsoft Windows programming with cygwin.

I know I've intalled cygwin painlessly, and even ran the gnu toolchain under irix.

I have to wonder if your post wasn't just intended to pretend a distinction.

Re:Not mentioning tac is not a dealbreaker (2, Informative)

illumin8 (148082) | more than 9 years ago | (#12868316)

Not installable by you, of course. But not installable?

Haha, yeah, I don't even know how to go to SunFreeware [sunfreeware.com] or Blastwave [blastwave.org] and download a copy of GNU textutils in Solaris package format. You can think that if you want to, but in the enterprise world, every software package I want to install has to be approved by about 3 levels of management. They want to know what it does, why we need it, how much it costs, and who else will know how to maintain it after I leave the company. The chance of providing them a list of all the GNU utilities necessary to compile your single average open-source app and getting approval for that is close to nil. Forget Perl modules and CPAN. These are real-world systems that might handle lots of real-world money, and they don't necessarily trust code that's been written by anyone on them.

Anyway, I'm just (hopefully) educating people on some of the problems that a real-world sysadmin runs into on a daily basis.

Re:Not mentioning tac is not a dealbreaker (0)

Anonymous Coward | more than 9 years ago | (#12870780)

I can't tell you how difficult it is to get the average GNU autoconf program to compile correctly on Solaris or any flavor of enterprise Unix, simply because most authors assume they're writing platform-independent code, without realizing that GNU's M4 is different from System V M4.

M4 has nothing to do with it. The configure script in a distribution of configurable, compilable and installable source code is purely /bin/sh shell script. The configure.ac/.in file is GNU m4, but that's beside the point because it's not needed for compilation or installation of a complete source code distribution where autoconf has already been run and the configure script exists.

You fail it.

MySQL (4, Informative)

DogDude (805747) | more than 9 years ago | (#12867096)

I have another problem with the section on SQL. Several of the slicker SQL recipes rely on nested queries (page 147-151). MySQL, clearly a very popular SQL database, has nested queries only in its latest versions, so many, if not the majority, of MySQL installations do not yet have that capability. Yet the text carries on as if nested queries were universal, without so much as parenthetical mention that some things might not work on all SQL implementations. It seems to me that this is exactly the sort of pitfall a book like this should inform the reader of.

Nested queries are *basic* database functionality. This is just one of many reasons why those of us who are experienced DBAs and database developers do not consider MySQL a database. The fact that there are lots of people trying to use it as such is irrelevant. The author didn't mention that the book is also missing a section of spreadsheets. Why not? Lots of people use spreadsheets as a database!

Re:MySQL (1)

Tiny Elvis (171954) | more than 9 years ago | (#12867117)

Agree. It's only a toy if it doesn't support subqueries. Insert coin.

Re:MySQL (2, Insightful)

DogDude (805747) | more than 9 years ago | (#12867385)

What I can't believe (and I'm replying more to myself than anything else, because I just realized...) is that if MySQL hasn't been supporting something as basic as sub-queries until recently that means that there have been tons and tons of complex applications written without subqueries! Holy mother of christ... How would something as simple as even Slashdot get written without subqueries? There must be thousands upon thousands of apps out there that were written with almost -no- understanding of what a modern RDBMS is designed to do even though they're manipulating data. I can only imagine the middle layer of all of these apps doing many, many, many, many unnecessary database connections and queries. Wow. There are truly a LOT of bad programmers out there.

Re:MySQL (1)

iggymanz (596061) | more than 9 years ago | (#12868210)

heh, was that a very obscure mocking of typical J2EE peristence layer architecture?

Re:MySQL (3, Insightful)

Matje (183300) | more than 9 years ago | (#12869931)

So from the fact that MySQL lacked subquery support you derive that there are a lot of bad programmers? me thinks there is only evidence here that you're a bad logician. Now that is a skill a good programmer must have ;). A couple of remarks:

- if you're building a simple website, chances are you won't need any subqueries. Websites were (are?) the bread and butter of MySQL.

- the fact that the dbms lacks subquery support does not imply that the programmer lacks knowledge about them, nor does it imply that programmers generally use unnecessary db connections or queries!

- The MySQL manual states, correctly in my opinion, that in many situations subqueries can be rewritten to joins. Could it be possible that all those bad programmers out there were aware of this and you weren't?

Re:MySQL (2, Insightful)

quasi_steller (539538) | more than 9 years ago | (#12869311)

DBAs and database developers do not consider MySQL a database.

You have got to be kidding me. Of course MySQL is a database. A database is simply a collection of data organized so that a computer program can access pieces of that data, something a MySQL database certainly does. This would make MySQL as a whole, a DBMS (DataBase Management System), as it is a collection of programs used for managing a database. Now, Is MySQL a RDBMS (Relational DBMS)? Well, that depends on your definition of RDBMS. If you define a RDBMS as a DBMS that stores it's data in the form of related tables, then MySQL is most certainly a RDBMS. However, if your a strict follower of Codd, then you might not consider MySQL a RDBMS, as it doesn't follow all of Codd's rules. However, under this strict definition, no SQL DBMS is a RDBMS, as SQL breaks some of Codd's rules.

Perhaps what you meant to say was: "DBA's don't consider MySQL a true SQL database." (Or at least until very recently, as MySQL has gained a lot of functionality.)

Don't get me wrong, I don't disagree with you completely. While I believe MySQL has is uses, I also believe there are many applications where it just shouldn't be used. I just think that we need to be a little more careful when we choose our wording here, so we don't sound like we're trying to flame, or even worse troll. (By the way, I don't believe you were doing either. I'm sure that when you said database, you were thinking SQL.) MySQL is a database, it just is (was? I'm not sure about the newest version) not an SQL compliant database.

References:

  • http://en.wikipedia.org/wiki/RDBMS
  • http://www.webopedia.com/TERM/R/RDBMS.html

Re:MySQL (0)

Anonymous Coward | more than 9 years ago | (#12869445)

"DBA's don't consider MySQL a true SQL database." Followed by "I just think that we need to be a little more careful when we choose our wording here"

Seriously, dude, step off the soapbox. The developers called it "MySQL", not "MyDBMS". Why shouldn't we expect it to be "a true SQL database"?

Re:MySQL (1)

Billly Gates (198444) | more than 9 years ago | (#12872567)

Mysql is to a real RDBMS as Windows 3.11 is a true multitasking, multiuser, and reliable OS.

Sure Windows 3.11 can theoretically support multiple users and multitask but I would prefer W2k thank you.

Same is true with mysql. Mysql is popular because its free and is very multi-user friendly for ISP's with tons of user accounts so they bundle it with their hosting.

PostgreSQL is arguably alot better and also free. In asia its what most Linux users use by default. The tools for it are finally cominging out and as soon as its more multiuser friendly most ISP's will stay reluctant to support it.

Mysql started out as just a small fast SQL filesystem to a simple embedded database for tiny apps. Its growing but its the fastest for small apps that do not need a RDBMS. This is why its experiencing growing pains. In many ways msql took over this market as mysql is turning into a RDBMS.

But a real RDBMS includes MS-SQL Server, Oracle, and Sybase. Even postgresql is behind with some features but is fine for midrange applications.

In alot of ways MCSE's who grow up on Windows who are ignorant of about unix are similiar to those who use Mysql. You can do a ton of stuff with a real RDBMS and going to mysql after experiencing a real RDBMS is like pulling teeth.

Summary in the first sentence (1)

springbox (853816) | more than 9 years ago | (#12867124)

"I really expected to love Data Crunching"

It's interesting the way that's written, because it tells me that you didn't like the book in the first sentence. If getting people to read the entire review was an issue, which is not the case here, then that would have been moved to the last paragraph.

Munging Alternative (2, Informative)

PotatoMan (130809) | more than 9 years ago | (#12867242)

You might want to compare this book to "Data Munging With Perl" by David Cross.

See the Slashdot Review:
http://books.slashdot.org/article.pl?sid=01/04/26/ 1229238&tid=145&tid=6 [slashdot.org]

Re:Munging Alternative (0)

Anonymous Coward | more than 9 years ago | (#12868187)

I read that as "Data Mugging with Perl" and thought "how appropriate."

And I like PERL..

Re:Munging Alternative (1)

DrHyde (134602) | more than 9 years ago | (#12870353)

DDJ's reviewer also liked it [ercb.com] , making the very good point that Dave Cross's book isn't really about perl.

Re:Munging Alternative (0)

Anonymous Coward | more than 9 years ago | (#12870373)

Looks like the author of this book was quite a fan [ercb.com] of Data Munging with Perl. Wonder where he got the idea for this book from :-)

Re:Munging Alternative (0)

Anonymous Coward | more than 9 years ago | (#12907971)

Just look at the publisher,
Publisher: Pragmatic Programmers, LLC, The

yeah right

Who's the author? (1)

The_Wilschon (782534) | more than 9 years ago | (#12867985)

Near the beginning of the post, in the green box, we have:

author | Greg Wilson

And yet, in the final paragraph we see:

In spite of them, it is still a very good and useful book and Mark Wilson has done a good job with a topic all too often ignored.

What's going on?

More, or even Better Books on the Topic? (1)

wehe (135130) | more than 9 years ago | (#12870039)

Are there any better books about data crunching? I found at least Data Munging with Perl by David Cross. BTW: check out DataConv for a survey of data conversion tools [dataconv.org] , many of them GPLed and often unix-based.
Check for New Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account

Loading...