Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Code style question

by Marshall (Canon)
on May 20, 2021 at 15:43 UTC ( #11132780=note: print w/replies, xml ) Need Help??


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!

        Original

        Alexander

        --
        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 ikegami@adaelis.com

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-08-06 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?