The Solver - Store
Buy crossword, anagram, sudoku related products
|
Home page
|
Wednesday, 17 August 2005 |
|
Current Store: UK Store
Books : Perl Best Practicesby: Damian Conway Related Items:
Editorial Review: Book Description: Many programmers code by instinct, relying on convenient habits or a "style" they picked up early on. They aren't conscious of all the choices they make, like how they format their source, the names they use for variables, or the kinds of loops they use. They're focused entirely on problems they're solving, solutions they're creating, and algorithms they're implementing. So they write code in the way that seems natural, that happens intuitively, and that feels good. But if you're serious about your profession, intuition isn't enough. Perl Best Practices author Damian Conway explains that rules, conventions, standards, and practices not only help programmers communicate and coordinate with one another, they also provide a reliable framework for thinking about problems, and a common language for expressing solutions. This is especially critical in Perl, because the language is designed to offer many ways to accomplish the same task, and consequently it supports many incompatible dialects. With a good dose of Aussie humor, Dr. Conway (familiar to many in the Perl community) offers 256 guidelines on the art of coding to help you write better Perl code--in fact, the best Perl code you possibly can. The guidelines cover code layout, naming conventions, choice of data and control structures, program decomposition, interface design and implementation, modularity, object orientation, error handling, testing, and debugging. They're designed to work together to produce code that is clear, robust, efficient, maintainable, and concise, but Dr. Conway doesn't pretend that this is the one true universal and unequivocal set of best practices. Instead, Perl Best Practices offers coherent and widely applicable suggestions based on real-world experience of how code is actually written, rather than on someone's ivory-tower theories on how software ought to be created. Most of all, Perl Best Practices offers guidelines that actually work, and that many developers around the world are already using. Much like Perl itself, these guidelines are about helping you to get your job done, without getting in the way. Synopsis: Many programmers code by instinct, relying on convenient habits or a "style" they picked up early on. They aren't conscious of all the choices they make, like how they format their source, the names they use for variables, or the kinds of loops they use. They're focused entirely on problems they're solving, solutions they're creating, and algorithms they're implementing. So they write code in the way that seems natural, that happens intuitively, and that feels good. But if you're serious about your profession, intuition isn't enough. "Perl Best Practices" author Damian Conway explains that rules, conventions, standards, and practices not only help programmers communicate and coordinate with one another, they also provide a reliable framework for thinking about problems, and a common language for expressing solutions. This is especially critical in Perl, because the language is designed to offer many ways to accomplish the same task, and consequently it supports many incompatible dialects. With a good dose of Aussie humor, Dr.Conway (familiar to many in the Perl community) offers 256 guidelines on the art of coding to help you write better Perl code - in fact, the best Perl code you possibly can. The guidelines cover code layout, naming conventions, choice of data and control structures, program decomposition, interface design and implementation, modularity, object orientation, error handling, testing, and debugging. They're designed to work together to produce code that is clear, robust, efficient, maintainable, and concise, but Dr. Conway doesn't pretend that this is the one true universal and unequivocal set of best practices. Instead, "Perl Best Practices" offers coherent and widely applicable suggestions based on real-world experience of how code is actually written, rather than on someone's ivory-tower theories on how software ought to be created. Most of all, "Perl Best Practices" offers guidelines that actually work, and that many developers around the world are already using. Much like Perl itself, these guidelines are about helping you to get your job done, without getting in the way. From the Publisher: Perl Best Practices offers a collection of 256 guidelines on the art of coding to help you write better Perl code--in fact, the best Perl code you possibly can. The guidelines cover code layout, naming conventions, choice of data and control structures, program decomposition, interface design and implementation, modularity, object orientation, error handling, testing, and debugging. About the Author: Damian Conway holds a PhD in Computer Science and is an honorary Associate Professor with the School of Computer Science and Software Engineering at Monash University, Melbourne, Australia. Currently he runs an international IT training company--Thoughtstream--which provides programmer development from beginner to masterclass level throughout Europe, North America, and Australasia. Damian was the winner of the 1998, 1999, and 2000 Larry Wall Awards for Practical Utility. The best technical paper at the annual Perl Conference was subsequently named in his honour. He is a member of the technical committee for The Perl Conference, a keynote speaker at many Open Source conferences, a former columnist for The Perl Journal, and author of the book Object Oriented Perl. In 2001 Damian received the first "Perl Foundation Development Grant" and spent 20 months working on projects for the betterment of Perl. A popular speaker and trainer, he is also the author of numerous well-known Perl modules, including Parse::RecDescent (a sophisticated parsing tool), Class::Contract (design-by-contract programming in Perl), Lingua::EN::Inflect (rule-based English transformations for text generation), Class::Multimethods (multiple dispatch polymorphism), Text::Autoformat (intelligent automatic reformatting of plaintext), Switch (Perl's missing case statement), NEXT (resumptive method dispatch), Filter::Simple (Perl-based source code manipulation), Quantum::Superpositions (auto-parallelization of serial code using a quantum mechanical metaphor), and Lingua::Romana::Perligata (programming in Latin). Most of his time is now spent working with Larry Wall on the design of the new Perl 6 programming language. Excerpted from Perl Best Practices by Damian Conway. Copyright © 2005. Reprinted by permission. All rights reserved.: CHAPTER 9 Subroutines If you have a procedure with ten parameters, you probably missed some. —Alan Perlis Subroutines are one of the two primary problem-decomposition tools available in Perl, modules being the other. They provide a convenient and familiar way to break a large task down into pieces that are small enough to understand, concise enough to implement, focused enough to test, and simple enough to debug. In effect, subroutines allow programmers to extend the Perl language, creating useful new behaviours with sensible names. Having written a subroutine, you can immediately forget about its internals, and focus solely on the abstracted process or function it implements. So the extensive use of subroutines helps to make a program more modular, which in turn makes it more robust and maintainable. Subroutines also make it possible to structure the actions of programs hierarchically, at increasingly high levels of abstraction, which improves the readability of the resulting code. That’s the theory, at least. In practice, there are plenty of ways that using subroutines can make code less robust, buggier, less concise, slower, and harder to understand. The guidelines in this chapter focus on avoiding those outcomes. Call Syntax Call subroutines with parentheses but without a leading & It’s possible to call a subroutine without parentheses, if it has already been declared in the current namespace: sub coerce # and later... my $expected_count = coerce $input, $INTEGER, $ROUND_ZERO; But that approach can quickly become much harder to understand: fix my $gaze, upon each %suspect; More importantly, leaving off the parentheses on subroutines makes them harder to distinguish from builtins, and therefore increases the mental search space when the reader is confronted with either type of construct. Your code will be easier to read and understand if the subroutines always use parentheses and the built-in functions always don’t: my $expected_count = coerce($input, $INTEGER, $ROUND_ZERO); fix(my $gaze, upon(each %suspect)); Some programmers still prefer to call a subroutine using the ancient Perl 4 syntax, with an ampersand before the subroutine name: &coerce($input, $INTEGER, $ROUND_ZERO); &fix(my $gaze, &upon(each %suspect)); Perl 5 does support that syntax, but nowadays it’s unnecessarily cluttered. Barewords is forbidden under use strict, so there are far fewer situations in which a subroutine call has to be disambiguated. On the other hand, the ampersand itself is visually ambiguous; it can also signify a bitwise AND operator, depending on context. And context can be extremely subtle: $curr_pos = tell &get_mask( ); # means: tell(get_mask( )) $curr_time = time &get_mask( ); # means: time() & get_mask( ) Prefixing with & can also lead to other subtle (but radical) differences in behaviour: sub fix { my (@args) = @_ ? @_ : $_; # Default to fixing $_ if no args provided # Fix each argument by grammatically transforming it and then printing it... for my $arg (@args) { $arg =~ s/\A the \b/some/xms; $arg =~ s/e \z/es/xms; print $arg; } return; } # and later... &fix('the race'); # Works as expected, prints: 'some races' for ('the gaze', 'the adhesive') { &fix; # Doesn't work as expected: looks like it should fix($_), # but actually means fix(@_), using this scope's @_! # See the 'perlsub' manpage for details } All in all, it’s clearer, less ambiguous, and less error-prone to reserve the &subname syntax for taking references to named subroutines: set_error_handler( \&log_error ); Just use parentheses to indicate a subroutine call: coerce($input, $INTEGER, $ROUND_ZERO); fix( my $gaze, upon(each %suspect) ); $curr_pos = tell get_mask( ); $curr_time = time & get_mask( ); And always use the parentheses when calling a subroutine, even when the subroutine takes no arguments (like get_mask( )). That way it’s immediately obvious that you intend a subroutine call: curr_obj( )->update($status); # Call curr_obj( ) to get an object, # then call the update( )method on that object and not a typename: curr_obj->update($status); # Maybe the same (if currobj( ) already declared), # otherwise call update( ) on class 'curr_obj' Homonyms Don’t give subroutines the same names as built-in functions If you declare a subroutine with the same name as a built-in function, subsequent invocations of that name will still call the builtin...except when occasionally they don’t. For example: sub lock { my ($file) = @_; return flock $file, LOCK_SH; } sub link { my ($text, $url) = @_; return qq{$text}; } lock($file); # Calls 'lock' subroutine; built-in 'lock' hidden print link($text, $text_url); # Calls built-in 'link'; 'link' subroutine hidden Perl considers some of its builtins (like link) to be "more built-in" than others (like lock), and chooses accordingly whether to call your subroutine of the same name. If the builtin is "strongly built-in", an ambiguous call will invoke it, in preference to any subroutine of the same name. On the other hand, if the builtin is "weakly builtin", an ambiguous call will invoke the subroutine of the same name instead. Even if these subroutines did always work as expected, it’s simply too hard to maintain code where the program-specific subroutines and the language’s keywords overlap: sub crypt { return "You're in the tomb of @_\n" } sub map { return "You have found a map of @_\n" } sub chop { return "You have chopped @_\n" } sub close { return "The @_ is now closed\n" } sub hex { return "A hex has been cast on @_\n" } print crypt( qw( Vlad Tsepes ) ); # Subroutine or builtin? for my $reward (qw( treasure danger) ) { print map($reward, 'in', $location); # Subroutine or builtin? } print hex('the Demon'); # Subroutine or builtin? print chop('the Demon'); # Subroutine or builtin? Average Rating:
![]() Rating: - Detoxing Perl - A must for anyone who writes longer Perl scriptsThe Perl motto "there's more than one way to do it" comes to bite you as you start to write longer and longer codes. Other people's Perl "codes" are often totally intractable and my scripts were probably even worse... Where does it all go wrong? Most of us who "code" in Perl started off writing short scripts to do simple tasks and it just grew - still looking like scripts but longer, meaner and weirder. The Best Practices starts off with formatting. Seemingly trivial but it really makes ... Read More Rating: - No Perl bookshelf should be without it...I have to agree with the previous reviewers that this book will seriously change the way you code Perl. Having read this you will write more readable, more maintainable, more thoughtful, better documented (and better self-documenting) code... and this in addition to learning techniques to simply writing *better* code. Use the downloadable files to amend your Emacs/Vim config to the PBP way, and run all your pre-release code through perltidy and Perl::Critic (using the PBP theme) and you ... Read More Rating: - Best Perl book everNot only the best Perl book I've ever read, it's also one of the best programming language books, period. If you've ever programmed C++ or Java, you'll know how revered the likes of Effective C++ and Effective Java are, a series of tips, suggestions, idioms, advice and commandments. This is the equivalent for Perl, except it's even more thorough and covers even more ground, from brace layout and statement formatting, to regexes, unit testing, documentation and command line parsing. Read More Rating: - WowI have been programming computers for the last 22 years. I loved Perl from the moment I set eyes on it. After I receiving my copy of Damian Conway's new book I love Perl even more. Browse for similar items by category:
|
|
||||||||||||||||||||||||||||
|
Featured Puzzle Related Books:
Electronics
SOFTWARE
Puzzle Toys
Featured Products:
Electronic Sudoku
Featured Computing Books:
Computers and Internet
Computer Peripherals
Electronics
All Electronics
Software
Software
Video Games
Video Games
|
||||||||||||||||||||||||||||||
|
Please visit our sponsors:
|
||||||||||||||||||||||||||||||
|
| Amazon Products Feed script by MrRat : Premium APF Mods from Dean Marshall : Open source APF Mods from APFMods.com |