Mr. Conway disagrees with some of my college professors again. He says that it is not useful to abuse loop constructs just to consolidate control in a single location. He is a hero for this stance. Read the rest of this entry »
PBP: 082 Distributed Control
February 16th, 2015PBP: 081 Linear Coding
February 12th, 2015This suggestion seems oddly worded to me, although I’m not sure I can think of a better one. The book says, “Reject as many iterations as possible, as early as possible.” Luckily, it goes on to explain what this means, as that isn’t – at least to me – terribly clear. It winds up being an extension of “coding in paragraphs” and is more about how to organize your code than how to format it. I think I agree with this and do it all the time, despite having had many college professors claim it is the root of all evil. Read the rest of this entry »
PBP: 080 do-while Loops
February 9th, 2015This suggestion from the PBP is simple: Don’t use do … while loops. The reasoning is good and readable alternatives are provided. I wind up having no trouble with this suggestion, although I wasn’t as happy with it when I first read it. Read the rest of this entry »
PBP: 079 Tabular Ternaries
January 29th, 2015Mr. Conway suggests that you can cascade uses of the ternary (?:) operator instead of an if-elsif-else chain. He feels this is much more readable. I strongly disagree. Read the rest of this entry »
PBP: 078 Value Switches
January 26th, 2015The idea behind this Best Practice is to explain how a table lookup can be used instead of an if/elsif/elsif/elsif/elsif/else block to make selections from a set of constants. This is almost always a good choice! Read the rest of this entry »
PBP: 077 Multipart Selections
January 22nd, 2015The PBP say “Avoid cascading an if.” At first glance, this sounds like a pretty harsh suggestion. As it turns out, I rarely ever have any issue following this suggestion. Well organized code seems not to need long if/elsif/elsif/elsif/elsif/else blocks. Read the rest of this entry »
PBP: 076 List Processing Side Effects
January 19th, 2015Mr. Conway suggests the very firm, “Never modify $_ in a list function.” I’m torn on this. Read the rest of this entry »
PBP: 075 Complex Mappings
January 15th, 2015The PBP suggests we factor complex map blocks into subroutines. Please, please do this! Read the rest of this entry »
PBP: 074 List Transformation
January 12th, 2015The last Best Practice suggested using map instead of a for loop to process lists. There is an exception suggested by the Best Practices; if you’re transforming a list in place, use a for loop. Read the rest of this entry »
PBP: 073 List Selections
January 8th, 2015The Best Practice is to use grep and first instead of for to refine or search lists. Again, there are good reasons, but I find it difficult, and am only improving with deliberate practice. Read the rest of this entry »