How to name boolean variable that indicates whether to do something? [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 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;
}

Related

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 ...".

Dynamic variable creation language [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 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;
?>

Wide Method Call VB.NET [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 4 years ago.
Improve this question
I've just written this:
ldb.Update(emp.Code,emp.number, "text", String.Empty, "EMP", emp.scheme, emp.status, emp.tod, emp.timestamp, emp.Code, emp.oldfrmd)
Its far to wide! How can I shorten this method call? The problem is this isn't my method, so I can't edit it.
It depends on what your concern is:
Too many parameters? Can't really change that without changing the method, although you could introduce a proxying method containing fewer parameters, where each parameter may map to several of the original ones. It looks like you might want to make this a method on whatever the type of emp is, but it's hard to know without more information.
Just too wide on the screen? Use line continuations:
ldb.Update(emp.Code, emp.number, "text", String.Empty, "EMP", _
emp.scheme, emp.status, emp.tod, emp.timestamp, _
emp.Code, emp.oldfrmd)
(IIRC the "_" isn't actually needed in VB10.)
Too many characters? Introduce some local variables, potentially, shortening the eventual call to something like:
ldb.Update(code, number, "text", "", "EMP", scheme, status, _
tod, timestamp, code, oldfrmd)
(Although your overall code will be bigger, of course.)
Since you can't change the method signature, you must really be passing all those fields of emp into it. I would tend to write my own function (pardon my terribly rusty VB; I'm sure there's something wrong with this):
updateLdb(Employee e)
which simply called ldb's function and did nothing more. Using a single letter for a variable name is generally a bad idea, but in this case it saves your line 16 characters, and in a one-line function, "e" isn't particularly less informative than "emp". As Jon says if you move this function into the Employee class, you can get rid of another 16 characters - and it does appear to really belong there.
I would not use "e" as a variable or parameter name in any function that is longer than one or two lines, but in that small a scope, I think you can get away with it without significantly sacrificing readability.