in reply to Code style question

So what's the right indent: 2 or 4?

A principle you often see mentioned in a Perl context is TIMTOWTDI (pronounced "tim toady"), short for There Is More Than One Way To Do It. I think some take it too far on occasion, using it to justify alternates which are objectively meritless, while I believe it means 1) one should be tolerant of differences and maybe even learn from them, and 2) adjust to what's best based on context.

With that in mind, anything that might be claiming to be an official style guide is merely making suggestions. So while your answer is inherently unanswerable, I'll leave you with the following:

From what I've seen, 4-space indents is by far the most common indent used, so I recommend that you use this. You will also come across 4-position tabs and 2-space indents pretty often. I use something I haven't see anyone else use (for somewhat historical reasons), so I won't mention it.

There is one "rule": Be respectful of the conventions of projects to which you collaborate.

Seeking work! You can reach me at

Replies are listed 'Best First'.
Re^2: Code style question
by Marshall (Canon) on May 20, 2021 at 16:20 UTC
    Indenting style is just that, indenting style. There is no official answer to this indentation question. I have a preference for 3. That doesn't mean that 2 or 4 is "wrong".

      Yes it is wrong. Wait . . . I'm sorry, was this just the five minute argument or the full half hour? :)

      Edit: 98% an unserious comment solely to make the Python (Monty) reference.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Hah! Whitespace and well written comments are some of the most important things in code. In my code, when the "subject/purpose" changes, I add a blank line. That blank line is important and it is there for a reason! The compiler doesn't care, but the humans do care!
Re^2: Code style question
by AlexP (Beadle) on May 21, 2021 at 07:16 UTC

    Thanks for your reply.

    TIMTOWTDI is one of the things that attracts me, but for perl neofit it could be quite complex to start without accurate information.

    Hope this node will be useful not only for me.