very nice read and thread my friend!
My coding style changed a lot because Perl was and still is my only programming language and I started horribly :)
Notably:
- I switched from &my_sub(..) to my_sub(..) where I used & to highlight my own subs defined in the current program. I was bored to receive perl4 accusation :) and "you should be aware of.." YES I'M AWARE! :)
- in quick hacks (I still do a lot of quickies) I just like to have decent style
- probably biggest change was not in style but in preparation: if I plan something that can be a module then I think about it more hours than before before coding, trying to highlight eventual critical points before coding. I have been burned by my own Game::Term where I missed completely the right implementation of my idea and now I have no more will to rewrite it..
- if a module, then I write tests, documentation and code in parallel and I use gitlab or github, with a bit of pain but rewarding effort!
- I always put POD after __DATA__
- I comment complex code but mainly for my lack of memory after a short while
- I generally put all subs at the end of the file, sometimes separated by long ##### lines
- I close braces at the indentation level where I open them, and I like spaces with parens:
foreach my $it ( @eles ){
foreach my $part ( split '|', $it ){
....;
}
}
- sometimes I align nested parens in another way, adding newlines too (see below example wher GetOptions parens follow this style, dfferently from unless parens)
- I align hashes and the alike only for my own eyes plesure and because a program should be beutiful
unless (
GetOptions (
'url=s' => \$url,
'agent=s' => \$agent,
'extraparts|cache=i' => \$cache_size,
'debug=i' => \$debug,
+
);
) { die "$0 -url URL [-agent STRING -extraparts N -debug [0-2]]" }
- I use as above short blocks in one line style.
- I put a blank line where my eyes need it, after complex blocks or deep indentation end
- I put attention to variable names, more if they spread all over the program. A speaking long name is not a problem if you have autocomplation. This can be verbose using Tk where if I have a part of the program managing Sierpinski fractals I have vars named: $input_sie $color_sie $title_sie $label_sie $hint_sie or $jpeg_quality_ent for the entry field
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.