Author Topic: code formatting  (Read 2598 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
code formatting
« on: August 08, 2010, 09:54:46 PM »
(*#@%&()*@#$&(*@#&$(*&@#$ !!!!

I hate poorly formatted code.  This is why I hate taking over for other developers.  I waste a bunch of time formatting code to make it readable so I can understand it.

Call me crazy, but this is how I format
Code: [Select]
if($i == 1)
{
     // junk - tabbed (tab = 4 spaces)
     // junk - tabbed (tab = 4 spaces)
}
That indent happens again if another if/for/etc. block happens within the if.

I also don't use braces if there is only one line to execute.  It's a fucking waste.

The only excuse for not using the above formatting, IMHO, is if you're coding over SSH directly on the server in a crappy editor.

Anyone else with me??

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: code formatting
« Reply #1 on: August 08, 2010, 11:31:00 PM »
for the most part I agree.

that said, I like putting my starting bracket on the same line as the if statement:
Code: [Select]
if($i == 1){
    // do some stuff
}

also, while I understand the convience of not using brackets when only executing one line, I like to still use them for the sake of uniformety and to keep from any confusion - especially if I eventually may need to add another line to execute.  But again, i put it all on one line:
Code: [Select]
if($i == 1){ $do_some_stuff = here; }
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: code formatting
« Reply #2 on: August 08, 2010, 11:37:28 PM »
(*#@%&()*@#$&(*@#&$(*&@#$ !!!!

I hate poorly formatted code.  This is why I hate taking over for other developers.  I waste a bunch of time formatting code to make it readable so I can understand it.
I recently found the joys of netbeans reformatting option.  It is hell on revision control diffing though.

Quote
Call me crazy, but this is how I format
Code: [Select]
if($i == 1)
{
     // junk - tabbed (tab = 4 spaces)
     // junk - tabbed (tab = 4 spaces)
}
That indent happens again if another if/for/etc. block happens within the if.
For compiled languages and Java I do tab = spaces.  For PHP I leave tabs and tabs.  No sense in making the files bigger than they need to be in (within reason).
Quote
I also don't use braces if there is only one line to execute.  It's a fucking waste.
Yes/no.  It kinda depends on whether or not I think they'll ever be a need to add second statement.  This is important when the code changes are done via any automated process and especially if more than one code change is expected.  For balance purposes a one line else will get brackets if the if did.
Quote
The only excuse for not using the above formatting, IMHO, is if you're coding over SSH directly on the server in a crappy editor.

Anyone else with me??
For the most part :D

I've been using closure in PHP 5.3 and that has thrown me some interesting formatting issues.  Especially when the closure is an element in a multidimensional array.

PJYelton

  • Power of Voodoo
  • Jackass In Charge
  • Posts: 1597
  • Karma: +56/-12
    • TheRecursiveFractal
Re: code formatting
« Reply #3 on: August 08, 2010, 11:47:09 PM »
My coding style is like Micah's.  We recently had to completely reformat thousands of lines of code written by a team of developer out in Vietnam that we fired.  No comments, no consistency, random uses of bit operators for no reason, that was fun...

charlie

  • Jackass In Charge
  • Posts: 7903
  • Karma: +84/-53
Re: code formatting
« Reply #4 on: August 09, 2010, 03:49:12 PM »
I only do C++ and my code is like ober's. Our codeline has been around for almost 15 years and at least 15 developers now, so it's pretty damn messy. Plus there's the fact that I'm super anal about doing it "right" so my code stands out from the rest which probably makes the situation worse.

But anyway, I agree. I can handle minor changes like micah/PJ use, but anything more significant is super annoying.

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: code formatting
« Reply #5 on: August 09, 2010, 07:26:18 PM »
In C++ I used to do the same as ober, but with tab = 2 spaces (4 always seemed unnecessary to me)

I've been writing in Igor recently, and it sucks because you have to do:
Code: [Select]
if (expr)
  //endif
endif
So even one line if statements require a stupid "endif"! It's maddening because it seems like Igor's syntax is based strongly on C, but they felt they needed to change it up a bit to have their own language. And there are no multiline comments (wtf!)

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: code formatting
« Reply #6 on: August 20, 2010, 12:30:55 AM »
Multiline comments are a necessity. Then again, Python and a lot of scripting languages don't

The Django Templating Language (OK, so it's not a *real* language) annoys me because it has that same "endif"yness.

Also, no elseif :(

Code: [Select]
{% if not fuck %}
    :(
{% else %}
     {% ifeqaul fuck "me" %}
           OK!
      {% else %}
               {% ifequal fuck "you" %}
                      You too, buddy!
                {% endifequal %}
     {% endifequal %}
{% endif %}