One of my pet peeves is pointless temporary variables, they often just clutter things up. Consider this example (pulled from production code) that is crying out for some refactoring.
my $keywords;
@$keywords = split ' ', $something;
foreach my $word (@$keywords) {
#...
}
vs.
foreach my $word (split ' ', $something) {
#...
}
Isn't this much easier to understand?
maybe... (Score:1)
I've split up operations sometimes, placing an intermediary step in between, to facilitate debugging.
Just a thought.
Re:maybe... (Score:2)
@$keywordsinstead of plain old@keywords? What's the point of the reference?Re:maybe... (Score:1)
Depends on who's reading it (Score:1)
Re:Depends on who's reading it (Score:2)
?
Furthermore, ?!
Re:Depends on who's reading it (Score:2)
I don't buy the theory that code should be readable by an average programmer. I code so that a competent programmer can understand it.
Temp variables == clarity... sometimes. (Score:2)
Folks advocate well named temp variables for clarity, similar to well named functions. Its not obvious from glancing at just a split that you're getting a list of keywords. It is obvious from "my @keywords = split ...". However, "foreach my $keyword (split ...)" works just as well.
I have seen this concept abused.
Other times folks start out with the long hand version using temp variables
Re:Temp variables == clarity... sometimes. (Score:2)
Whilst I try to avoid extra variables where I can, I'm not fastidious about it. I will frequently use an extra one if it stops the code leaking over 80 columns...
-Dom
Re:Temp variables == clarity... sometimes. (Score:2)
Re:Temp variables == clarity... sometimes. (Score:2)
I know it's not fashionable to print code, but sometimes it's easier to take away and read.
-Dom