Coder Social home page Coder Social logo

Comments (11)

havocp avatar havocp commented on July 24, 2024

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.

viktorklang avatar viktorklang commented on July 24, 2024

defaults in code is a bad practice.

from config.

rkuhn avatar rkuhn commented on July 24, 2024

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.

patriknw avatar patriknw commented on July 24, 2024

My vote is also on no defaults in code.
reference.conf is great for documentation.

from config.

havocp avatar havocp commented on July 24, 2024

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.

sheki avatar sheki commented on July 24, 2024

I think the choice of using reference.conf or defaults in code should lie with the user.

from config.

rkuhn avatar rkuhn commented on July 24, 2024

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.

viktorklang avatar viktorklang commented on July 24, 2024

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.

havocp avatar havocp commented on July 24, 2024

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.

LeifW avatar LeifW commented on July 24, 2024

Any clarification as to why "defaults in code" is considered bad practice?

from config.

viktorklang avatar viktorklang commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.