Skip to main content
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 ...
Kilian Foth's user avatar
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 ...
Laiv's user avatar
  • 15k
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 ...
Greg Burghardt's user avatar
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 ...
Filip Milovanović's user avatar
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 }
Ewan's user avatar
  • 84.6k
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 ...
Flater's user avatar
  • 59.5k
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 ...
Joop Eggen's user avatar
  • 2,639
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 ...
amon's user avatar
  • 136k
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 ...
Arseni Mourzenko's user avatar
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 ...
Ewan's user avatar
  • 84.6k
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 ...
Thiago Pereira Maia's user avatar
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 ...
gnasher729's user avatar
  • 49.4k
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 ...
Ben Cottrell's user avatar
  • 12.1k
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 ...
Robert Harvey's user avatar
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 ...
Greg Burghardt's user avatar
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 { ...
Fabio's user avatar
  • 3,176
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 ...
HorusKol's user avatar
  • 4,161
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: ...
Winston Ewert's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible