Dynamic variable creation language [closed] - variables

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Which computer languages will allow code that dynamically extracts a variable name from a string, like user types in an argument "hhh", and the code then knows to reference a variable with the identifier: hhh? Thanks for your help.

Not exactly "dynamic variable creation", but you can get pretty much the same effect by using an associative array (a.k.a. dictionary or map). For example, in Python:
vars = {}
vars['x'] = 'hello'
vars['y'] = 10
With the above code, the keys 'x' and 'y' in the dictionary are like dynamic variables for all practical purposes, for example:
print vars['x']
> hello
vars['y'] + 6
> 16
As a matter of fact, under the hood many programming languages (Python, JavaScript, etc.) use a dictionary of bindings for implementing variables and scoping rules.

The associative array is probably a better idea to use, but just in case, php supports this without putting the code inside an eval function:
<?php
class ff {
var $u = "aagg";
}
$y = new ff();
$i = "u";
echo $y->$i;
?>

Related

What does ++num1var[num2var] mean? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Page 109 of The AWK Programming Language book has a statement to create a 2-D array named attr:
attr[nrel, $1] = ++nattr[nrel]
nrel = an integer representing the number of relations (tables)
nattr = an integer representing the number of attributes (table columns)
Substituting country for $1, 1 for nrel, and 1 for nattr we have:
attr[1, country] = 1[1]
What does the right-hand side of that statement mean? It appears to be referencing subscript 1 of array 1. Can an array be named 1? Would you explain what that expression means, please?
Page 109(...)
I have look into archive.org's version and line
attr[nrel, $1] = ++nattr[nrel]
is sole line referencing nattr and therefore this is where nattr is created, as you are asking about value under key it will be array. You might check that by substituting all but nattr as proposed and using typeof function
awk 'BEGIN{attr[1, "France"] = ++nattr[1];print typeof(nattr)}' emptyfile
gives output
array
therefore shown line does firstly increase value in array nattr under key nrel and then assign such changed value to array attr under key nrel, $1.
(tested in gawk 4.2.1)

How to name boolean variable that indicates whether to do something? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
As far I as my experience tells me, boolean variables usually named in format - is/has+noun/adj/verb, e.g isValid, isButton, hasClickedLink
But say there is the case where we have some flag which straightly tells whether to do something, like for example, clean to indicate that cleanup function should be automatically called in the end.
How to name such a booleans? Same clean - is ambiguous, looks like a method name more, but naming it toClean is, I don't know, too weird. Or should I name it like callCleanup?
Thanks in advance!
In this case i usually append the word wanted, which makes cleanWanted. In general, for boolean variables I also prefer to always let the last word be an adjective. This makes it very clear that it represents a truth value. The is/has prefix is often superfluous, as in hasClickedLink which is more concisely communicated with linkClicked.
methods are usually one word adjectives with a capitol at the start
maybe create a method that sets the flag
for example
void Clean(){
clean = True;
}

How to idiomatically format .apply{} in Kotlin? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
This might seem a little trivial, but since we read more code than we write, I want to know which of these versions looks nicer and more readable for you
private val VALUES by lazy {
mutableListOf<Value>().apply {
add(VALUE_1)
add(VALUE_2)
add(VALUE_3)
}
}
OR
private val VALUES by lazy {
mutableListOf<Value>()
.apply {
add(VALUE_1)
add(VALUE_2)
add(VALUE_3)
}
}
In other words, should we care that the method (.apply) be on the same line as the caller, or the ending curly bracket to be aligned with the (.apply) method?
As per https://kotlinlang.org/docs/reference/coding-conventions.html
Chained call wrapping
When wrapping chained calls, put the . character or the ?. operator on the next line, with a single indent:
val anchor = owner
?.firstChild!!
.siblings(forward = true)
.dropWhile { it is PsiComment || it is PsiWhiteSpace }
The first call in the chain usually should have a line break before it, but it's OK to omit it if the code makes more sense that way.
So it's up to you :)

Is a dictionary patch the appropriate term used to describe an acronym? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In Silicon Valley S03E01 Gilfoyle and Dinesh have a conversation about Richard. In the conversation they use the term dictionary patch as such:
Gilfoyle: What if we use like a dictionary patch? To compress all the
nice-guy stuff.
Dinesh: Like an acronym.
Gilfoyle: Exactly. "Richard is great, but you know"... R-I-G-B-Y.
Dinesh: Rigby.
Gilfoyle: Rigby is all the nice-guy stuff.
Wouldn't that be a dictionary key?
Example of a dictionary key:
var dictionary:Dictionary = new Dictionary();
dictionary["RIGBY"] = "Richard is great, but you know";
console.log(dictionary["RIGBY"]);
// output is "Richard is great, but you know";
in this case the dictionary key is "RIGBY"
http://siliconvalleyism.com/silicon-valley-quote.php?id=135
I've never heard of the term "dictionary patch" outside of Silicon Valley. But, yes, 'RIGBY' would be the dictionary key, but dictionary patch wasn't just talking about the key. They were referring to a process of using a dictionary key to replace a long value with that key. So, he's calling this whole higher-level process "dictionary patching", although I've never heard of it.

How to pluralize a function's name in technical writing? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How to pluralize a function's name such as foobar in technical writing?
By technical writing i mean, for example, comment text in source code, documentation of a software or programming element that might be in different place from the corresponding source code.
Should i use
foobars
foobar`s
foobar's
foobar
?
I'd suggest not changing the function/method name in any way as that would invite confusion, but refer to it like:
Use the fooBar functions to blah, blah, blah...
or
Use the fooBar methods to blah, blah, blah...
Add the "s" at the end like any other plural, but distinguish via formatting.
Write something like "All of the substrs are...". I also will distinguish a function name as a function name by using parentheses, as in "All of the substr()s are ...".