Comments (11)
see https://groups.google.com/group/play-framework/browse_thread/thread/9857d18dd7328bf2?fwc=1 for some background on this issue. You can always define a Config with your defaults in code, myDefaults=ConfigFactory.parseMap(), then conf.withFallback(myDefaults), if reference.conf doesn't work in a given situation. Defaults passed to the getter inherently mean cut-and-paste code as soon as you get a setting in two places, right? better to ensure the Config falls back to defaults.
from config.
defaults in code is a bad practice.
from config.
I’d like to also put my weight in on the “no defaults in code” side. You can always include a reference.conf
or application.conf
for this purpose.
from config.
My vote is also on no defaults in code.
reference.conf is great for documentation.
from config.
to be clear, I don't have a plan to add defaults to getters. but I did want to be sure @sheki's use case is covered by a reference.conf and/or putting a withFallback in code. basically want to be sure the issue is not knowing about those approaches (vs those approaches not working in some way)
from config.
I think the choice of using reference.conf or defaults in code should lie with the user.
from config.
You can already do that using config.withFallback(ConfigFactory.parseString(mydefaults))
or using hasPath()
(where the latter is really only for things where the information whether it was configured or not is actually valuable/of interest).
from config.
I disagree, by making it hard to do the wrong thing, you foster people to do the right thing. Fostering people to do the right thing improves the world, fostering them to do the wrong thing makes it worse.
from config.
Always interested in use-cases that aren't covered by the current API, but as best I can think of, withFallback and reference.conf cover all the cases. I don't want to add another way to do it that involves a couple dozen extra methods and most would consider bad practice. At least not without some very strong rationale that I'm not yet aware of.
from config.
Any clarification as to why "defaults in code" is considered bad practice?
from config.
Because they get sprinkled all over the code base, you risk having to repeat the code in several places which means risk of different defaults for the same value, it also leads to defensive code because no-one can trust the config, it is also hard to change the defaults without recompiling the entire project.
from config.
Related Issues (20)
- Find a StackOverflowError in config
- Find a StackOverflowError in config
- Find a StackOverflowError in config HOT 1
- underscore characters HOT 2
- Problems with com.typesafe/config and maven-dependency-plugin
- introduce method accepting a list of Objects to add a value
- Should this project be explicitly considered as deprecated/not supported? HOT 29
- Community fork? HOT 7
- Resolving Variable Substitutions Between Multiple Config HOT 1
- Something error when use com.typesafe.config API convert conf file to scala bean class
- withFallBack is not adding value if not present
- how to load the config with substitution details HOT 3
- Add info about which signing keys will be used for published artifacts.
- Cannot provide environment variables programmatically
- Rendering partially resolved appended array results in invalid configuration HOT 1
- Inconsistent behavior with Overflow/Underflow and Exceptions
- Regression in environment variable reading behavior HOT 2
- Add a module info HOT 6
- Question about `ConfigFactory.systemProperties()` on windows HOT 1
- When rendering unresolved ConfigConcatenation, whitespaces are erroneously included
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.