variables

c# using setters or getters from base class

Is it recommended to set member variables of a base class to protected, so that subclasses can access these variables? Or is it more recommended to set the member variables to private and let the subclasses get or set the varible by getters and setters? And if it is recommended to use the getters and setters method, when are protected v...

C# implementation multiple variables

Hi all, I have something like this: classes A to D all have variables var1, var2, var3, var4, var5 class A has an extra variable var6 class B doesn't have var6, but do have the variables var7, var8 class C is the same as B, but has an extra variable var9 class D only has an extra variable, var10 How should i implement this? The be...

xsl grouping sort problem

Hi I have the following xsl template that I'm using to group my xsl. The problem I have is that I need to uppercase the @Title as currently my grouping is seeing upper and lowercase as seperate groups. <xsl:key name="rows-by-title" match="Row" use="substring(@Title,1,1)" /> <xsl:template name="Meunchian" match="/dsQueryResponse/...

How to trim whitespace from bash variable?

I have a shell script with this code: var=`hg st -R "$path"` if [ -n "$var" ]; then echo $var fi But the conditional code always executes because hg st always prints at least one newline character. Is there a simple way to strip whitespace from $var (like trim() in php)? or Is there a standard way of dealing with this issue?...

Python variable scope question

Hi, I've been programming for many years, and recently started learning Python. The following code works as expected in both python 2.5 and 3.0 (on OS X if that matters): a, b, c = (1, 2, 3) print(a, b, c) def test(): print(a) print(b) print(c) # (A) #c+=1 # (B) test() However, when I uncomment line (B), I ...

need help-variable creation in Python

I want to create varibales as a1,a2,a3,...a10. For that i used a for loop.As the variable in loop increments..i need var gettng created as above . Can anyone give me an idea? At the same time of creation i need to be able to assign to them There i m gettng syntax error ...

Can you get a list of variables on the stack in C#?

All, just wondering if it's possible in .NET/C# to get a list of variables on the stack and their values? I am creating an exception handler for my app and beyond a standard stack trace I'd also like to see the names and values for any variables that are on the stack. Any idea if this can be done? ...

PHP: printing undefined variables without warning

I'm just wondering if there is a quick way to echo undefined variables without getting a warning? (I can change error reporting level but I don't want to.) The smallest I have so far is: isset($variable)?$variable:'' I dislike this for a few reasons: It's a bit "wordy" and complex $variable is repeated The echoing of a blank string a...

need help-variable creation in Python (continuation)

That was helpful kgiannakakis. I'm facing a problem as below: a = ['zbc','2.3'] for i in range(0,5): exec('E%d=%s' %(i,a[i])) This results in: Traceback (most recent call last): File "", line 2, in exec('E%d=%s' %(i,a[i])) File "", line 1, in NameError: name 'zbc' is not defined ...

Whats The Most Efficient Way To Instantiate Worker Variables

Should I instantiate my worker variables inside or outside my for loop E.g. a) bool b = default(bool); for (int i = 0; i < MyCollection.Length; i++) { b = false; foreach(object myObject in myObjectCollection) { if (object.Property == MyCollection[i].Property) { b = true; break; } } if (b) {...

What naming convention do you use for member variables?

What do you use to denote a member variable in a class? The most common time this is a problem is when you have a parameter passed into a constructor to set a member variable. Here is an example: public MyClass(string name) { name = name; // arghh!! } I've used m_name before, but that stinks of Hungarian. I've used _name before...

Should I use static data members? (C++)

Let's consider a C++ class. At the beginning of the execution I want to read a set of values from an XML file and assign them to 7 of the data members of this class. Those values do not change during the whole execution and they have to be shared by all the objects / instances of the class in question. Are static data members the most el...

removing whitespaces in ActionScript 2 variables

let's say that I have an XML file containing this : <description><![CDATA[ <h2>lorem ipsum</h2> <p>some text</p> ]]></description> that I want to get and parse in ActionScript 2 as HTML text, and setting some CSS before displaying it. Problem is, Flash takes those whitespaces (line feed and tab) and display it as it is. <some...

In C, why is the asterisk before the variable name, rather than after the type?

In my experience, everyone names variables like this: int *myVariable; Rather than like this: int* myVariable; Both are valid. It seems to me that the asterisk is a part of the type, not a part of the variable name. Can anyone explain this logic? ...

Why can't a member Sub change a member variable in RapidQ (Basic)?

I am using RapidQ (an obscure environment, I know). The programming language is Basic. The following source code illustrates the problem: Type MyType Extends QOBJECT aVar as Integer Sub SetTheVar this.aVar = 10 End Sub Sub DoSomething this.Avar = 20 this.SetTheVar SHOWMESSAGE "aVar =...

Difference between declaring variables before or in loop?

Hi, I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference? A (quite pointless example) in Java: a) declaration before loop: double intermediateResult; for(int i=0;i<1000;i++){ intermediateResult = i; System.out.println...

Iteration over vector in C++

What is the correct way of iterating over a vector in C++? Consider these two code fragments, this one works fine: for (unsigned i=0; i < polygon.size(); i++) { sum += polygon[i]; } and this one: for (int i=0; i < polygon.size(); i++) { sum += polygon[i]; } which generates warning: comparison between signed and unsigned integer ...

Are these PHP conditionals the same or does one have an advantage

Is there any advantage to writing a PHP conditional like this: if ($variable != NULL) { versus if (!empty($variable)) { versus if ($variable) { Aren't they all same thing? It seems like the last is always the simplest if you are just trying to tell whether the variable exists or not. Thanks for helping me understand the differen...

PHP session variables not carrying over to my logged in page, but session ID is

I'm using PHP 4.3.9, Apache/2.0.52 I'm trying to get a login system working that registers DB values in a session where they're available once logged in. I'm losing the session variables once I'm redirected. I'm using the following code to print the session ID/values on my login form page and the redirected page: echo '<font color="re...

Why are local variables not initialized in Java?

Was there any reason why the designers of Java felt that local variables should not be given a default value? Seriously, if instance variables can be given a default value, then why can't we do the same for local variables? And it also leads to problems as explained in this comment to a blog post... ...