Tagged Questions
69
votes
22answers
17k views
Where do you declare variables? The top of a method or when you need them? [closed]
I am in sort of a dilemma (in a geekish way of course).
I love to declare variables at the beginning of my methods, and usually order them in some logical way.
The problem is, when the list gets ...
2
votes
1answer
51 views
When should I pass setting-like value as class' variable and when as an assoc. array?
Following my other question, is there a general rule of thumb, when we should pass a setting-like value, that controls class' behavior (for example displayed texts) as as class' constant or variable, ...
1
vote
1answer
88 views
When should I pass value as class variable and when as a method argument?
Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer?
For example -- are there any reasons, why ...
31
votes
11answers
1k views
Intentional misspellings to avoid reserved words
I often see code that include intentional misspellings of common words that for better or worse have become reserved words:
klass or clazz for class: Class clazz = ThisClass.class
kount for count in ...
9
votes
7answers
994 views
Temporary variables vs line length requirements
I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble.
Fowler recommends that you replace temporary ...
8
votes
3answers
239 views
Is a single object to be preferred over multiple variables?
It was quite hard to put what I meant into a title, but it's easy to put into code.
C++
Is this
int offset_x = 10;
int offset_y = 40;
...
element.move(offset_x, offset_y);
To be preferred over ...
61
votes
6answers
5k views
Should the variable be named Id or ID?
This is a bit pedantic, but I've seen some people use Id as in:
private int userId;
public int getUserId();
and others use:
private int userID;
public int getUserID();
Is one of these a better ...
5
votes
4answers
544 views
Method flags as arguments or as member variables?
I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes:
I'm currently trying to get my head around the ...
4
votes
6answers
355 views
Order of subject and modifiers in variable names
I'm looking for experiences regarding the ordering of the subject and modifiers in variable names.
A simple object Shape would have just a subject for the variable name, such as Area.
A slightly ...
42
votes
11answers
6k views
Should I reuse variables?
Should I reuse variables?
I know that many best practice say you should not do it, however later when different developer is debugging the code and have 3 variables that look a like and only ...
5
votes
10answers
5k views
Variable names: underscores, no underscores, or camel case? [closed]
Variable names can be written in many ways, but the most common that I'm familiar with are:
thisisavariable,
this_is_a_variable, and
thisIsAVariable.
Which of these are preferred, and why?