合理的默认配置

发布于 2024-07-18 03:06:11 字数 320 浏览 2 评论 0原文

我最近开始使用 Ruby on Rails,它更倾向于约定而不是配置,并依赖合理的默认值将应用程序的各个方面联系在一起。

我在想,如果在各种框架的通用配置中使用这种合理的默认配置的概念,那么它可能会很有用,那么它可能会节省一些开发麻烦。

例如,在 .net 应用程序中,我通常希望使用企业库异常处理块在 Windows 事件日志中记录异常,但如果我没有在配置文件中明确说明我想要的行为,那么 EL 会抱怨。 我认为,如果它找不到自定义配置,那么它应该恢复到合理的默认配置,例如在事件日志中记录我的异常。

对于框架在其配置中采用的概念来说,这是一个好还是坏的概念?

I've recently started to play with Ruby on Rails which favours convention over configuration and relies on sensible defaults to tie various aspects of the application together.

I was thinking that it might be useful if this concept of sensible default configuration was used in general configation for various frameworks then it might save some development headache.

For example, in a .net app I usually want to log an exception in the windows event log using enterprise library exception handling block but if I don't explicity state the behaviour I want in a config file then EL will complain. I think that instead, if it can't find custom configuration then it should revert to a sensible default configuration, like logging my exception in the event log.

Would this be a good or bad concept for frameworks to adopt for their configuration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2024-07-25 03:06:11

我经常使用一个可以完成这件事的框架。 我对这种工作方式的麻烦在于:

  • 框架变得拥有过多的配置键,而这些配置键实际上从未在配置文件中使用/设置。
  • 软件的行为有时会变得隐式,我想明确地将系统设置为以某种方式运行,而不是由于“默认”而使其在其他代码路径上回退。
  • 配置密钥中的拼写错误可能会导致在弄清楚发生了什么情况之前进行很长时间的诊断会话。

当忘记设置配置值时,我宁愿让软件告诉我,而不是假设我可能根本不追求的某种形式的行为。

我更喜欢一个“模板”配置文件,在其中我可以更改我想要的内容,并将未更改的设置作为默认设置。

弄清楚软件在调试时选择哪种约定也可能会浪费大量时间。

I work a lot with a framework that does this exact thing. My trouble with this way of working is that:

  • the framework grew to having an excessive amount of configuration keys that are actually never used/set in a configuration file.
  • behavior of the software becomes implicit sometimes, I want to explicitly set the system to behave a certain way instead of having it fallback on some other code path due to a 'default'.
  • a missed typo in configuration key may result in a very long diagnostic session before figuring out what is going on.

When forgetting to set a configuration value I rather have the software tell me, instead of assuming some form of behavior that I might not at all be after.

I'd prefer a 'template' configuration file in which I change what I want and have the unchanged settings serve as the default.

Figuring which out which convention the software picked when debugging can be a lot of time wasted also.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文