"Style"

What is good coding style

Page 1 of 1

8 Replies - 1407 Views - Last Post: 04 May 2008 - 07:34 PM

#1 jediokie  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 215
  • Joined: 07-February 08

"Style"

Posted 01 May 2008 - 10:31 PM

So I just finished Programming I at school (made 101% if you're intrested), and the biggest complaint my teacher had was about my coding 'style.' Nothing really specific got mentioned just overall. So that made me wonder what is good coding style?
Is This A Good Question/Topic? 0
  • +

Replies To: "Style"

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5354
  • View blog
  • Posts: 27,312
  • Joined: 10-May 07

Re: "Style"

Posted 01 May 2008 - 10:47 PM

I'm not sure if this is considered "style", but I prefer to indent correctly & comment whenever common sense says I should. It makes it easier for #2pencil (or anyone else) 2 years from now that might need to work on the code again, to actually be able to read the code.

If you have sloppy code, it makes reading your code much much harder.
Was This Post Helpful? 0
  • +
  • -

#3 mikeblas  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Re: "Style"

Posted 01 May 2008 - 11:40 PM

You should ask your instructor. They've actually seen your code, and can explain what they meant specifically.

For me, good coding style largely means fitting in with the team. You do things that help the team, you don't assert your way over the team's way, and so on. Sure, there's room to suggest things to help the team out, but by fitting in, you help others help the product.
Was This Post Helpful? 0
  • +
  • -

#4 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: "Style"

Posted 02 May 2008 - 03:06 AM

i just find indenting the code and giving each part a title (by comment) so that later on if i have to do anything to it, it is easy to find what i am looking for.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5848
  • View blog
  • Posts: 12,707
  • Joined: 16-October 07

Re: "Style"

Posted 02 May 2008 - 04:10 AM

Everyone has an opinion of which styles are best, but good programming style is universal: consistency. Everything must be consistent. If it's consistent you can tell whats happening from one point to the next, even if you don't like the style the programmer uses. Another element that's considered universally good; variable names that mean something.

As no2pencil noted, what's fresh and obvious today won't be in the passage of time. If you program so others can at least follow along it will help you greatly when you haven't looked at it for so long that you're the other.
Was This Post Helpful? 1
  • +
  • -

#6 JasonMcAuley  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 144
  • Joined: 10-April 08

Re: "Style"

Posted 03 May 2008 - 07:44 AM

Just keeping your code well organized; easy to follow; well documented/commented. What is considered good "style" can really depend on the person though.
Was This Post Helpful? 0
  • +
  • -

#7 mikeblas  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Re: "Style"

Posted 03 May 2008 - 09:37 AM

View PostJasonMcAuley, on 3 May, 2008 - 07:44 AM, said:

What is considered good "style" can really depend on the person though.
Indeed, after a certain point, it's very much arbitrary. Most of the teams I've been on which have had long discussions about style have had much more serious problems that should have been attended to long before the matter of style came up.
Was This Post Helpful? 0
  • +
  • -

#8 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: "Style"

Posted 04 May 2008 - 02:23 PM

I agree that style is arbitrary, though my interpretation of good style is code that is as concise as possible and as easy to follow as possible. This can include how you go about solving your problems presented, comments, structure, identifiers, indentation, anything.

Second on no2pencil, if i didn't comment and indent, i couldn't understand my code 2 hours from now (no joke).

BTW: My style sucks, kudos for you (not literally)

PS: for those of you who have seen any of my questions, you see my impossible to follow logic (w/o comments, i can't follow my own logic). Man i'm jealous.

This post has been edited by polymath: 04 May 2008 - 02:24 PM

Was This Post Helpful? 0
  • +
  • -

#9 mikeblas  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Re: "Style"

Posted 04 May 2008 - 07:34 PM

View Postpolymath, on 4 May, 2008 - 02:23 PM, said:

I agree that style is arbitrary, though my interpretation of good style is code that is as concise as possible and as easy to follow as possible. This can include how you go about solving your problems presented, comments, structure, identifiers, indentation, anything.
I guess that's where I disagree. Style is not implementation; implementation includes how the problem is solved. Style involves formatting, naming, and so on. It's prefectly arbitrary.

Some teams try to enforce implementation requirements; using anonymous global namespaces instead of statics, for instance; or using exceptions or not. these vague admonitions generally have reasons based on some requirements of the architecture. For example, the memory manager can't handle exceptions, or an analysis tool gets sick when there are too many static variables.

Beyond that, I've never worked on a team that did any real enforcement for implementation rationale. It would be an interesting experiment--it would seem like it wouldn't result in any productivity gain, though, does it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1