Mastering Algorithms with Perl 225
Mastering Algo | |
author | Jon Orwant, Jarkko Hietaniemi, and John Macdonald |
pages | 704 |
publisher | O'Reilly, 08/1999 |
rating | 8/10 |
reviewer | John Regehr |
ISBN | 1-56592-398-7 |
summary | The intended audience is programmers who don't have a background incomputer science, who know at least some Perl. However, experiencedprogrammers who don't know Perl should have no trouble picking up thebasics of the language with this book and a copy of ProgrammingPerl. |
Mastering Algorithms with Perl is designed to provide the necessary background. It's structured like a traditional algorithms textbook: after describing some basic and advanced data structures (linked lists, trees, heaps, etc.), it has chapters about searching, sorting, sets, matrices, graphs, strings, and some related topics. After the introduction and discussion of data structures, the chapters are relatively independent and could be read in any order. The authors provide plenty of cross-references as well as pointers to books that describe individual subjects in more detail.
The intended audience is programmers who don't have a background in computer science, who know at least some Perl. However, experienced programmers who don't know Perl should have no trouble picking up the basics of the language with this book and a copy of Programming Perl. Also, computer scientists can often use a review of algorithms, and the CPAN pointers are very useful. So, I would go so far as to say that this book would enrich any programmer's bookshelf. A stringent test of the merit of a new technical book is to ask if it adds some value, given the best existing books in its area? I think that Mastering Algorithms with Perl definitely does. It is a well-written introduction to algorithms that is more accessible, practical, and entertaining than standard algorithm books. It leverages off of the strengths of a powerful language and a large base of reusable code.
The rest of this review will evaluate the strengths and weaknesses of Mastering Algorithms with Perl in more depth. The central issue that I will consider is why the reader might or might not prefer an algorithms book that concentrates on a single language, as opposed to a general algorithms book. I will try to be up-front about my biases: as a computer scientist, I consider this book to be a compromise between an algorithms book and a how-to manual. This compromise makes it much more useful to Perl programmers, but it sometimes causes the algorithms content to be too watered down.
It is traditional in algorithms books to describe algorithms in pseudocode, which often superficially resembles Pascal. The difference between pseudocode and real code is that pseudocode is not compilable - it ignores implementation details that are not helpful to understanding a particular example. This is considered to be an advantage: without the clutter, the core of the algorithm is easier to see and understand. At the beginning of the book the authors make the point that the Perl code for a binary search is actually shorter than the corresponding pseudocode. And it's true! The advantage of the Perl program is that we have a readable description of the algorithm, and it's executable too. (Unfortunately, it's often nontrivial to convert pseudocode into real source code - the devil is in the details.) The binary search example is slightly misleading, however, because in this case a native Perl data structure (the array) matches the semantics of the problem extremely well, leading to a clear and concise implementation. Later in the book, particularly in the chapter on graphs, we see examples where Perl's built-in data structures are less well suited to the problems. The executable Perl code for graph operations are much longer than the corresponding pseudocode, and are often so syntactically cluttered that they are difficult to read. Is this a flaw in the book or in Perl? No - it's a consequence of giving examples in runnable code instead of pseudocode. Is the tradeoff worth it? Probably, but it depends on what you're trying to get out of the book.
Another consequence of basing an algorithms book on a real language is that the authors can point readers to existing implementations of the algorithms, in CPAN. It's hard to overstate how big of a win this is. Perl is a powerful language to begin with, but it becomes far more powerful when programmers are able to take advantage of the large body of existing code modules. An unfortunate side effect of the fact that the book talks about specific versions of Perl and about specific CPAN packages is that this information will become outdated much more quickly than the algorithms will. Unless the Perl language and CPAN are exceptionally stable in the future, I would not expect most of this information to be valid for more than a few years - hopefully a new version of the book will be available before this one becomes too out of date.
Because the book provides executable code for the algorithms, it's possible to evaluate the performance of the example code (which is available at the O'Reilly site). The authors benchmark a number of the algorithms that they present, and compare the results. This is a nice change from the discussion of asymptotic running times found in traditional algorithm books, which generally ignore the constant factors that often make the difference between an algorithm being useful in practice or not.
The design and analysis of algorithms is a highly mathematical discipline. A sophisticated set of tools has been developed to evaluate the tradeoffs between various algorithms: How efficiently do they use memory and processor cycles? What is the best, average, and worst case running time of various operations? How does the algorithm scale as the size of the input grows? As it turns out, programmers need to understand a few of these formalisms, particularly the "big O" notation for describing asymptotic running time. I think that Mastering Algorithms with Perl uses theory in just the right way: as an aid to programmers' intuition about algorithms, rather than beating us over the head with formulae and proofs. That said, I think there is one area of theory that this book should have spent more time on: NP completeness. NP-complete problems are solvable, but are believed to be inherently hard: no efficient algorithm has been discovered to solve them. There are a wide variety of NP-complete problems, and they do come up in practice. For programmers, the important thing is first to recognize that an NP-complete problem has been encountered, and that it cannot be solved exactly except in small instances. Then, a heuristic that comes up with a good enough approximation of the solution needs to be found and implemented. This is a practical and well-studied part of algorithm design, and in a 650-page book I would expect more than a page or two to be devoted to it.
Several chapters of Mastering Algorithms with Perl are too shallow to be considered good introductions to the associated areas of algorithms. For example, the chapter on matrices only shows code for some of the more trivial matrix operations; for complex tasks, it tells the reader how to use PDL - the Perl Data Language. Although PDL looks like a useful and powerful package, readers should not confuse knowing how to use it with understanding matrix algorithms. In other words, the matrix chapter is too much of a how-to manual. Other chapters such as the ones on searching and sorting are excellent and avoid falling into this trap. Algorithms is a huge area, and it can't all be covered well in 650 pages. The later chapters are a lot of fun to read, but some of them should probably have been scrapped in favor of more depth in core areas.
In conclusion, this is a well-written, useful book. Viewed as a Perl book it's superb; it complements the strengths of Programming Perl and The Perl Cookbook, and I think most or all Perl programmers would benefit from having a copy. Viewed as a computer science book, it has made a number of compromises in order to focus on a specific language; this is not necessarily a problem but it is something that readers should be aware of.
Acknowledgments: Thanks to Tom Christiansen, Dave Coppit, Bill Pearson, and Jamie Raymond for helpful comments on previous drafts of this review.
Purchase this book at fatbrain.
Perl Algos (Score:1)
--
Algothingies (having just forgotten how to spell) (Score:2)
Argh. Can anybody recommend a good basic book for those of us not from a Computer Science background (my degree is in theatre) but who are trying to get into programming, albiet slowly?
Re:Algothingies (having just forgotten how to spel (Score:1)
Re:Algothingies (having just forgotten how to spel (Score:1)
Pseudocode and Introductory Books (Score:2)
Second, I'd like to ask why a good, pseudo-code, readable language *isn't* more popular nowadays. There are many books written like this (my Operating Systems text in school, and many of the examples, are written in something that looks like Pascal with support for multiple processes, although I've never seen such a beast) and their code is very readable.
I used to write in Turbo Pascal 7, and I enjoyed writing classes ("objects") with it. All my code was inherently pretty readable, even when I used nasty tricks, unlike my C code (or most Perl code that I've seen). Later, I did convert some of it to C and C++ with p2c and some hacking on my own, but it would be nice to maintain the readable version of the code.
---
pb Reply or e-mail rather than vaguely moderate [152.7.41.11].
Re:Algothingies (having just forgotten how to spel (Score:1)
I don't really have any programming background, just batch files and shell scripts. The best thing I have found to do is find a piece of code, play with it, and look up what you don't understand.
Guess I have to add yet another O'Reilly book to the collection...
This Book... (Score:2)
Re:Algothingies (having just forgotten how to spel (Score:2)
I would recommend Learning Perl also by O'Reilly & Associates. When I first started learning Perl, this book was invaluable. Perl was also, for me anyway, a good first programming language to learn on. Prior to that, the only other language I had learned was BASIC, and only very little. Most people will recommend not starting with a language like C, due to its complexity. Perl seems to be a good starter.
I now use Programming Perl and Perl Cookbook. Both are from O'Reilly & Associates. This book also sounds like a good reference to have once you have the basics down.
Ryan
P.S. My major was also theater (design).
So-so book (Score:2)
So, if you are collecting all Perl book, or are really interested in how to implement red-black trees in Perl, do buy it. On the other hand, if you are looking for snippets of code to solve small-to-medium-sized problems you meet all the time, "Perl Cookbook" is a much better choice.
Kaa
Learning Python (Score:1)
This is straying onto religious war territory, but Python's possibly an "easier" language to learn than Perl for a newcomer to programming, and it's certainly as powerful (and anyway, they have a lot in common).
Hope This Helps,
Andy
Re:Algothingies (having just forgotten how to spel (Score:2)
You don't necessarily need a book. Although I like having a peice of paper to reference (call me old-fashioned), there are many resources you can access for free on the internet (and print out if you're like me). Just hop over to http://www.google.com and enter the words "Perl Tutorial" for lots of good links.
Re:mastering alogithms in perl (Score:1)
Errr.. ?
I think you are missing the point. There are plenty of books on Algorithms. Loads. Really, lots and lots and lots. However, until now there were few that focussed on Perl.
Some consider Perl to have outgrown its old 'Unix scripting language' roots, and so a book that looks at a strong foundation of programming principles for Perl is welcome.
If this book is shelved with 'Algorithms' then it has been misshelved, I'll grant you. If it is shelved with 'Perl' then it is a very useful contribution.
I don't think the author's were trying to promote greater understanding of algorithms and forcing people to learn Perl while they did it.
Re:Algothingies (having just forgotten how to spel (Score:2)
Re:So-so book (Score:2)
For an algorithms book, Wolf is quite nice. It has some wonderful discussions of queues, stacks and their relatives. This far from a so-so book for what the book intends to discuss. Ram is quite nice too for that "how do I find the difference of two arrays again"? type problems.
Please DO NOT compare apples to oranges.
This Book... ... is not for you! (Score:1)
Perl has been unusual in being a language that started in a small niche were it was used by non-computer-science folk (Unix sysadmin), moved into ANOTHER niche of the same kind (simple CGI), and is now widening its usage into a general applications programming language.
That's why these kinds of books are very useful - so many Perl programmers such as me never went near a CompSci class.
NP-completeness (Score:2)
There is one part of the review which doesn't make much sense
That said, I think there is one area of theory that this book should have spent more time on: NP completeness. NP-complete problems are solvable, but are believed to be inherently hard: no efficient algorithm has been discovered to solve them. For programmers, the important thing is first to recognize that an NP-complete problem has been encountered, and that it cannot be solved exactly except in small instances.
A big part of this is simply wrong. Problems are NP-complete if it is proven that there is no algorithm which solves it in polynomial time. What he describes is NP-hard. His basic requirement, finding out if a problem is NP-hard needs some literature research. To recognize an NP-complete problem one can read about it if it is known. If no literature is found, showing that the problem is NP-complete will take skills on highly advanced levels.
RSA crypto is a good examples: It relies on factorization being NP which has not been proven. It uses so calld strong primes to avoid polynomial factorization algorithms.
Re:Algothingies (having just forgotten how to spel (Score:3)
If you'd like an online tutorial, you might want to check out The CGI Resource Index [resourceindex.com], which is made by the same guy as Matt's Script Archive [worldwidemart.com]. Between the tutorials on the Resource Index, looking at the source of Matt's script, and reading the O'Reilly books, you can learn just about anything you want to know about Perl.
Of course, if you get stuck, you can always go to ng's, irc, or your local Perl nut.
Excerpt available on line (Score:4)
--Kevin
=-=-=-=-=-=
"I think the P-Funk Mothership just landed in my back yard!"
Re:Algothingies (having just forgotten how to spel (Score:1)
What would be the next step by ORILY? (Score:2)
Why Perl? Perl's day is over (Score:2)
Re:Pseudocode and Introductory Books (Score:1)
But of course, obfuscated code is cool, etc.
Andy
Re:NP-completeness (Score:1)
Learning that there are distinct classes of problems, and being able to have a gut feeling that one problem is intrinsically harder than another is an important skill.
No, YOU are wrong (Score:4)
Wrong. Problem A is NP-complete if there are no problems in the set NP that are harder than A.
Furthermore, no one has yet proved that NP problems cannot be solved in polynomial time, although it is widely suspected this is true.
What he describes is NP-hard.
The classes *I* took used "NP-complete", "NP-hard" and "hard for NP" synonymously.
Again, just plain wrong. Prime Factorization is known to be NP (NP-complete, in fact). What is NOT known is whether PF can be solved in polynomial time.
It sounds very much like you picked up your Computation Theory knowledge by reading posts on Slashdot. I don't recommend that for people who enjoy flaming.
---
Re:NP-completeness (Score:1)
No, it's your post which doesn't make much sense.
A big part of this is simply wrong.
No, it's not.
Problems are NP-complete if it is proven that there is no algorithm which solves it in polynomial time.
No. A problem is NP complete if it is in NP (i.e it is an decision problem whose solution can be verified in polynomial time) and if every other problem in NP reduces to it. It is believed that there is no polynomial time algorithms for NP complete problem, but this has not been proved.
A problem is NP hard is every problem in NP reduces to it (i.e it need not necessarily be in NP)
If no literature is found, showing that the problem is NP-complete will take skills on highly advanced levels.
I'm not sure what you mean by "highly advanced". We teach it to second year undergraduate CS-students.
My (limited) experience with real-life examples is that they are either trivial or quite difficult to prove NP-complete.
Usefulness of this book. (Score:2)
I have this book in my library, but don't think I'd buy it again if I had to rebuild it. It's one of the few perl books that collects any dust on my self.
minor nit.. (Score:2)
Python is also conceptually simple, but it stresses operator overloading over object re-use and inheritance trees are typically pretty shallow. Lack of types make for code that's quick to write, not too hard to read, but you have to check them well because your arguments could be anything.
Maybe there should be an "Algorithms in Python" book. The language is ideal for beginners - even moreso than Java because of built-in lists and hashes.
Just my minor nit about typing :)
Try reading "Object Oriented Perl" (Score:3)
Really though you're trolling. Sure there are things wrong with perl (like the fact that the second argument to bless isn't mandatory), but you can create crap code in any language. If you have experience of building a large app in perl and it all went horribly wrong because it got too large - you only have yourself to blame.
Re:Algothingies (having just forgotten how to spel (Score:1)
Buy an O'Reilly book.
A Good place to start for linux programming (Score:1)
Re:ahem - Microsoft- sponsored trolling (Score:1)
I Really Liked this Book (Score:1)
I've always found it easier to understand mathematic concepts transcribed to code because of the lack of vagueness allowed by computer languages. The author can't skip a step(s), refer broadly to previous concepts that may or may not have been explained/understood, or hide ideas necessary for full understanding by invoking the classic "you don't need to know this yet" mantra extolled in most lower level mathematic books.
I find also that because computer languages have been engineered from the ground up to reuse previously mastered concepts ( functions & | objects) they lend themselves well to explaining very complex ideas.
Higher level mathematics can and are expressed as proofs, lower level mathematics should be expressed as computer algorithms..? Written in perl? Works for me!
This book is just fun. :)
Instant Gratification (Score:2)
I picked up Lutz & Ascher's Learning Python just over a week ago, and I already love it. One of the great things about Python as a learning language is its "interactive" mode; run the interpreter without a program file ("module" in Python terminology), and you get an interactive prompt. Just start typing in statements; you can define functions, set variables, load modules, etc. Anything with a return value displays that value. It's a lot easier for experimenting with different statements than the usual cycle of edit a file, run it, edit it again, run it again, etc.
I've seen Python described as "pseudocode that runs", and so far, I have to agree; it pushes you toward writing more readable code. Yeah, yeah, yeah, "you can write readable or unreadable code in any language", and that's true. But where Perl seems to require additional effort to write readable code, Python seems to require extra effort to write unreadable code.
Re: Matt Wright (Score:1)
Kurumi http://www.kurumi.com [kurumi.com]
Another algorithms text recommendation (Score:3)
Far more mathematically rigorous than the O'Reilly book (from what I read of the O'Reilly book in the bookstore - I didn't buy it because it didn't look like much I didn't already have). No actual code, just pseudocode. I think this is the book you want if you really want to learn about algorithms (but not if you just want to get stuff done in Perl).
It's expensive, but it's a tome (>1000 pages). It was a good class textbook and still makes a very good reference. Check out the Table of Contents [fatbrain.com].
Re:Summary (Score:1)
Get the camel book. You cannot go wrong with that. -
"Programming Perl, 2nd Edition" by Larry Wall, Tom Christiansen and Randal L. Schwartz
ISBN 1-56592-149-6
"Perl in a Nutshell" ISBN 2-56592-286-7 is a handy companion volume organised for quick reference
I haven't got a copy myself, but I will when I get organised enough to get it.
I also recommend "The Perl Cookbook" ISBN 1-56592-243-3, which contains a load of useful code snippets to do all sorts of things. I found it very useful for "learning by example".
I think one of the major reasons for the popularity of Perl has been the availability of well-written documentation such as these three books. Another reason is the CPAN code repository, which makes code reuse easy.
Re: Matt Wright (Score:1)
Larry Wall and O'Reilly (offtopic) (Score:1)
Maybe he's spending all his time on the next State of The Onion...
Re:Instant Gratification (Score:1)
What, no mention of Smalltalk (check), Ada(check), or Dylan^WButt-Head Musician (nope)? After the first three or four languages you learn, the next twenty become easier. Not that I remember most of these languages, but I did assimilate the basic principles once upon a time. I keep telling myself that I could pick them up again pretty quick if anyone ever did take my resume seriously.
Re:Why Perl? Perl's day is over (Score:1)
The thing I like about Perl is that it gives you _freedom_. You just need to have discpline for large scale projects. (not really different then in any other language).
Reg Exp are condensed code and I find if used properly they increase code readability since a single line of reg exp contains a complete thought in one concise statement - instead of spreading the purpose over several loops of code.
Re:NP-completeness (Score:1)
If you can prove the nonexistance of a polynomial time algorithm for any NP-complete problem, you'll get a Turing Award.
Re:Algothingies (having just forgotten how to spel (Score:1)
Yeah, you definitely won't want to start your programming experience with algorithms if you're new to programming.
I would also really suggest that your first programming language be something (anything! ;-) ) other than Perl. It's really easy to use, but it makes it so easy to fall into bad programming habits. This is a good thing if you already know what you're doing, but a horrible way to start programming. This is one of the main reason why Perl gets no respect in academia -- it's still pretty much viewed as a toy language. That said, I probably have written more code in Perl than I have in any other language by an order of magnitude. I'm serious, though, don't let Perl be the first language you learn.
Something I'm really starting to enjoy is Python, and it seems to be picking up steam, so I'd strongly recommend O'Reilly's Learning Python, which seems to be about a gentle introduction to a programming language as it gets. (I'd give Learning Perl 2nd-place honors here. I still don't recommend you start with Perl, but I'm not sure why so many people dislike this book as an introductory text -- it lets you do useful things pretty much right away.) I wasn't too pleased with Programming Python, especially compared to Programming Perl, so I ended up learning the language from the Learning book and then using the great online documentation.
If I had a gentle Java book to recommend, I'd give you that as well, because despite all the troubles, I think a lot of people will eventually use it, or at least variations of it. Like Python, it'll help get you acclimated to object-oriented principles, which I recommend, and there is plenty of sample code out there for both. Not as much sample code as Perl, but you don't want to get your feet wet with Perl, do you? (Sensing a theme yet? ;-). Also, it's pretty much taken for granted that the Python folks seem like great guys and very helpful, and that the Perl guys are, well, not the friendliest people around. Jon Orwant (a Perl guy who, along with Larry Wall, I do like) was even quoted in this month's Linux Journal that the Python guys seemed nicer. Considering the dim view that many in academia have of Perl, I'm not quite sure exactly how so many in the Perl community turned out to be egotistical/self-righteous dicks, but it sure seems like it's happened. (And no, this isn't why I'm urging you from starting out with Perl -- I still use it all the time myself.)
Cheers,
ZicoKnows@hotmail.com
Re:Why Perl? Perl's day is over (reformatted) (Score:1)
Re: "Get Paid to read Slashdot... click here!" (Score:2)
Apologies for the topic drift, back to the regular discussion.
-----
The real meaning of the GNU GPL:
Re:minor nit.. (Score:1)
As for the whitespace issue, it can be annoying, but minimized with the use of a decent text editor. Python has quirks, certainly, but seems more consistant than Perl in general. Consistancy is good for beginners (maybe not for everybody, but certainly for beginners).
Re:Larry Wall and O'Reilly (offtopic) (Score:1)
Re:No, YOU are wrong (Score:1)
NP-complete is a subset of NP-hard.
NP-complete problems are all as hard as each other in the sense that either all of them or none of them can be solved by a polynomial-time
algorithm.
NP-hard problems are at least as hard as NP-complete problems. So, for example, the halting problem is NP-hard, but it is not NP-complete.
Anyway, this is not the part of NP-completeness theory that I think programmers need to know. What they need to be able to do is recognize that, for example, the way they are attempting to optimally put outgoing mail messages into the proper queue is equivalent to bin-packing, and therefore takes exponential time in the worst case. They can then go find one of the excellent bin-packing heuristics that has been developed, implement it, and then move on.
Re:Another algorithms text recommendation (Score:1)
P.S. Have you been able to get enough time with a second fork to keep from starving?
Re:No, YOU are wrong (Score:2)
NP-hard : every problem in NP can be reduced to this problem.
NP-complete : NP and NP-hard.
> Prime Factorization is known to be NP (NP-complete, in fact).
Do you have a reference for this? How do you reduce Satisfiability to factorization?
GO TO SCHOOL!!! (Score:1)
Yes, NP-complete and NP-hard are not synonymous.
So:
NP means "polynomial-time verifier".
NP-hard means "reduce to NP in polynomial-time".
NP-complete means "NP and NP-hard".
But, these all refer to classes of computable problems.
The halting problem is the prototypical "not computable" problem. Thus, it is not in NP-hard.
Hehe, I hope I got that right
nick
Well (Score:2)
If you think you know what the hell is going on you're probably full of shit.
Re:Why Perl? Perl's day is over (Score:2)
"TIMTOWTDI" may be fun and even productive for individual programming, but there are lots of different contexts in which programming happens, and, not surprisingly, they all have different tools and languages.
NP-completeness explained (Score:5)
NP stands for "nondeterministic polynomial", and is probably most easily understood as the class of problems for which the solution can be verified in polynomial time. It includes P, the class of problems that can be solved in polynomial time.
A nice example of a problem that is in NP but not known to be in P is satisfiability. This problem is given as a list of predicates of the form (x1 or x2 or not x3). The problem is finding a set of xi such that all of the predicates are satisfied.
So, it should be obvious that you can verify a solution in polynomial time - just start with the values of xi and check that all the predicates turn out true. However, there is no known general technique for solving this problem than enumerating all the possibilities, which takes exponential time.
NP-completeness takes this idea one step further. It is a large an interesting class of problems that are basically equivalent in difficulty. If you solve one, you've solved them all. Thus, if a problem is NP-complete, there's no known efficient algorithm.
The way people analyze NP completeness is do define reductions, ie show how instances of one problem can be reduced into instances of another NP-complete problem, and vice versa. Maybe this takes "highly advanced skills," but it's actually fairly routine for algorithmicists.
The class of NP-complete problems includes the travelling salesman problem, the Hamiltonian path problem, the knapsack problem, determining collisions of 3D objects, and many others.
NP-hardness is when you can reduce an NP-complete problem into the NP-hard problem, but not necessarily vice versa. Many integer optimization problems are NP-hard.
Factoring is clearly NP, but is not known to be NP-hard. It's entirely plausible that someone (Arjen Lenstra, for example) will come up with a polynomial factoring algorithm, but leave the rest
of the NP pantheon untouched.
There are some crypto algorithms that are based on NP-completeness, but NP-completeness is not in and of itself enough for strong crypto. Even if the problem is hard in general, a specific instance may be easy to solve. Unless you can prove that this never happens, you're hosed. IBM has done some excellent work in this direction with randomized self-reductions for their lattice-based crypto algorithm.
Complexity theory is one of the most beautiful areas in computer science, and NP-completeness is one of the most striking results, as it illuminates a fundamental unity across many seemingly disparate subfields of computer science. It is indeed a shame that this book skimps on its coverage of NP-completeness.
Re:Algothingies (having just forgotten how to spel (Score:1)
The reason that Scheme is not as well known as a programming language is that it is sort of the "learning beater car" of programming languages. Scheme's main utility advocates are in AI and its sub-disciplines, so commercial applications will not be written in Scheme. There is no great market for Scheme programmers, but there is a market for programmers who can understand the fundamentals behind great programming. I think that this book especially lends itself to the beginning programmer- and for web support of all kinds the Scheme Repository [indiana.edu] of Indiana University is rivalled only by the Schem Underground [mit.edu] at MIT.
Good luck in your programming endeavors!
Re:Instant Gratification (Score:1)
There is. Or rather it stands for a family of languages, the most proeminent ones being Standard ML (SML) and Objective Caml (O'Caml). ML itself is a shorthand for "Meta Language" and was designed in the 70's as an implementation language for a theorem prover at the university of Edimburgh.
ML languages are functional, strongly typed, have type inference, are mostly interpreted but can be compiled to native code. The syntax is very expressive. They also support imperative programming, and object-oriented programming in O'Caml case.
And to be a little more on-topic, they are very well-suited to study algorithms (and actually used to teach classes), though the functional semantics can be mind-boggling to those used to imperative languages.
Xavier
Well, no... (Score:2)
I'm not angling to repeat the nightmares that were my attempts to reduce problems to other NP-complete problems, but it seems pretty obvious that PF is in NP. I can definitely verify a solution in polynomial time. All that would remain is to show that the number of primes increases at the same rate as the number of possible solutions to a SAT problem. Now that I think about it, I don't think the number of primes grows exponentially, so maybe PF isn't NP-complete. Huh.
---
Re:GO TO SCHOOL!!! (Score:1)
Re:Another algorithms text recommendation (Score:1)
Also, the book is not the expensive, I think I only paid $55. And for a book of its size and content, it is a very attractive price.
Re:Algothingies (having just forgotten how to spel (Score:1)
There are plenty of amazingly well written books on the subject.
Personally I guess I would suggest trying to pick up a Kernigan (Programming C), Any of the O'Reilly 'Learning' books, and if you feel adventurous you might even try Knuth's Art of Computer Programming series.
If you've got a clear idea of what you would like to learn though the best thing to do would be to go to the book store and just start flipping through books and see what you like.
Good luck!
Whoa...easy, killer! (Score:1)
I even said that Perl is really easy to use, that you can get useful things done right away while reading Learning Perl, and that I've written a lot more code with it than any other programming language. Why would you think I'd want to ban it? (Yeah, I know you were exaggerating, but still.)
The guy to whom I replied said that he was looking to learn programming, not to learn Perl, or had some specific thing that he needed to get done. I just don't think that learning Perl is very helpful if you're looking to learn programming in general or plan to use other languages later. I definitely wasn't attacking Perl.
As to the other person who replied to me: The Perl Cookbook is great (I own the Perl CD Bookshelf which has it and I have the dead-tree version at work), but I wouldn't recommend it to someone who, like the person whose post I answered, has never done any programming before. I'd suggest checking out Learning Perl first so that he isn't totally lost by things like all those expletives in the language ($@_!#%) ;-).
Cheers,
ZicoKnows@hotmail.com
Re:Algothingies (having just forgotten how to spel (Score:2)
Re:Instant Gratification (Score:2)
The older I get, the further away I get from this attitude. Currently, my feeling is the fewer things you need to learn to get the job done, the better off you are. I know Perl pretty well (if you already know Unix, Perl comes easy), the documentation for it is excellent (arguably the best of any language, ever), and there's a huge base of written code on CPAN for me to draw on. I'm not going to learn Python because some math geeks think it's more elegant. In fact, I will learn another scripting language if, and only if, someone holds a gun to my head. I will be perfectly happy if I can spend the rest of my life learning in more depth the things that I already know something about (on my personal shortlist is perl, SQL, C++ and elisp).
For you newbies, I'd suggest that you consider the fact that you're probably not going to be able to get by without learning some Perl, but you *can* probably get by without learning any Python. Perl has a reputation for being difficult to learn in some circles, but I think that this is grossly exaggerated. There's a school of thought that says that languages should be stripped to their essentials, and have nothing in them but the absolute core set of things that they need... but in practice this never works, they always accumulate complications, and Perl has always just ignored that "elegance through oversimplification" philosophy. I'm actually beginning to think that Larry Wall is right about Perl being more "language-like" than most computer languages... it appeals to a different kind of head, with a different style of thinking.
In many ways, I think the book Mastering Algorithms with Perl is a blow in this war with the academic CS geeks. It *assumes* that you're someone who's learned Perl on the street without any formal CS background, and lets you in on the secrets using what may be the "lingua franca" of the software world: Perl.
Re:Another algorithms text recommendation (Score:2)
Yup. I have a secret - I put the forks in my pocket while I think.
Pisses off the other philosophers, but what do I care?
Re:Another algorithms text recommendation (Score:2)
Granted, the course I took was both a CS and a math course, and if you don't care about the math you'll end up skimming some of the text. It is fairly formal and academic.
Don't Learn Perl (was: Algothingies) (Score:1)
I'm not knocking Perl as a language - I use it all the time - but it's not suitable as an introduction to programming. I've not used Python, but the reasons that other posters have put forward suggest to me that it may be appropriate.
At our school we teach the functional language
Haskell in our first course, then C. Java, C++, and even a little Prolog and Assembler are taught along the way through. Haskell is a great teaching language, partly because it knocks the smart-alecs who know C++ before they get in to university back on their arse, partly because it's a great introduction to some pretty clever concepts like strong typing and recursion.
However, for someone having a taste of programming to see if they like it, it's probably a little intimidating and not easy to immediately write useful programs.
John McDonald is a really nice guy (Score:2)
He was a really nice guy, and he told quite a few interesting stories.
Re:GO TO SCHOOL!!! (Score:1)
The halting problem is the prototypical "not computable" problem. Thus, it is not in NP-hard
Nope. NP-hard and NP-complete refer to decision problems.
The halting problem is a decision problem, and it's at least as hard as satisfiability. Therefore, it is NP-hard.
Re:Algothingies (having just forgotten how to spel (Score:1)
Here's a place to look... (Score:1)
---
pb Reply or e-mail rather than vaguely moderate [152.7.41.11].
Re:Instant Gratification (Score:1)
(if you already know Unix, Perl comes easy)
I think you mean 'C'. If you know Unix shell programming, Tcl comes easy. Perl remains excessively incoherent.
For you newbies, I'd suggest that you consider the fact that you're probably not going to be able to get by without learning some Perl,
Care to elaborate? What can you do in Perl that you cannot do in Python? Apart from
It *assumes* that you're someone who's learned Perl on the street without any formal CS background, and lets you in on the secrets using what may be the "lingua franca" of the software world: Perl.
I can probably find someone who feels the same about Visual Basic. Doesn't make it any more true. Perl has a head start: But so did Cobol.
I wish Python had been around when I learned Perl - I wouldn't have chosen as wrongly.
Re:minor nit.. (Score:1)
Yes, but that's just because any language derived from C is a terrible beginner language.
Re:What would be the next step by ORILY? (Score:1)
Re: Matt Wright (Score:1)
When I started learning perl, I figured a good way to do it would be to a) read the camel, b) look at lots of code. Matt's stuff is all over the place so I started reading it. It took me ages to weed out the bad habits I acquired.
Except as an excercise in correcting other people's mistakes, don't touch the stuff.
Re:Another algorithms text recommendation (Score:2)
Re:Pseudocode and Introductory Books (Score:2)
It is -- Python is actually quite popular. It's nowhere near as popular as Perl, but its community is well past critical mass (so to speak), and is also much, much nicer.
-Billy
Re:Algothingies (having just forgotten how to spel (Score:1)
That's worse than looking at Microsoft on how to design Operating Systems - at least Windows works for certain values of "work", which is more that you can say from Matts scripts. There are daily complaints in comp.lang.perl.misc about people having problems with his scripts.
-- Abigail
Re: Matt Wright (Score:1)
No, it's not. It's bad code, and because it's bad code, it's a very bad starting point.
-- Abigail
Re:Instant Gratification (Score:1)
I've never been much of a C programmer, and have more experience with shell programming. Yet, Perl was quite easy for me, and I might say, I can code a thing or two in Perl.
What can you do in Perl that you cannot do in Python?
Nothing of course. Just like you cannot do anything in Python you can't do in Perl. Or VB for that matter - they're all Turing equivalent.
But you need far less parens in Perl, and because of the use of $ and friends, you can interpolate variables in strings, leading to less punctuation characters. In the end, it evens out. (Now, why doesn't anyone complain about English? All those comma's, periods, question marks, parens, etc, etc?)
As for the OO system in Perl, it sucks. But then, it's copied from Pythons.
There's one thing that makes it hard to learn Python, and that are the extremely cryptic error messages. Specially compared to Perls.
Now, why does anything remotely Perl related on Slashdot always ends up in Perl bashing? The topic here is the book "Mastering Algorithms in Perl", not "my favourite pet language is Python and Perl sucks".
-- Abigail
Re:Algothingies (having just forgotten how to spel (Score:1)
It's lack of memory management is one of the reasons C sucks as a first language. It makes the beginning programmer get lost in details better left to the computer; taking away his/her time from focussing on the problem. Perl as a first language sucks too, but for different reasons. Python, Java, LPC, Ada or something from the ML family are much more suitable.
-- Abigail
Re:No, YOU are wrong (Score:1)
You're all wrong.
The set of NP problems consists of a set of problems in NP which are all P reducable to each other. Hence, if one problem of the set of NP-complete problems is found to be in P, they all are. NP-hard problems are "harder". One can P reduce an NP-complete problem to an NP-hard problem, but not the other way around. Hence, discovering that NP-complete == P doesn't solve the P ?= NP question; as it doesn't prove that the NP-hard problems are in P.
The classes *I* took used "NP-complete", "NP-hard" and "hard for NP" synonymously.
You should ask your money back.
-- Abigail
Don't buy the CRS book! (Score:1)
Dr. Dobbs has it as part of their Algorithms CD. It has full text searching, too!
Not only that, but the price is lower than you would normally pay for the CRS book alone.
My only complaints are:
- the interface was a bit weird and buggy
- you can only browse it using the supplied Windows app (I think; I lent it to someone and never got it back).
Graham
Re:GO TO SCHOOL!!! (Score:1)
NP-hard means "reduce to NP in polynomial-time".
NP-complete means "NP and NP-hard".
That would mean that NP-hard == N-complete, yet you write:
NP-complete and NP-hard are not synonymous.
-- Abigail
Re:GO TO SCHOOL!!! (Score:1)
No, it's not. The halting problem isn't computable.
-- Abigail
Re:Another algorithms text recommendation (Score:1)
Good for you. I've teached grad students from this book, and it's a very good textbook on algorithms and datastructures. I need to get myself a new copy as well - mine is falling apart.
-- Abigail
Re:Larry Wall and O'Reilly (offtopic) (Score:1)
Perhaps because he isn't employed as an author?
-- Abigail
Re:ahem - Microsoft- sponsored trolling (Score:1)
Not so good. (Score:1)
Some parts of the book don't contain more than "if you want to do `foo', just call the function (or method) called `foo' in this package". I really, really don't need a book to state what I can find easily in a manual as well.
In the parts they do discuss algorithms, they often get side-tracked, by either explaining language features, or showing a trick that saves 0.5% of your execution time. The important things get burried in the details. It has been argued that having "real code" and not pseudo-code is a feature. In my opinion, this books makes an excellent argument in favour of pseudo-code. Pseudo code doesn't have to bother with language details, and people writing pseudo-code have to waste time wondering whether an alternative construct saves 1% of time. An algorithms book should focus on algorithms, not on the language.
If you want a bag of tricks, get Effective Perl Programming, if you want a bag of useful code snippets, get The Perl Cookbook, if you want to know modules, read their man pages, and if you want to learn algorithms, get a real algorithms book, like Cormen, Leierson, Rivest, Knuth's The Art of Computer Programming, or something from Wirth or Mehlhorn.
-- Abigail
Re:Pseudocode and Introductory Books (Score:2)
My apologies. That was VERY unclear, and is not what I meant to say.
I meant to say that the Python community is very nice. I've mingled very little with the Perl community, so I have no qualification for calling them meanies
However, I have mingled with the Python community, and there are some great guys there.
-Billy
Re:Pseudocode and Introductory Books (Score:1)
I apologise for the comparative -- I didn't mean it. I was just saying that the Python community is helpful.
I'm rather frightened by the fact that my slip of the pen was correct. I'm sorry about that.
In both cases, popularity destroyed that community.
No offence meant, but look at the size of the Python community. It's by no means as huge as Perl's, but it still gets a lot of newbies. Somehow they all wind up contributing to the community.
Perhaps Perl's and C++'s problems are that they're not easy languages to learn. Perhaps the problem IS the sheer size of the crowd. We'll see. You do have to notice, though, that Perl and C++ are not seperate cases; they're both very complex languages with highly non-orthogonal syntax.
-Billy
Re:Pseudocode and Introductory Books (Score:1)
Perhaps that's true for system administrators, though. Before Perl, they had to use AWK, grep, ed, and many other awkward tools. Perl slaps all those together MUCH better than the Unix command line could.
Even there, though, there's no reason for a programmer to prefer Perl to Python (unless they only know Perl, of course). Their programming abilities are about equivalent, except that Perl throws a lot of sysadmin stuff your way whether you ask for it or not.
-Billy
Algorithm Book (Score:3)
- Computer Algorithms: Introduction to Design and Analysis 3rd Ed
by Baase and Gelder. I just took my intro to algo course in which this was used as a text; it is very much readable and the examples really do illustrate the principles they claim to. It spans every thing from a base level introduction to NP-complete.Having checked my copy of "PC Roadkill"... (Score:2)
Re:Algothingies (having just forgotten how to spel (Score:2)
Others have responded that Matt's scripts aren't really a good source of information on how to program perl idiomatically, or maybe even correctly. :-)
But to add something to this thread, I'd like to point out that you really, truly can learn much more about Perl than you'd ever get from Matt's Script Archive by going to the Perl home page at www.perl.com [perl.com]
After you've spent a couple of weeks digesting that, it is possible that you would want to know even more, so you can go to Tom Christiansen's Far More Than Everything You've Ever Wanted to Know About... [perl.com] web page, if you haven't already. Oh yeah, and you can buy O'Reilly books, too. :-)
Not true (Score:2)
R is definitely for Rivest. Check the "What is RSA? [rsasecurity.com]" section of RSA's cryptography FAQ. I quote directly:
RSA is a public-key cryptosystem that offers both encryption and digital signatures (authentication). Ron Rivest, Adi Shamir, and Leonard Adleman developed RSA in 1977 [RSA78]; RSA stands for the first letter in each of its inventors' last names.
Re:Instant Gratification (Score:2)
That's probably the biggest truth in this whole thread. Perl and Python just appeal to different people. Sure, you can write structured code in Perl, but if that's what you want to do, you'll probably use Python because it was designed with that in mind. Likewise, you can make efforts towards writing code that follows your own thought process in Python, but it's not going to be nearly as easy.
And a really good programmer with a style somewhere in between could write code that was just as good in both languages (it might run faster in Perl as a result of the more mature interpreter). They just appeal to different mindsets.
I suspect one of the greatest problems Python advocates have (and I have to count myself in that group) is that since Perl came out first and became very popular, a lot of people to whom Perl's way of doing things doesn't particularly appeal and still programming in it anyway because they learned it first. Slightly more valid is the argument that Perl is better because CPAN exists---yeah, that's good, but it's not really talking about the language and is partly a benefit of age. As a result, Python advocates exagerrate the flaws of Perl and the pros of Python. It's a lot like Free Unices vs. the rest of the world. You know there are people out there who would be better off on your side---certainly not all---but they're stuck over there and unless you scream your head off they won't look at you (not that I advocate this procedure).
One final comment is that I think that the spirit behind the creation of the language is also something to be considered. Both are certainly general purpose, but Perl has had a lot of influence from the need to process text, hence a lot of choices that are unpopular with people who don't want to do this. Its syntax reflects this. Python has a lot of influence from the desire to make it easy for nonprogrammers to learn, hence a lot of things (whitespace) that others don't like. But Guido is doing all he can to make sure Python 2.0 (whenever it comes out!) will be newbie-friendly, and I'm sure Perl will never lose its roots either.
Cybernetic Epidemiological Report: BAD CODE SUCKS (Score:3)
Without seeing the code for those important parts, I can't say for sure, but given the rest of the non-industrial strength code, one can easily imagine the worst.
That would read better like this:
Because otherwise you have too much needlessly duplicated information.Better yet, you should just split into my ($key, $value) and loop across those in the same way. The anonymous array just seems to hurt legibility.
That should be far more than enough nits and gnats to keep you thinking for a while.
Absence of evidence does not imply evidence of absence.Here's my suggestion: read the CGI.pm source very, very carefully. There's a lot to learn. Good luck. Hopefully, you'll repent of your hackish ways that help give Perl a bad name by spreading bad CGI code around the world.
I shan't be tilting at any straw windmills.I shall, however be patiently awaiting your public apology and contrition.
Re:Cybernetic Epidemiological Report (Score:2)
As for the matters of strict, your disdain for robust coding should scare the hell out of any employer or co-worker. And symbolic reference are 99% of the time used because someone had no clue how to build a proper data structure.
You have a long ways to go yet in becoming a competent software engineer. And you don't seem to be on that path right now.
There's much more to CGI than you seem to realize. For example, do you even understand the critical semantic difference between GET and POST? They're hardly interchangeable.
If I should ever write a book on low-level CGI internals (which I hope to avoid), I shall be sure to include all this. Meanwhile, you should abandon your attempts at wheel re-implementation, because you're doing it in a dangerously cavalier and often completely wrong fashion. I stand by my work: the module is going to get things right that 98% of the script kiddies will never even understand. So use it.
Re:Cybernetic Epidemiological Report (Score:2)
Pay attention. You are dangerous. This is the horribly stupid perl code that people trash the language about, and you're part of the cause!
Re:Cybernetic Epidemiological Report (Score:2)
Re:Cybernetic Epidemiological Report (Score:2)
This is part of being a glue language. We glue to everything. We can only teach you how to attach the glue. You need to understand what you're gluing to.