in reply to On Testing and Formatting Code

It is a rare thing when I don't test code I post, usually only trivial stuff gets past the "I should test that" filter.

More importantly, I try and benchmark things against other answers. I always wanna know why/how things work so one day when it does matter that I did it the fast way, my instincts will lead me down the mostly-right path =)

As to formatting, I like compressed code, so I tend to hang the open braces on the main line and indent body only. I ALWAYS use tabs IRL and tend to have my vim set to 3space tabs.

Spacing brackets and parens is becoming a habit as well, I pad inside and out of brackets, braces, and parens that block code, enclose arguments, or create arrays/lists. Never spaces on array brackets or hash keys. Space on both sides of assignments and math is generally a must, excepting a few degenerate cases like $a+0 and the like.

Vertical whitespace is for separating logical blocks of code, especially in long linear sections.

--
$you = new YOU;
honk() if $you->love(perl)

Replies are listed 'Best First'.
RE (tilly) 2: On Testing and Formatting Code
by tilly (Archbishop) on Oct 05, 2000 at 06:53 UTC
    Were you working closely with me I would be unhappy about the non-standard tab-stop.

    I leave editors at the default 8 spaces. Your code would probably not display nicely for me in 80 columns and I would request that you change your settings to make sure your tabs become spaces in the file. I don't care what happens on your screen when you hit tab. I do care that the output is readable for me, prints properly, etc. And since others use editors with 8-space tab-stops, I am not going to be sympathetic to changing to match what you are doing...

    Oh, and the first time you open and touch some Python code? You will turn it into a complete and utter mess! Seriously, Python uses indenting for its logical structure, and non-standard tabstops can result in your not being able to read it, and then it's not being able to read it either after you make a trivial edit and spaces are converted to tabs (or vica versa)!

      No, you read that wrong. My editor leaves tabs as tabs. In code I write for work I NEVER EVER use spaces. I set my EDITOR to use 3 space representation. Most people here leave theirs set to 4 or 8. But they are free to use what ever they like. My Python code works great. Every tab is a level and it prints beautifully, compact and clean. Better still, since it's all tabs, any goofus who wants can smash tabs to 8 spaces and further fsck it up at will.

      The porpoise of the odd fish "tab" is to indent, with flexibility of representation. That it is abused into spacing to ($col + 8 - ($col % 8)) is just a shame.

      Rewriting you last paragraph (no offence here I'm trying not to devolve into ad hominem attacks) :
      Oh, and the first time you open and touch some Fortran code? You will turn it into a complete and utter mess! Seriously, Fortran uses indenting for its logical structure, and non-standard tabstops can result in your not being able to compile it, and then it's not being able to read it either after you make a trivial edit and spaces are converted to tabs (or vise-versa)!

      So what? We weren't talking python here and why should I care if my Perl habits might cause me trouble editing Python? You don't see me decrying your Perl habits inflicting woe upon your writing paragraphs of off topic-ness. Why not? Because you don't blindly type a "$" or "@" in front of every noun and tell people to precede their documents with "use grammar;". I, and you clearly, are able to keep more than one way of formatting and describing information straight. Please don't mis-read what I say " I ALWAYS use tabs IRL and tend to have my vim set to 3space tabs." and then call me ignorant to my face.

      Sorry if this came off too heated tilly. I didn't mean it to insult you but who are you to chide me? Especially with the specious "wait till you hit Python" argument.

      --
      $you = new YOU;
      honk() if $you->love(perl)