How do you share configuration information or business rules between languages

坚强是说给别人听的谎言 提交于 2019-12-28 15:34:29

问题


I'm looking for best practices for using the same data in different places without repeating yourself - this could include configuration or business rules.

Example 1. Data validation rules where you want to validate on the client using javascript, but you want to make sure by validating on the server.

Example 2. Database access where your web server and your cronjobs use the same password, username.

Ease of processing and a human-readable solution would be a plus.


回答1:


Encode your data in JSON. There's a JSON library for pretty much any language you'd care to think of, or if not, it's pretty easy to code one up. If JSON is not enough, perhaps look at YAML.




回答2:


XML is pretty globally used. Easy to read, easy to write, and human readable. If you're concerned about the space overhead (which you actually aren't if you want human readable) then just compress it before you send it out, XML compresses quite well.




回答3:


See answers to this question. I think they are applicable here, especially the one with a DSL.




回答4:


As much hate as they get, for sharing data validation rules, I'm going to have to say Regular Expressions.

I know, I know, everyone hates them, but they are (generally) language-agnostic.




回答5:


  1. Use O/S Environment Variables (envvars) to store application configuration info (such as db passwords)

  2. Validation rules often require logic. You could write your rules in JavaScript, and then run them in the browser, server (using Nashorn), and database (PLV8 with Postgres).



来源:https://stackoverflow.com/questions/239832/how-do-you-share-configuration-information-or-business-rules-between-languages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!