Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: No Hard Tabs in Code

by SuicideJunkie (Vicar)
on Jul 06, 2010 at 14:44 UTC ( #848229=note: print w/replies, xml ) Need Help??

in reply to No Hard Tabs in Code

8 is a paragraph comment introducing 9..10. Therefore it is indented equally. 9 is the match of a filtering rule. 10 is the replacement, therefore an extra space is inserted to align left delimiters; which is still indentation.

Why would you refuse to distinguish between indentation and alignment even when you know what they are?.

To put it simply, you indent blocks of code, and you align symbols (such as delimiters). If it doesn't matter whether it is 2,3,4,6 or 8 spaces, then it is indentation. If it has to be exactly N spaces then it is alignment.

#indent (arbitrary distance) #\/ \/ while (... or ...) #/\ /|\ /\ #indent alignment (distance must be exactly length("while ("))

If in doubt, run Perltidy with the -i=0 option. It will still add spaces for alignment, but not for indenting.

Replies are listed 'Best First'.
Re^2: No Hard Tabs in Code
by Xiong (Hermit) on Jul 06, 2010 at 15:09 UTC

    I deliberately treat all horizontal whitespace alike today. Spaces only.

    It's just as well I don't make the distinction. If I did, I'd have to quibble with your definition. But I don't. "One char to rule them all."

    - the lyf so short, the craft so long to lerne -

      I fail to see what is so difficult about that definition. Indentation is logical spacing. Alignment is the visual spacing.

      TidyPerl knows the difference as shown above.

      Or, to use a heretical example, Python forces you to use only indentation, and forbids alignment.

      I don't think it gets much simpler than saying "The stuff you like to be 2 spaces wide but the guy sitting next to you likes to be 4 spaces wide". That's the indentation.

        Or, to use a heretical example, Python forces you to use only indentation, and forbids alignment.

        Python forces you to indent consistently but does not mandate what consistency is required (it's possible to mix tabs and spaces, but that's unfortunate).

        Python does not mandate alignment (though there is common practice - see PEP8), and if you wanted to format a Python dict like a (standard) Perl hash with keys, colons, and values each aligned, you could. You could also put the closing brace wherever you wanted: end of line, start of next line, indented, matching the opening brace... Same goes for method parameters - the "def" has to be at the correct indentation, but everything after that is freely alignable. If you wanted to align open parentheses of every method, align parameters one below another, and close the parentheses 4 spaces in, you can. etc etc etc.

        It is possible to write any program in perfectly legal, if unpleasant, python where only a single character has forced indentation, and everything else can be freely aligned. (It's also possible to write any program with a total of 2 keywords and no other letters, numbers, or hardcoded strings, but that's considered impolite)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://848229]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-10-23 07:24 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (87 votes). Check out past polls.