in reply to Code style question

I haven't looked seriously at your code. But this question: P.S. So what's the right indent: 2 or 4? is clear. The answer from multiple papers is 3. That gives a slight advantage over 2. 4 causes problems with lines becoming too long without increasing readability over 3. I am sure that my statement will be controversial. If 2 or 4 are the only options, then use 2.

Replies are listed 'Best First'.
Re^2: Code style question
by VinsWorldcom (Prior) on May 20, 2021 at 19:39 UTC

    "Then shalt thou indent to three, no more, no less. Three shall be the number thou shalt indent, and the number of the indenting shall be three. Four shalt thou not indent, neither indent thou two, excepting that thou then proceed to three. Five is right out!"

      This will be a great start for the book!



        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        "Five is Tabs are right out!

Re^2: Code style question
by ikegami (Pope) on May 20, 2021 at 15:57 UTC

    Really? I thought I was the only using that! Back in the Turbo Pascal days, indents levels were all over the place, and I settled on 3 for exactly the reasons you mentioned. Been using it ever since.

    Seeking work! You can reach me at

      Wow, Turbo Pascal! That brings back memories...

      I hired a guy to write a test program for me. Running 24 hours per day, it took about 5 days to reach a result.
      I knew that the problem lay in a buffer compare routine.
      I had the guy rework the code such that this was a sub which "touched" all the vars that I needed.
      I took the floppy back to my office and hacked in the binary code for the new "string" operations that Intel had for the 80186. Cut the execution time down to about 8 hours.

      PS: I still have a pre-production 6 Mhz IBM PC with a 5MB Quantum hard card. Free to anybody who wants it. Production models were 8 Mhz. This thing boots and works, even has Lotus 123 on it!

      This 3 has very solid evidence in CS studies. And for the reasons that we both agree upon.
Re^2: Code style question
by 1nickt (Abbot) on May 21, 2021 at 09:56 UTC

    Indents are four spaces ;-) ... but I note that Cpanel::JSON::XS uses three spaces by default in pretty-printing JSON. (I override it, lol...)

    The way forward always starts with a minimal test.
Re^2: Code style question
by AlexP (Beadle) on May 21, 2021 at 07:29 UTC

    Also (2+4)/2 is 3. Looks nice.