The tag has no wiki summary.

learn more… | top users | synonyms

5
votes
5answers
638 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
414 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
510 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
2answers
297 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
396 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 ...
34
votes
15answers
4k 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
135 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 = ...
6
votes
3answers
7k 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 ...
3
votes
1answer
392 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
238 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 ...
10
votes
9answers
2k 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 ...
26
votes
17answers
3k 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
3k 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
805 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
226 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
2k 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 ...
5
votes
8answers
440 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 ...
8
votes
2answers
7k 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
898 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 ...
8
votes
5answers
285 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 ...
5
votes
5answers
520 views

Is it OK to use dynamic typing to reduce the amount of variables in scope?

Often, when I am initializing something I have to use a temporary variable, for example: file_str = "path/to/file" file_file = open(file) or regexp_parts = ['foo', 'bar'] regexp = new ...
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 ...
1
vote
6answers
2k views

Why declare variables close to where they are used?

I have heard people say that variables should be declared as close to their usage as possible. I don't understand this. For example, this policy would suggest I should do this: foreach (var item in ...
7
votes
6answers
1k views

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
8
votes
4answers
1k views

When would dynamic scoping be useful?

With dynamic scoping, a callee can access the variables of its caller. Pseudo C code: void foo() { print(x); } void bar() { int x = 42; foo(); } Since I have never programmed in a ...
1
vote
3answers
4k views

Why am I seeing more boolean naming conventions where “is” is used as the first word in the variable (eg, IsUserAdmin vs UserIsAdmin)? [closed]

I think everyone will agree that the following boolean variable/property names are standard: UserIsAdmin OrdersAreClosed The important thing to note about boolean expressions is that they are ...
5
votes
7answers
3k views

How to abbreviate variable names

I always struggle in abbreviating variable names. Is there any standard for abbreviating variable names?
2
votes
2answers
133 views

Is it good idea to write variable names that match application specific terms?

Let us say I am writing a Facebook like application. I write code like below $this->get_user_friends(); then next morning the boss says that we don't want to call Friends friends anymore, we ...
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 ...
6
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?
10
votes
9answers
3k views

When is it ok to use a Global variable

Ok, so this is a bit of a devils advocate question really. When are global variables ok, and if never, what would you use as an alternative? An interesting side-case to this question, how is a ...
20
votes
6answers
9k views

C#: Explicitly defining variable data types vs. using the keyword 'var'?

In C#, am I encouraged to use the all-purpose var keyword for every variable declaration? If yes, do I have to mention those special characters for literal values within the variable declaration like ...
8
votes
3answers
1k views

Are my method or variable names too long?

So I was currently in the middle of coding, unfortunately for me, I was in "The Zone" then I thought to myself, are my method/variable names to long? POP out of the Zone I go! So I came here to ...
5
votes
2answers
919 views

Why is CATALINA_HOME named that way and other interesting program names

I work with open source software a lot and keep coming across weird and funny names for executables, variables, constants and etc. Currently I am wondering why CATALINA_HOME environment variable was ...
10
votes
5answers
704 views

Does any programming language use variables as they're in maths?

In maths, a variable means you can put any number there, and an equation will still be true: root(square(x)) = abs(x) In programming languages, this is not so: a var can change. In Python: y = ...
2
votes
2answers
128 views

Best way to delimit variable elements of a path in code documentation?

Often some element of a path is variable, but the path as a whole needs to be documented in some manner for later programmers. Especially when using *nix systems, almost any character is a valid ...
6
votes
18answers
2k views

What do you name functions/variables/etc when you can't think of a good name?

When you are defining a function/variable/etc and are not sure what to name it, what do you name it? How do you come up with a name? If you use a temporary name as a place-card until you give it it's ...
20
votes
17answers
9k views

How do you name your private variables in C#? [closed]

What is the best practice, most commonly accepted naming conventions for private variables in C#? private int myInteger; private int MyInteger; private int mMyInteger; private int _myInteger; ...
16
votes
3answers
2k views

What's the origin of foo and bar? [duplicate]

Possible Duplicate: Using “Foo” and “Bar” in examples I know AT&T labs used them in their Unix days, but do they have even deeper histories?
69
votes
22answers
18k 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 ...