The tag has no wiki summary.

learn more… | top users | synonyms

102
votes
12answers
32k 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. ...
69
votes
22answers
13k 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 ...
60
votes
6answers
4k 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 ...
42
votes
11answers
5k 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 ...
39
votes
7answers
3k 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 ...
34
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 ...
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 ...
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 ...
24
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 ...
20
votes
2answers
1k views

When did the term “snake case” come into use?

Many people use the term Snake Case to describe variables or other symbols with_the_form_of_underscores. When did this term enter into use?
19
votes
17answers
8k 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; ...
17
votes
6answers
7k 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 ...
16
votes
3answers
1k 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?
14
votes
10answers
3k 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 ...
14
votes
1answer
543 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 ...
11
votes
7answers
391 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 ...
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 ...
10
votes
5answers
683 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 = ...
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 ...
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 ...
9
votes
7answers
972 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 ...
9
votes
2answers
302 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 ...
8
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 ...
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 ...
8
votes
2answers
3k 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?
8
votes
3answers
237 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 ...
8
votes
5answers
275 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 ...
8
votes
4answers
978 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 ...
7
votes
5answers
258 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 ...
7
votes
4answers
353 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? ...
7
votes
3answers
2k 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 ...
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 ...
6
votes
2answers
6k 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 ...
6
votes
5answers
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 ...
5
votes
7answers
2k views

How to abbreviate variable names

I always struggle in abbreviating variable names. Is there any standard for abbreviating variable names?
5
votes
10answers
4k 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?
5
votes
8answers
415 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 ...
5
votes
5answers
501 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 ...
5
votes
4answers
493 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 ...
5
votes
7answers
626 views

How important is to initialize a variable

How important is it to initialize variables? Does proper initializing avoid memory leaks or have performance advantages?
5
votes
5answers
542 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 ...
5
votes
2answers
840 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 ...
5
votes
1answer
432 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 ...
4
votes
6answers
350 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 ...
4
votes
5answers
362 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 ...
4
votes
3answers
5k 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 ...
4
votes
4answers
1k 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 ...
4
votes
3answers
134 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
2answers
220 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 ...
4
votes
5answers
204 views

Using π, φ, λ etc. as variable names while programming? [duplicate]

This is a function in the d3.v3.js file (the graph library D3.js): function d3_geo_areaRingStart() { var λ00, φ00, λ0, cosφ0, sinφ0; d3_geo_area.point = function(λ, φ) { ...