メインスクリプトといくつかのサブルーチンがインターリーブされた1つのperlスクリプトを入手しました。次のようになります。
sub utils1 {
...
}
# some code
# some more code that calls utils1
sub utils2 {
...
}
# some code that calls utils2
sub utils3 {
...
}
# some code that calls utils3
# the rest of code
コードを整理するためのより良い方法はありますか?良いコーディング規約を探しています。私のPythonコーディングの経験に基づいて、私は以下のようなことを考えています。それはどのように見えますか?
sub utils1 {
...
}
sub utils2 {
...
}
sub utils3 {
...
}
sub main {
# some code
# some more code that calls utils1
# some code that calls utils2
# some code that calls utils3
# the rest of code
}
&main();
私の知る限り、サブルーチンの編成について定義されたベストプラクティスはありません。私の経験から、ドキュメントはしばしば順序を指示します。
例えば
use Getopt::Lucid;
=head1 SYNOPSIS
This program does nothing so long ...
=cut
# ... main code here, not necessary to wrap into a sub
=head1 PUBLIC METHODS
=cut
sub method1 {
=head2 method1
This method does something ...
=cut
$self = shift;
# ...
}
sub method2 {
=head2 method2
This method does something different...
=cut
$self = shift;
# ...
}
=head1 PRIVATE METHODS
These methods are private their interface may change.
=cut
sub _priv1 {
=head2 _priv1
The _priv1 method is for ... and used by ....
=cut
my $self = shift;
# ...
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加