general programming structure question.. order of declared variables

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I've taken the habit of declaring variables in the order in which they appear in the document during processing.

When declaring variables or processing a large set of variables in which order is not important, how do you choose to order them? As they appear? Or alphabetically?
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
Usually as they appear and as close to the use as possible.

If the variables are all at the same place/scope, then I try to group related variables together and use and empty line to signify a group.

If I really have a large group of variables that are not related in any way, I generally start to question whether I have a good structure. A mass bulk of variables USUALLY (but not always) signifies that you need to think about you design some more.
 

EvilManagedCare

Senior member
Nov 6, 2004
324
0
0
Usually as they appear and as close to the use as possible.

If the variables are all at the same place/scope, then I try to group related variables together and use and empty line to signify a group.

I try and adhere to something like this too. I usually declare constants first as well.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I work with a globally dispersed team of people, so no matter what convention I choose, it won't be adhered to.

I work in C# 90&#37; of the time, and in C# most of what's interesting is at class scope. I try to order my definitions like this...

public constants
public properties
public constructors
public methods
protected properties
protected methods
private properties
private methods
fields