Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using js files for configuration rather than json #4

Open
fresheneesz opened this issue Oct 17, 2017 · 8 comments
Open

Switch to using js files for configuration rather than json #4

fresheneesz opened this issue Oct 17, 2017 · 8 comments

Comments

@fresheneesz
Copy link

Static formats like XML and JSON will inevitably introduce complexity in other tools. JSON isn't composable (you can't import parts of your configuration from somewhere else). JSON doesn't have comments. JSON can't take advantage of symmetry in your configuration file. Read this: https://arp242.net/weblog/json_as_configuration_files-_please_dont

NodeOS is based around javascript. Why not just use pure javascript as your configuration files?

@mitsukaki
Copy link
Contributor

@fresheneesz how would this look? Would it be a JS file that could be loaded like a module and contained the configuration? What do you have in mind? This is definitely an interesting proposal.

@fresheneesz
Copy link
Author

Would it be a JS file that could be loaded like a module and contained the configuration?

Yeah exactly. Something like this:

module.exports = {
   port: 38597  // this is the magic port
}

I don't have insight into how often JSON files are used in NodeOS in general - looks like maybe PalmTree itself doesn't care whether your config is in a JSON file or otherwise, but I think raw js files as configuration would be good to advocate for the project as a whole.

@mitsukaki
Copy link
Contributor

@fresheneesz sounds like a cool idea! @piranna what do you think on the matter? Would this be a simple alteration?

@piranna
Copy link
Member

piranna commented Oct 26, 2017

Sorry for radio silence, too much busy with work during last months and for the coming.

In short: possible? yes, probably is already available since we are using require() to read the config JSON files, so go for it if you want. Condone? No, Javascript files add a lot of complication and ugliness regarding to static config files, specailly simple ones like JSON, so we are not going to start using Javascript files for config as default, they only makes sense for more advanced, "dynamic" configuration, so the door is still open for it. If you just only want comments, I will greatly apreciate if you add optional support for json5, but no, I will not start to change JSON config files for Javascript scripts.

@fresheneesz
Copy link
Author

@piranna

Javascript files add a lot of complication and ugliness regarding to static config files

How so? Isn't it just an extra module.exports = {} in there? Is that tiny extra boilerplate not worth having the ability to add comments, objects that are easier to read and write, and the ability to do more interesting things if/when the need arises?

add optional support for json5

json5 looks great, but I still don't understand why pure JS is a bad choice for basic static config files.

@mitsukaki
Copy link
Contributor

@fresheneesz The only assumption that I can make is that JSON can be parsed more efficiently than JS. If you would like comments, we can look into implementing json5?

@fresheneesz
Copy link
Author

@lite20 Thanks for the thought, but parsing efficiency is not going to be a concern with config files. But sure, why not add in json5 if you're gonna use json.

@piranna
Copy link
Member

piranna commented Nov 17, 2017

Sorry for the radio silence, during last months I have been very busy with several simultaneous jobs and no spare time. In fact, I'm writting this on the train going to PortAventura park a free weekend as late summer holidays.

if/when the need arises?

KISS principle. If/when the need arises you can opt-in to use Javascript-based config files, nobody is preventing that, but by default, we'll only support stateless JSON config files. If you need more advanced features, use the project as a dependency and directly use its API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants