What is your coding style?

Prosaic. With comments that answer "why?" more than "what?" or "how?". I want a person, upon first exposure to the source code, to be able to understand the idea of it - much like reading a book, instead of reading program source code.
 
Programming potpourri

I've been immersed into different programming cultures over the years... and when I've been particularly impressed with a style, I morphed it into the whole. I did this when I saw what I liked, and eventually smooshed all those different templates of approach into something I think is uniquely my own.
 
kpedersen said:
The code I write on Wednesday is pretty good. The rest of the time it's crap.

Huh, sounds like a case of the Wednesdays?:\
 
In one word, practical. I'm not one to do massive re-writes of existing code to improve its modularity or style. Once code works, I like to leave it alone. I'm also cautious. A lot of my work is bug-fixes and I try to avoid making big changes, preferring small tweaks where possible. I also prefer commenting out code to deleting it.
 
6a0120a85dcdae970b012877707a45970c-pi
 
Code:
# intro comment of module
class something
begin
  # description of locals
  # <-- Note there are only 2 spaces per indent level
  # all privates start with "my" or "my_"
  myLocal as whatever
  # all protected/shared start with "our" or "our_"
  ourShared as whatever
  # all globals are just a label
  globalVar as whatever
  
  method something as void
  begin
    # describe what is being attempted which ultimately is really only a guideline
    do somestuff
    do some more stuff
    # describe why what you're doing here doesn't match with the method description
    do contrary stuff
    do some more stuff that probably makes some sense
  end
end

...
I also tend to prototype everything I write in pseudo-code to avoid the overhead of "crappy" looking code. It doesn't always work once I get started but I don't like leaving it to chance.
 
Carpetsmoker said:
I always try to write my code in a way that's good for my job security.

And that is why people like me are tormented with coding style guides with more than 130 pages, defining which i to dot how and what not... All that, when K&R is the first and last word in styles.

Ok, I deviate from it when I need to, but I do not see any reason to be too detailed about the style. As long as I can read it, and others can understand it, it's OK by me.
 
Back
Top