Skip to content

Commit

Permalink
coding_style: Document each's evilness
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Sep 6, 2024
1 parent 9d70b58 commit afed854
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions _development/coding_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ And the bad example:
my $circle_area = $radio * 3.14159 * 3.141592;
```

### Don't use each

`each` is evil, and although it can be used correctly, should be avoided at all costs.

The problem is that each sort-of remembers the last element it iterated over, this has all sorts of nasty side effects.

Use `foreach` to iterate over `keys` instead.

Bad example:

```perl
while (my ($k, $v) = each(%h)) {
...
}
```

Good example:

```perl
foreach my $k (keys %h) {
my $v = $h{$k};
...
}
```

### Module header

A Perl module **must** start with a line like:
Expand Down

0 comments on commit afed854

Please sign in to comment.