Re: Catching typos
by haukex (Archbishop) on Jan 06, 2021 at 17:58 UTC
|
I like the others' suggestions of Perl::Critic (which at least warns that "Subroutine "foo" does not end with "return"") and no indirect, the former of which I use for my modules. I just wanted to add another point that hasn't been mentioned yet: having a test suite with good code coverage (Devel::Cover) helps too; almost all of my CPAN modules have 100% code coverage. Though that's not a guarantee that everything is caught, it at least checks that each line of code is executed at least once, which would hopefully have helped in this particular situation.
| [reply] [d/l] [select] |
Re: Catching typos
by hippo (Archbishop) on Jan 06, 2021 at 16:49 UTC
|
Nothing catched this, obviously perl -cw myModule.pm didn't
A quick test on the commandline shows that this is treated as indirect object notation which perlcritic should pick up on. Perhaps that's one way to go.
Did your test suite not raise failures?
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
|
|
|
|
d:\tmp\pm>perl -MO=Deparse -e "reeturn $self->someMethod()"
$self->reeturn->someMethod;
-e syntax OK
d:\tmp\pm>
Obfuscators would party now... ;-)
wait ... look at this:
d:\tmp\pm>perl -MO=Deparse -e "A B C D"
'B'->A('D'->C);
-e syntax OK
d:\tmp\pm>
Forget the lockdowns and lets meet for 99 beers ... xD
| [reply] [d/l] [select] |
Re: Catching typos
by GrandFather (Saint) on Jan 07, 2021 at 04:04 UTC
|
The problem isn't finding this specific error again because the chance that it will happen and not be caught by you is now pretty small. The better question is "how do I catch silly error in my code before publishing it?" and the answer is: code coverage and tests.
Devel::Cover is the go to for code coverage. Test is a starting point for writing a test framework, although the testing support for Perl is vast.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] |
Re: Catching typos
by stevieb (Canon) on Jan 06, 2021 at 16:51 UTC
|
hippo quickly came up with at least one possible reason. Any half decent editor or IDE would catch this typo and at least warn about it.
I can't even think of an instance where that would fly, unless you've declared a reeturn() sub.
In what context is this used in?
| [reply] [d/l] |
|
|
> Any half decent editor or IDE would catch this typo and at least warn about it.
Really? Most IDE depend on running perl -c for checks.
Emacs syntax highlighting and indentation help me in similar cases , but that's not a warning. ..
| [reply] [d/l] |
|
|
My IDE highlights the word in yellow (warning), and hovering over it produces the following pop-up: Unable to find sub definition, declaration, constant definition or typeglob aliasing. It also throws a yellow dot at the line where the warning is located, so even if that line isn't in view on the screen, I can always see if there are any warnings/errors anywhere within the file at a glance. Everything happens live-time, so I can actually see it immediately after I'm done typing.
Here's an image of what I'm speaking of. If I point at the word, the notice pops up.
| [reply] [d/l] |
|
|
|
|
|
Re: Catching typos
by Bod (Parson) on Jan 06, 2021 at 22:21 UTC
|
| [reply] |