Coder Social home page Coder Social logo

Comments (4)

viktorklang avatar viktorklang commented on July 4, 2024

Never, never, never put defaults in code. That's the entire idea with the Typesafe Config library. So huge 👎 on this. Put your defaults in a reference.conf.

from config.

havocp avatar havocp commented on July 4, 2024

See issue #14. Just check out the example app and library in the source tree (https://github.com/typesafehub/config/tree/master/examples) to see the suggested way to do it (reference.conf). But if you for some reason don't want an external file, you still should not use the hasPath pattern; instead, create a Config object that contains all your defaults, put that config object in one place, and then when you load config do "loaded.withFallback(myDefaults)" to get the final config. Then you don't need hasPath because you know you've forced the settings to exist. The bottom line is, add defaults to and validate your config up-front when you load it, throw exceptions or do fixups at that central load location, then pass around an already-validated known-good config.

The time to use hasPath is if null/missing is actually meaningful rather than a screwup or missing default. For example if an unset password means "don't use a password" then you need to do a hasPath in that case.

from config.

havocp avatar havocp commented on July 4, 2024

to be completist for the archives, the other reason not to support these "with default" overloads is that there are a lot of them (1 getFoo and 1 getFooList per type). so since there's already a way to specify defaults in code (withFallback) it doesn't seem worth adding all that. also, when wrapping the API in Scala several people have made these return Option which is not what I'd suggest for the same reason.

from config.

 avatar commented on July 4, 2024

wow, guys, you've got some religion going on here! :-)

come on, I was merely checking if you are still around - the previous 3 requests got no reaction from you :-)

apart from that - fine, I am now a new convert and an adept of the church of the saint havoc,
and will faithfully practice my default config files every morning and night;

cheers!

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.