Seij has asked for the wisdom of the Perl Monks concerning the following question:
Hello there,
I am new to Perl and I am not sure if my Coding Style is good.
Could some of you please check if my Coding Style is good or tell me what I should change to get a good Coding Style?
You can find 2 files of my current project under http://www.christophfriedrich.de/code/
Please check it so that I can write good code on bigger projects.
Thank you and greetings
Christoph
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help with Coding Style
by CountZero (Bishop) on Dec 25, 2009 at 16:46 UTC | |
Some program editors (such as Komodo) now even incorporate an "as you type" Perl::Critic check. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James | [reply] |
Re: Help with Coding Style
by erix (Prior) on Dec 25, 2009 at 16:53 UTC | |
Here is a (monastery) classic on the subject by Abigail-II: My coding guidelines | [reply] |
Re: Help with Coding Style
by ww (Archbishop) on Dec 25, 2009 at 21:33 UTC | |
Because the linked material or its address may change, making it part of your question may devalue the answers for future readers -- if-and-when they can't find the source. | [reply] |
Re: Help with Coding Style
by amir_e_a (Hermit) on Dec 25, 2009 at 19:41 UTC | |
First of all, i strongly join the people who recommended using Perl::Critic. It is an excellent to improve your style and avoid bugs. You should also use Perl::Tidy. Your naming, indentation and spacing style is mostly OK, but there are some lines which may be wrong. Among them:
Another hint: If you only use integer values in your program, consider writing `use integer' in the beginning. It may improve performance. But compare your results with and without it. Good luck! | [reply] [d/l] |
by JavaFan (Canon) on Dec 25, 2009 at 20:59 UTC | |
First of all, i strongly join the people who recommended using Perl::Critic. It is an excellent to improve your styleActually, using Perl::Critic doesn't help you to improves one style. It will however help you mimic the style of the people in charge of Perl::Critic. I loathe this kind of advice. You give two alternatives to a line, without any explanation of why any of the alternatives are better. I certainly don't see any problem with the first line than any of the alternatives solves. It's Perl. Hence, it's Perl style. Just because it looks like C doesn't mean it's bad. If it's a matter of taste, why recommend one over the other? Personally, I also look at the body when deciding what kind of loop to use. In this case, I wouldn't use a for statement at all. I suspect $self->{allowed}[0] is never used, but I didn't look at the code a lot. If it's not used, I wouldn't use the undef in the code above. | [reply] [d/l] [select] |
by CountZero (Bishop) on Dec 25, 2009 at 22:06 UTC | |
Actually, using Perl::Critic doesn't help you to improves one style. It will however help you mimic the style of the people in charge of Perl::Critic.That may be but when the guidelines of Perl::Critic are quite sensible and when there is also the possibility to edit its rules to suit your own style, I find Perl::Critic really quite helpful. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James | [reply] |
by amir_e_a (Hermit) on Dec 25, 2009 at 22:18 UTC | |
Actually, using Perl::Critic doesn't help you to improves one style. It will however help you mimic the style of the people in charge of Perl::Critic. ... Who more or less mimic the style suggested by Damian Conway. Since i started using Perl::Critic, i get from an idea to working bugless code faster. Everyone is free not to use it. I loathe this kind of advice. You give two alternatives to a line, without any explanation of why any of the alternatives are better. I certainly don't see any problem with the first line than any of the alternatives solves. Writing my ($self) = @_ is not wrong, but it may mean that the coder - who admits to being a novice - is not sure that he knows what it means. I am showing other ways to pass args, TMTOWTDI. You may loathe it, but i hope that it encourages people to read documentation. Maybe i'm wrong. | [reply] |
by BrowserUk (Patriarch) on Dec 26, 2009 at 00:38 UTC | |
by JavaFan (Canon) on Dec 25, 2009 at 23:46 UTC | |
Re: Help with Coding Style
by Khen1950fx (Canon) on Dec 25, 2009 at 22:58 UTC | |
| [reply] [d/l] [select] |
Re: Help with Coding Style
by matze77 (Friar) on Dec 26, 2009 at 10:29 UTC | |
I would not think myself as experienced enough to give well advice, what i learned so far: | [reply] |