variables

What is the purpose of long, double, byte, char in Java?

So I'm learning java, and I have a question. It seems that the types int, boolean and string will be good for just about everything I'll ever need in terms of variables, except perhaps float could be used when decimal numbers are needed in a number. My question is, are the other types such as long, double, byte, char etc ever used in no...

Best way to test for a variable's existence in PHP; isset() is clearly broken

From the isset() docs: isset() will return FALSE if testing a variable that has been set to NULL. Basically, isset() doesn't check for whether the variable is set at all, but whether it's set to anything but NULL. Given that, what's the best way to actually check for the existence of a variable? I tried something like: if(isset($v)...

How to maintain lists and dictionaries between function calls in Python?

Its urgent... I have a function. Inside that I'm maintainfing a dictionary of values. I want that dictionary to be maintained between different function calls Suppose the dic is : a = {'a':1,'b':2,'c':3} At first call,say,I changed a[a] to 100 Dict becomes a = {'a':100,'b':2,'c':3} At another call,i changed a[b] to 200 I want that ...

Cant declare variables after statements in DevC++

Hey guys, The trouble here is that i cant declare variables inside a function after the function already has some statements in it. Declaring at the start works fine, but after something, it gives a parse error. for example: int main() { int b; b = sisesta(); float st[b]; return 0; } Id like to declare an array st with its size ...

Enumerate or list all variables in a program of [your favorite language here]

A friend asked me last week how to enumerate or list all variables within a program/function/etc. for the purposes of debugging (essentially getting a snapshot of everything so you can see what variables are set to, or if they are set at all). I looked around a bit and found a relatively good way for Python: #!/usr/bin/python ...

mocking superclass protected variable using jmockit

Hi, I couldnt able to mock the protected varibale defined in the superclass.i could able to mock the protected method in superclass but couldnt to mock the protected variable in to the subclass ,wherein am writing the testcase for subclass,Please if anybody out there has any soluton for it .please reply. Thanks Shashi ...

PHP: Convert a String to Variable

I've got a multidimensional associative array which includes an elements like $data["status"] $data["response"]["url"] $data["entry"]["0"]["text"] I've got a strings like: $string = 'data["status"]'; $string = 'data["response"]["url"]'; $string = 'data["entry"]["0"]["text"]'; How can I convert the strings into a variable to access ...

Shell script user prompt/input

This is a crude korn shell script that someone else wrote. I don't know much about using shell syntax and I'm not even sure if this is possible. Is there any way for me to run this file and be prompted for the date so that I don't have to manually go into the script and change it each time? For example, I wan to replace the "1/12/09" ...

What type of variable names do you use to compare two objects

I do a lot of data analysis scripting, comparing two objects or strings to determine differences or come up with gaps that need to be filled. When you're in a loop, comparing object a to object b, do you have a preferred coding standard that makes sense (i.e., it is self-documenting) and can travel nicely to other code? Or are variable ...

What does '@_' do in Perl?

I was glancing through some code I had written in my Perl class and I noticed this. my ($string) = @_; my @stringarray = split(//, $string); I am wondering two things: The first line where the variable is in parenthesis, this is something you do when declaring more than one variable and if I removed them it would still work right? Th...

What is readable code? What are the best practices to follow while naming variables?

Do you think x, y, z are good variable names? How will you explain a new programmer to write readable code? ...

Why are we using i as a counter in loops

why are we using for (int i = 0 ; i < count ; i++){ } why the i why not for (int a = 0; a < count; a++){ } I do it, you do it, everyone does it but WHY? *edit I found out an old saying about FORTRAN which is more funny than correct which says "god is real, everything else above is an integer". "god" would be a variable name s...

SCons problem - dont understand Variables class

I'm working on an SConstruct build file for a project and I'm trying to update from Options to Variables, since Options is being deprecated. I don't understand how to use Variables though. I have 0 python experience which is probably contributing to this. For example, I have this: opts = Variables() opts.Add('fcgi',0) print opts['fcgi'...

Javascript: how to set "this" variable easily?

I have a pretty good understanding of Javascript, except that I can't figure out a nice way to set the "this" variable. Consider: var myFunction = function(){ alert(this.foo_variable); } var someObj = document.body; //using body as example object someObj.foo_variable = "hi"; //set foo_variable so it alerts var old_fn = someObj.fn...

Identifiers or Variables which is which?

Hi, I'm quite confused about several books in .NET that I have read. Would someone out there like to explain to me what an identifier is and how it differs from a variable? Or variables and identifiers are the same? Thanks in advance. ...

How to set the $PATH as used by applications in os x

I'm using ant to build my project, and use the 'svnversion' executable to insert a version id into my sources for easy tracking of versions. Running this ant file from the command line works, I've set my $PATH in .profile to include the path to svnversion and it works fine. Now I try and run this same ant file from inside Eclipse and t...

How do you recommend denoting static class members?

I have a naming strategy for denoting the nature of code entity (variable, method, etc.) which accounts for the most common permutations of scope, entity type, and mutability, but I have not been able to choose a way of denoting private static member fields (not properties). What are some recommended ways of denoting this? Update: F...

C string initializer doesn't include terminator?

I am a little confused by the following C code snippets: printf("Peter string is %d bytes\n", sizeof("Peter")); // Peter string is 6 bytes This tells me that when C compiles a string in double quotes, it will automatically add an extra byte for the null terminator. printf("Hello '%s'\n", "Peter"); The printf function knows when to ...

Javascript local variable technique

I have a simple question related to one-line programming. First an example: function test(a) { var b=a.toString(); return b.replace("a","b"); } It's very simple (this function is, of course, useless), but the question here is little more complicated: What if I was to do this in one line? I have my thoughts, but tell me does this...

Does it help GC to null local variables in Java

I was 'forced' to add myLocalVar = null; statement into finally clause just before leaving method. Reason is to help GC. I was told I will get SMS's during night when server crashes next time, so I better did it :-). I think this is pointless, as myLocalVar is scoped to method, and will be 'lost' as soon as method exits. Extra nulling j...