variables

How many variables should a constructor have?

匆匆过客 提交于 2020-01-01 03:51:10
问题 I realize this is a pretty open question and could get a variety of answers, but here goes. Using C# (or Java, or any OO language), is there a general rule that states how many variables should be passed into the constructor? The number of variables I am passing into the constructor of the extended classes seem to be getting out of hand. In an effort to encapsulate the data of a class, I declare the members private, initialize them in my constructor, and use public accessors. Here is an

Variable scope in XSLT

最后都变了- 提交于 2020-01-01 03:12:13
问题 I am having an issue trying to figure out var scoping on xslt. What I actually want to do it to ignore 'trip' tags that have a repeated 'tourcode'. Sample XML: <trip> <tourcode>X1</tourcode> <result>Budapest</result> </trip> <trip> <tourcode>X1</tourcode> <result>Budapest</result> </trip> <trip> <tourcode>X1</tourcode> <result>Budapest</result> </trip> <trip> <tourcode>Y1</tourcode> <result>london</result> </trip> <trip> <tourcode>Y1</tourcode> <result>london</result> </trip> <trip> <tourcode

How do I use Python to easily expand variables to strings?

拜拜、爱过 提交于 2020-01-01 02:34:23
问题 What's a nice idiom to do this: Instead of: print "%s is a %s %s that %s" % (name, adjective, noun, verb) I want to be able to do something to the effect of: print "{name} is a {adjective} {noun} that {verb}" 回答1: "{name} is a {adjective} {noun} that {verb}".format(**locals()) locals() gives a reference to the current namespace (as a dictionary). **locals() unpacks that dictionary into keyword arguments ( f(**{'a': 0, 'b': 1}) is f(a=0, b=1) ). .format() is "the new string formatting", which

Replace multiple characters in a string in javascript

这一生的挚爱 提交于 2020-01-01 02:31:35
问题 I got this nice code, which I have no idea why doesn't work. It should get the value of a text input and replace each given national character with it's HTML code, for compatibility purposes. But, when I click the button, the function returns the string without any changes. Any idea? (jsfiddle) <a id="reminder1" onclick="document.getElementById('reminder2').style.display = ''; document.getElementById('reminder1').style.display = 'none';"> Set reminder </a> <a id="reminder2" class="reminder"

Why do I get an “Unreferenced Local Variable” warning? (C++)

ぃ、小莉子 提交于 2020-01-01 00:50:14
问题 When I do something like #include<iostream> int main() { int x; return 0; } I get a warning about x being an unreferenced local variable (I assume becuase I created a variable, then did not use it), why does this give me a warning though? 回答1: Probably because you're wasting memory for nothing. Besides, the code becomes dirty and harder to understand, not to mention that programmers don't usually define variables they don't need, so it's sort of a "is this really what you meant?" warning. 回答2

What's the purpose of using & before a function's argument?

匆匆过客 提交于 2019-12-31 17:49:12
问题 I saw some function declarations like this: function boo(&$var){ ... } what does the & character do? 回答1: It's a pass by reference. The variable inside the function "points" to the same data as the variable from the calling context. function foo(&$bar) { $bar = 1; } $x = 0; foo($x); echo $x; // 1 回答2: Basically if you change $var inside the function, it gets changed outside. For example: $var = 2; function f1(&$param) { $param = 5; } echo $var; //outputs 2 f1($var); echo $var; //outputs 5 回答3

How to pass parameters or arguments into a gradle task

人走茶凉 提交于 2019-12-31 17:37:30
问题 I have a gradle build script into which I am trying to include Eric Wendelin's css plugin - http://eriwen.github.io/gradle-css-plugin/ Its easy enough to implement, and because I only want minification (rather than combining and gzipping), I've got the pertinent parts of the build script looking like this: minifyCss { source = "src/main/webapp/css/brandA/styles.css" dest = "${buildDir}/brandA/styles.css" yuicompressor { lineBreakPos = -1 } } war { baseName = 'ex-ren' } war.doFirst { tasks

jmeter - showing the values of variables

元气小坏坏 提交于 2019-12-31 12:36:13
问题 My group does a lot of test automation with JM. Typically we have a properties file which has a bunch of variables defined. These in turn are mapped to "User Defined Variables" of which we have a number of different sets. These are in referenced throughout the rest of the jmx - I find it difficult as there are so many variables in so many different places to know what is what. Is there any way to have jmeter display what values its variables have - custom sampler is fine ? Ideally id love it

Regex $1, $2, etc

半世苍凉 提交于 2019-12-31 12:18:49
问题 I've been trying to do some regex operations in PHP, and I'm not very skilled in this area. It seems that when I use a regex function like preg_replace on a string, I can access the regex-replaced strings by some sort of variables named $1, $2, and so on. What is this called and how can I use it? 回答1: These are known in regex terminology as backreferences (more on that here). You use them to refer to capture groups (or subpatterns, surrounded by () ) within your regex or in the replacement

Assigning using ternary operator?

廉价感情. 提交于 2019-12-31 09:12:13
问题 I am on Perl 5.8 and am needing to assign a default value. I ended up doing this: if ($model->test) { $review = "1" } else { $review = '' } The value of $model->test is going to be either "1" or undefined. If there's something in $model->test , set $review to "1" otherwise set it equal to '' . Because it's not Perl 5.10 I can't use the new swanky defined-or operator. My first reaction was to use the ternary operator like this... defined($model->test) ? $review = "1" : $review = ''; but that