The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
2answers
286 views

Why to declare a String (as final) and then use it?

In a typical spring mvc validator class, while inserting an errorCode value in the Errors object, what difference does it make between using a String (props.somefield.req) like so ...
2
votes
1answer
211 views

Why is mixing plural with singular and camel case with underscores in cake php naming convention better than a simpler convention?

I have been using cake php for over a year and generally I like it but I struggle to understand the advantages of the complex naming conventions over something simpler. Cake uses plural here and ...
1
vote
4answers
176 views

Best datatype to store a ternary, or three-state variable

Disclaimer: I know that datatypes are a little bit subjective to which scripting/programming language you are using, I like to write in Python as a matter of preference; though I am happy to hear ...
2
votes
1answer
1k views

Where should variables be declared [duplicate]

Considering I have a for loop in a method of a class. Should the incremented variable be declared as member of the class, or should it be declared in the method it uses it(or even in the for loop, ...
0
votes
3answers
151 views

Isolating unit tests in python

As a 30-year software developer, mostly in OO languages, but a newbie at python, I'm looking to find what is best practise for isolating unit tests in python. Let's say I have the following, ...
1
vote
2answers
128 views

What is the underlying mechanism behind va_list and where is it defined?

http://www.cplusplus.com/reference/cstdarg/va_list/ According to the above link, va_list is an argument or parameter used in some macros - va_start, va_arg, va_end. These macros are present in the ...
4
votes
5answers
244 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(λ, φ) { ...
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
87 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 ...
0
votes
2answers
84 views

Scope vs Visiblity vs Lifetime vs Accessibility vs etc

I have been trying to understand what it means to say "scope of a named entity". In reading about scope, there are terms like visibility, lifetime, accessibility and more that are used. What is ...
2
votes
2answers
143 views

Is there a difference between declaring variables outside or inside a loop? [closed]

Is there any difference if I were to write something like this: int row,col; for(row = 0; row < data.length; row++){ for(col = 0; col < data[row].length;col++){ //do ...
5
votes
7answers
1k 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?
1
vote
4answers
385 views

How should you cleanly restrict object property types and values in Python?

I have been learning python from no long time ago. But nearly at the beginning I stumbled on simple question: how to set a restriction (limitation) on object value or object's properties without ...
0
votes
1answer
379 views

When to use (Or not) C# myVariable { set; get; }

I have been trying to wrap my head around the finer points of this today. Essentially I have fallen in love with this format for booleans: Class { public static bool myBool {set; get;} private ...
1
vote
3answers
253 views

“state” or “status”? When should a variable name contain the word “state”, and when should a variable name instead contain the word “status”? [closed]

Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist: When a variable holds a value intended ...
2
votes
2answers
190 views

How to pass parameters to a function in C

Suppose I'm writing a program in C in which several parameters are asked at the beginning of the execution to the user and then remain costant until the end. Now, I need to pass these parameters to ...
2
votes
2answers
549 views

Recommended guidelines for declaring bash/sh variables

I have been programming in BASH for a while now and the scripts that I write are starting to get more complicated. I realized that I started to bring in some habits from C/C++ and wanted to get ...
0
votes
5answers
603 views

Changing a variable through a series of statements … What is this technique called?

I'm looking at a function that that has several statements like this: n = returnDifferentVersionOf(n); I.e., the value of the same variable n changes progressively several times during the course ...
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?
0
votes
1answer
134 views

Translating variables into english [closed]

I have recently came across some code where the variable names are in french, I could not use google translate because only part of the code needs translated, and it would not be that practical to ...
2
votes
0answers
59 views

Multiple meanings for one variable? [duplicate]

I'm replacing a guy who was in his first job as a programmer. You'd think being fresh out of school means the basics are fresh in one's mind, but think again. The code base is horrible, Ctrl+C / ...
2
votes
1answer
676 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
260 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 ...
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
606 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 ...
2
votes
1answer
133 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
508 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
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 ...
1
vote
5answers
337 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 ...
13
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 ...
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 ...
7
votes
5answers
261 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 ...
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 ...
9
votes
7answers
992 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
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 ...
5
votes
1answer
447 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
263 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 ...
7
votes
3answers
3k 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
297 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
543 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 ...
103
votes
11answers
33k 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
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 ...
11
votes
2answers
5k 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
313 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
161 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
1answer
80 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
393 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 ...
1
vote
2answers
1k 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
612 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
393 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? ...