11
votes
Accepted
Is it necessary for a boolean to be "false" by default?
No, you absolutely should not choose variable names to conform to your language's default values.
The point of variable names is to make reading code easier for the maintainer. Default values are a ...
10
votes
Should an optional boolean function argument rather default to true or false?
In line with @Ewan's arguments, choose the one making the code easier to read and reason about.
For example, double negations (!isNotA or Ewan's !FileDoesntExist) are the kind of conditional ...
7
votes
Accepted
What should be the last entry in a switch/case statement?
imagine an implicit enumeration
I think this is the key point. Implicit means not an actual enum type, but, say, numbers with special meaning.
const int A = 1;
const int B = 2;
const int C = 3;
And a ...
6
votes
Accepted
Should an optional boolean function argument rather default to true or false?
I agree that you should go with what makes more sense semantically, but I also find that, when the boolean argument is optional, the thing that fairly often makes more sense when omitting it is for it ...
4
votes
Should an optional boolean function argument rather default to true or false?
You should choose the one that will favour the most common use of calling code.
eg
if(FileExists) //good
{
//do something to file
}
vs
if(!FileDoesntExist) //bad
{
//do something with file
}
4
votes
Accepted
Should I assign a default value for this property in the constructor?
Why allow the impossible?
I believe that I should be setting the Method property to string.Empty by default, and if the user doesn't supply the Method then the service won't execute (I.E. I'll check ...
3
votes
Should an optional boolean function argument rather default to true or false?
With the following it is clear that true should be the default value (especially with setVisible).
void setVisibility(boolean visible) { ... }
void setVisibility() {
setVisibility(true);
}
Below ...
3
votes
Accepted
Should default configuration for deployed services be set as per production usage?
There should be no default configuration.
Using the production configuration as default is problematic because
this config is necessarily incomplete (e.g. credentials)
this config might accidentally ...
3
votes
Accepted
Miroservices default value for Fallback scenarios
You're overthinking it.
A distributed cache's goal is to optimize performance, nothing more. If you expect data to always be cached, your design is flawed. You may not have the data for a bunch of ...
2
votes
What should be the last entry in a switch/case statement?
I remember early in my career writing a series of if else if statements which I thought covered all cases.
At the end I added:
else
{
Throw new Exception("THE IMPOSSIBLE HAPPENED!!");
}
Of ...
2
votes
Is it necessary for a boolean to be "false" by default?
Erik Uzureau and Cameron Yick provide some interesting insight on this article about this question. Their recommendation is for avoiding negative values whenever possible, but naming such that the ...
2
votes
Should an optional boolean function argument rather default to true or false?
If you have an optional argument, the argument should usually not be passed to the call. If you have an optional bool argument, I’d say 80% of calls should have no argument passed, and the default ...
1
vote
Accepted
Wrapper Auxiliary Method VS Default Arguments for Initialization: Pros/Cons
Consider using decorators. The original motivation for including decorators in the language is described in PEP-318.
An example below using a decorator to remember whether a method on an instance ...
1
vote
Should a CLI wrapper specify function defaults?
You should either duplicate the defaults, or store them in variables that can be used in both places.
Here's why: the compute function needs to know what the defaults are so that it can properly ...
1
vote
Accepted
Should default values be explicitly stated in configuration files for libraries or frameworks?
Ultimately I think this might be opinion based, but given that you are using a specific framework (Karma) and this framework has documentation, it is fine to omit default values.
An exception would ...
1
vote
Is it necessary for a boolean to be "false" by default?
Alternative approach would be to have an enum (or based on your programming language a type with only two possible values, but with more descriptive names then true/false)
public enum SoundState
{
...
1
vote
Should default configuration for deployed services be set as per production usage?
I would approach this from a risk-based stance.
Some development options can be detrimental or downright dangerous if set in a production environment. For those options, your default should be to set ...
1
vote
Is there a normal way to program a CLI script that overrides default parameters in python
/lib/doer.py shouldn't know about the default at all. Remove the default parameter and have /bin/runner pass in the correct config file to use.
If opts is a dictionary, use code like this:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
default-values × 19parameters × 3
c# × 2
javascript × 2
python × 2
coding-style × 2
coding-standards × 2
functions × 2
methods × 2
wrapper × 2
design × 1
java × 1
design-patterns × 1
database × 1
php × 1
programming-practices × 1
testing × 1
api-design × 1
microservices × 1
functional-programming × 1
naming × 1
language-agnostic × 1
node.js × 1
patterns-and-practices × 1
memory × 1