Skip to content

Commit

Permalink
Recommend Readonly instead of constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Aug 30, 2023
1 parent 66990a1 commit 5de39df
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _development/coding_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ Here are the classic metrics for modularity:

### Don't use magic numbers

The `constant` pragma will give you meaningful names for any values other than 0 and 1 you need.
Use [`Readonly`](https://metacpan.org/pod/Readonly) to give meaningful names to any values other than `0` and `1` that you need.
They'll help you to understand why you chose such values on the past.

A good example:

```perl
use constant PI => 3.141592;
my $circle_area = $radio * PI * PI;
my $circle_area = $radio * $PI * $PI;
Readonly my $PI => 3.141592;
```

And the bad example:

```perl
# Oops! I missed a decimal somewhere!
my $circle_area = $radio * 3.14159 * 3.141592;
my $circle_area = $radio * 3.14159 * 3.141592;
```

### Module header
Expand Down

0 comments on commit 5de39df

Please sign in to comment.