I have a lot of Perl code. At work we have a lot of Perl code. I had to come up with a standard Perl style. It's not important that this is the best Perl style ever - instead it's important that this Perl style is good enough and this is the one I use with all my CPAN modules. I use Perltidy to reformat Perl code using the following
-l=78 # max line width is 78 cols
-i=4 # indent level 4 cols
-ci=4 # continuation indent 4 cols
-st # output to STDOUT
-se # errors to STDERR
-vt=2 # maximal vertical tightness
-cti=0 # no extra indentation for closing brackets
-pt=1 # medium parenthesis tightness
-bt=1 # medium brace tightness
-sbt=1 # medium square bracket tightness
-bbt=1 # medium block brace tightness
-nsfs # no space before semicolons
-nolq # don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -=/= |= >>= ||= .= %= ^= x=" # break before operators
-ce # cuddled elses
You may use this too. Or pick your own. If you send patches to my modules, I'll run Perltidy on it and all the code will have the same style
with a dash of critic (Score:1)
perltidy is sanctioned babel (Score:1)
If
I just ( you know , like this )
format my English text in any old way,it
gets awfully hard to read.There are standard grammatical conventions for written text,yet we try to reinvent them for programming
. See how silly it is to break before the operator
?And what's the deal with braces being non-tight
? ( I mean, we don't have space after an opening paren ( and
Re: (Score:1)
For example, based on your post you should not break before operators. However if you read Perl Best Practices, you'll find some excellent reasons given for why you should break before operators. Basically they have to do with how our eyes move when we skim through c
Re: (Score:1)
Exactly. Like I said: babel. The conflict comes from the subtle differences.
I would rather than the debate be based in reason than religion (call it semantics, but "religious debate" is, by definition, a contradiction of terms.)
Given one internally consistent system, which i
Re: (Score:1)
Actually it is not a contradiction of terms. It is a description.
Debates happen. Both sides bring arguments to bear, and argue. But people wind up arguing past each other, and after a while it becomes apparent that the answers are hugely important to people, but they cannot logically justify that importance.
Because this is so reminiscent of debates over r
Re: (Score:1)
In French, it's conventional to put a space before the question mark -- like this ? They also don't seem to indent new paragraphs. ¡In Spanish, they mark exclamations at the front too! In Czech, we can see, that they put commas before "that" when the independent clause comes first (as in this sentence, so "we can see" isn't parenthetical). In German, they capitalize Nouns and some
Re: (Score:1)
Though you could probably argue that those languages are consistent "internally", so picking a format for Perl would only be equivalent to picking it for one of those languages.
Yes. And Perl is (quite arguably (on many levels)) linguistically based in English.
Maybe programming languages each need a few hundred years to settle on formatting conventions.
Maybe, but please name some French/ Spanish/ German/ Czech programming languages.
(So I was trying to put one "phrase" per line, with continuations indented by one space.) They end up looking almost like poems, which I think makes them too flippant.
Poems yes, but "poem" does not imply "flippant". Poetry has been quite influential throughout history (though we forget that thanks to technological advances like "fox news".) Poems are memorable because of the rhyme (or non-rhyme), beat, linebreaks, syntactical twists, etc. It's not much different than distending an array/hash decl
Re: perltidy is sanctioned babel (Score:1)
Maybe, but please name some French/ Spanish/ German/ Czech programming languages.
Rasmus Lerdorf (Denmark) designed PHP.
Bjarne Stroustrup (Denmark) designed C++.
Guido van Rossum (Netherlands) designed Python.
Yukihiro Matsumoto (Japan) designed Ruby.
Niklaus Wirth (Switzerland, german part) designed ALGOL, Pascal, Modula.
Jean David Ichbiah (France) designed Ada.
The Ericsson company (Sweden) designed Erlang.
French professors designed Prolog.
Norwegian professors designed Simula.
INRIA (France) designs OCAML.
etc, etc.
I could go through the thousands of programming languages listed
Close the world. txEn eht nepO
Here's mine (Score:1)
--check-syntax # Ask perl to check the syntax of the file
--backup-and-modify-in-place # Dont output to another file
--backup-file-extension=.tdy.bak # Backup.pl.tdy.bak
--logfile # Save a log of what's going on
# Formatting
--output-line-ending=unix
--format-skipping
Wow!! (Score:1)
Did anyone ever tell you that you have too much time on your hands?
Re: (Score:1)
if you want some here's a list of my must have (they're in
-
-
-
-
-
-
-
-
-
-
-
Re: (Score:1)
yep. I am. Thanks
Re: (Score:1)
I just ask for the delay to clean up my config directory, it's a real mess in there and i don't have the time to sort everything right now.
Re: (Score:1)
Take your time. I asked because I was curious to see how people organize their things. Lately I seem to waste time in simple yet important tasks with a net result of less time to code :(. Having a working (and portable) set of config files is certainly an asset.
cheers --stephanRe: perltidy (Score:1)
You could shorten this by invoking all of the Perl Best Practice options using -pbp or --perl-best-practices.
John.
--
Missing wbb options (Score:2)
One difference is that we have "!~ >= = | & = **= += *= &= >= ||=
(didn't care to figure out the differences, sorry
A few other options we use:
--maximum-line-length=100 # be slightly more generous
--warning-output # Show warnings
--maximum-consecutive-blank-lines=2 # default is 1
--nohanging-side-comments # troublesome for
-- ask bjoern hansen [askbjoernhansen.com], !try; do();