The variables tag has no wiki summary.
-4
votes
0answers
43 views
Cannot refer to a class within another .java file [closed]
So, I am editing the minecraft launcher, and I am trying to make a bit that saves the value typed into the JTextField() and the JPasswordField(). I am following a tutorial, and it says I should have a ...
2
votes
1answer
249 views
What is the difference/ advantage of doing double assignment?
Is there any advantage / is it a bad practice in Java to do the below
x = x = 5
I saw it in one of my peers code and I was surprised why he would do double assignment?
Is this something that is ...
1
vote
4answers
248 views
Is there a concept of a variable with phases of initialization: uninitialized, initializing, immutable?
I was looking at this thread on Stack Overflow and thinking about the functional programming I've been learning, and how immutability is so key there, and it occured to me that maybe some language has ...
-2
votes
0answers
69 views
Examples of bad variable names and reasons [closed]
I'll start with a class in the jdk package :
public final class Sdp {
should be :
public final class SocketsDirectProtocol {
Sdp is class name, this is ambigious, should be :
Class<?> ...
9
votes
11answers
2k views
What is the reason for using lowercase for the first word in a local variable (eg, employeeCount, firstName)
I take a good deal of criticism from other programmers due to my use of full proper casing for all my variables. For example, your typical programmer will use employeeCount for a variable name, but I ...
14
votes
1answer
332 views
Dollar Sign Blues: Javascript and PHP
I grew up programming C++ and Java where everything was safe and beautiful. Compilers made sure to keep me in check if I ever strayed. Of course, everyone did a little Perl in college, but I didn't ...
1
vote
1answer
80 views
What are the pros and cons of temporary variables vs multiple returns [duplicate]
Take the following examples:
public static String returnOnce() {
String resultString = null;
if (someCondition) {
resultString = "condition is true";
} else {
resultString ...
1
vote
4answers
369 views
“Is” prefix and “On” suffix as reasonable exceptions to a “non-hungarian” naming standard?
First, I believe I've seen this question discussed here before, but I cannot find it. My apologies if you do find it.
I'm starting a new project, and trying to figure out why IsResolved and/or ...
8
votes
3answers
224 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 ...
1
vote
5answers
261 views
Why do some programmers keep values in global variables or member variables but not reused?
I am talking about normal PC applications, memory should be sufficient.
They declare global or member variables.
In each function/method, they use the same global/member variables.
At the beginning ...
15
votes
10answers
2k views
How to write useful Java programs without using mutable variables
I was reading an article about functional programming where the writer states
(take 25 (squares-of (integers)))
Notice that it has no variables. Indeed, it has nothing more than three ...
59
votes
6answers
3k 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 ...
7
votes
5answers
240 views
Programming principles with regard to software (computational) efficiency and the use of variables
I'm classically trained psychologist, not a programmer, so sometimes the more advanced aspects of programming escape me, in particular regarding program efficiency and/or certain best practices, in ...
38
votes
7answers
2k views
How to name a variable when the word is both a noun and a verb
I have run into a corner-case problem with the general guidance of:
nouns for variables
verbs for functions
Specifically, I have a case where the word is ambiguous - it can be either a verb or a ...
9
votes
7answers
808 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 ...
4
votes
4answers
620 views
Stack and heap - dynamic allocation question
Sources usually mention that dynamically created variables are allocated on the heap, while functions' variables on the stack. Also the ones on the stack cease to exist automatically when e.g. the ...
5
votes
1answer
393 views
Do there exist programming languages where a variable can truly know its own name?
In PHP and Python one can iterate over the local variables and, if there is only once choice where the value matches, you could say that you know what the variable's name is, but this does not always ...
2
votes
1answer
242 views
Effective handling of variables in non-object oriented programming
What is the best method to use and share variables between functions in non object-oriented program languages?
Let's say that I use 10 parameters from DB, ID and 9 other values linked to it. I need ...
4
votes
3answers
790 views
Does it make a difference if I declare variables inside or outside a loop in Java? [duplicate]
Possible Duplicate:
Where do you declare variables? The top of a method or when you need them?
Does it make a difference if I declare variables inside or outside a loop in Java?
Is this
...
-3
votes
3answers
288 views
In what practical ways is it good to remember the memory/pointers model? [closed]
A variable refers to a value. A variable is also stored in a memory address. People say that it's good to have this memory model in mind. Is that true? What is some sample code that shows this as ...
5
votes
4answers
357 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 ...
87
votes
12answers
28k views
Why is Clean Code suggesting avoiding protected variables?
Clean Code suggests avoiding protected variables in the "Vertical Distance" section of the "Formatting" chapter:
Concepts that are closely related should be kept vertically close to each other. ...
4
votes
6answers
332 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 ...
6
votes
2answers
1k views
What does the term “Payload” mean in programming
I was going through the source code of an open source framework, where I saw a variable "payload" mentioned many times. Any ideas what "payload" stands for?
9
votes
2answers
254 views
What is a user-friendly solution to editing email templates with replacement variables?
I'm working on a system where we rely a lot of "admins / managers" emailing users from the database. One of the key features is being able to email several people at the same time, with specific ...
0
votes
1answer
123 views
Tool to visualize values from variables during the execution of a program in C
I just need to see what is stored, in realtime, in some particular variables and struct used by an application written in C.
I need something like the stack tracer that comes with the ADT plugins for ...
2
votes
2answers
66 views
Variable names for Contact Information bits [closed]
I am in the middle of refactoring code and would like to get some ideas on variable naming so that my new names clearly represent the data they hold.
I have a class called ContactMethod which makes ...
11
votes
7answers
375 views
Generalise variable usage inside code
I would like to know if it is a good practice to generalize variables (use single variable to store all the values).
Consider simple example
Strings querycre,queryins,queryup,querydel;
querycre ...
-2
votes
1answer
220 views
Naming conventions for variables in Germany [duplicate]
Possible Duplicate:
Do people in non-English-speaking countries code in English?
Do programmers in Germany/France use English names for variables or it's a normal practice to use local ...
1
vote
1answer
780 views
Ongoing confusion about ivars and properties in objective C
After almost 8 months being in ios programming, I am again confused about the right approach. Maybe it is not the language but some OOP principle I am confused about. I don't know..
I was trying C# a ...
5
votes
5answers
339 views
Initialized variables vs named constants
I'm working on a fundamental programming class in college and our textbook is "programming logic and design" by joyce farrell(spelling?)
Anyhow, I'm struggling conceptually when it comes to ...
7
votes
4answers
263 views
Definition of “state”
What is a good way to define "state", as in state variable or state machine, to a new (previously non) programmer? What are some good ways to explain why this concept is useful for writing software? ...
2
votes
7answers
447 views
Should I refactor single letter variables for constructs like pointer/structure names?
And No, i am not referring to single variables in loops or exceptions. Lets say pointer/struct names in large c ,c++ programs . Are there any languages where this type of naming is acceptable or is ...
3
votes
1answer
248 views
Better use on the name of variables
I have a method that looks like this:
Public Function NormalizeStreetAddress(country As Namespace.Country,
streetAddress As Namespace.StreetAddress) _
...
4
votes
5answers
270 views
variable comparison without initialising
I am working with a project in VC++ which involves co-ordinate system having x,y,z axis.
I am trying to check for if a variable(Point with x,y,z values) is assigned on the coordinate system or its a ...
32
votes
15answers
3k views
Is it bad practice to name an unused variable with a single underscore?
Often when the syntax of the language requires me to name a variable that is never used, I'll name it _.
In my mind, this reduces clutter and lets me focus on the meaningful variables in the code. I ...
4
votes
3answers
125 views
Using “prevent execution of method” flags
First of all I want to point out my concern with some pseudocode (I think you'll understand better)
Assume you have a global debug flag, or class variable named "debug",
class a :
var debug = ...
4
votes
3answers
2k views
What is meant by Scope of a variable?
I think of the scope of a variable as -
"The scope of a particular variable is the range within a program's source code in which that variable is recognized by the compiler".
That statement is ...
2
votes
1answer
235 views
Giving variables default values vs. treating accessing an undefined variable as an error
Having messed around with several scripting languages and being a bit of a linguist, there seems to be a way to divide dynamically typed languages into two groups: languages that give variables a ...
4
votes
2answers
178 views
How to deal with variables when extracting methods in to smaller methods?
This is an abstract question to clarify a refactoring concept in the ruby language. Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish ...
9
votes
9answers
1k views
Why do variables need a type?
So we write:
Customer c = new Customer();
Why is the design not such that we write:
c = new Customer();
c.CreditLimit = 1000;
The compiler can work out c points to a Customer and allow ...
23
votes
17answers
2k views
Is it a good practice to name the returned variable “result”? [closed]
Is it a good practice to call the variable a method returns with a variable name result?
For instance:
public Zorglub calculate() {
Zorglub result = [...]
[...]
return result;
}
Or ...
25
votes
9answers
2k views
Why should identifiers not begin with a number?
Most programming languages appear to be designed to not allow one to declare an identifier that starts with a number. I was just curious to know the reason. I have already searched the web, but ...
2
votes
5answers
545 views
Why is it discouraged to create variables on the fly? PHP gives you a Notice Error
Are you guys familiar with those pesky PHP notice errors? You know, the ones that will appear when you do something like this:
if($some_variable == 45)
But if $some_variable wasn't created already, ...
0
votes
2answers
184 views
Semantic or structure - which should get preference for variable naming?
We've a call stack in our project. The program is written for microcontroller, the language is C. The call stack is basically an array of integers. The variable that represents this call stack ends ...
11
votes
4answers
1k views
Handling extremely large numbers in a language which can't?
I'm trying to think about how I would go about doing calculations on extremely large numbers (to infinitum - intergers no floats) if the language construct is incapable of handling numbers larger than ...
4
votes
8answers
363 views
One-use variables - has any language ever had them?
A principle that I follow is that, when an identifier is established, it should be a signal to the reader that the value referred to is indeed an abstraction which will be used more than once. That ...
4
votes
2answers
3k views
Naming conventions for instance, local and parameter variables
I was discussing with a senior developper coding conventions to apply to our projects (mainly Java/JEE projects). I disagreed with one convention he proposed:
Instance variable names should start ...
3
votes
7answers
614 views
Any standards for naming variables in for loops (instead of i,j,k) [duplicate]
Possible Duplicate:
Why do most of us use 'i' as a loop counter variable?
I was just writing a nested loop and got to the point where I was using l and m as variables to control for ...
7
votes
5answers
252 views
How do you avoid name similarities between your classes and the native ones?
I just ran into an "interesting problem", which I would like your opinion about:
I am developing a system and for many reasons (meaning: abstraction, technology independence, etc) we create our own ...