简体   繁体   English

部署友好代码

[英]Deployment friendly code

Is writing deployment friendly code considered a good virtue on the part of a programmer? 编写部署友好代码是否被认为是程序员的优点?

If yes, then what are the general considerations to be kept in mind when coding so that deployment of the same code later does not become a nightmare? 如果是,那么在编码时要记住哪些一般注意事项,以便以后部署相同的代码不会成为噩梦?

The biggest improvement to deployment is to minimize manual intervention and manual steps. 部署的最大改进是最小化手动干预和手动步骤。 If you have to type in configuration values or manually navigate through configuration screens there will be errors in your deployment. 如果您必须键入配置值或手动浏览配置屏幕,则部署中将出现错误。

If your code needs to "call home", make sure that the user understands why, and can turn the functionality off if necessary. 如果您的代码需要“回家”,请确保用户了解原因,并在必要时关闭该功能。 This might only be a big deal if you are writing off-the-shelf software to be deployed on corporate networks. 如果您正在编写要在企业网络上部署的现成软件,这可能只是一个大问题。

It's also nice to not have your program be dependent on too many environmental things to run properly. 如果没有让你的程序依赖太多的环境事物来运行正常,这也是很好的。 To combat this, I like to define a directory structure with my own bin, etc and other folders so that everything can be self-contained. 为了解决这个问题,我喜欢用我自己的bin等文件夹和其他文件夹来定义一个目录结构,以便一切都可以自包含。

The whole deployment process should be automated to minimize the human errors. 整个部署过程应自动化,以尽量减少人为错误。 The software should not be affected by the envrionment. 该软件不应受到环境的影响。 Any new deployment should be easily rolled back in case any problem occurs. 如果出现任何问题,应轻松回滚任何新部署。 While coding you should not hard code configuration values which may be different for each environment. 在编码时,您不应该对每个环境可能不同的配置值进行硬编码。 Configuration should be done in such a way that it can be easily automated depending upon enviroment. 配置应该以这样的方式进行,即根据环境可以轻松实现自动化。

Client or server? 客户端或服务器?

In general, deployment friendly means that you complete and validate deployment as you complete a small story / unit of work. 通常,部署友好意味着您在完成一个小故事/工作单元时完成并验证部署。 It comes from continual QA more than style. 它来自持续的QA而不是风格。 If you wait till the last minute to build and validate deployment, the cleanest code will never be friendly. 如果你等到最后一分钟来构建和验证部署,那么最干净的代码永远不会友好。

Everything else deployment, desktop or server, follows from early validation. 其他所有部署,桌面或服务器都遵循早期验证。 You can add all the whacky dependencies you want, if you solve the delivery of those dependencies early. 如果您尽早解决这些依赖项的交付,则可以添加所需的所有可疑依赖项。 Some very convenient desktop deployment mechanisms result in a sand-boxed / partially trusted applications. 一些非常方便的桌面部署机制导致沙盒/部分受信任的应用程序。 Better to discover early that you can't do something (eg write your log to c:\\log.txt) than to find out late that your customers can't install. 最好尽早发现你不能做某事(比如把你的日志写到c:\\ log.txt),而不是发现你的客户无法安装。

I'm not entirely sure what you mean by "deployment friendly code." 我不完全确定“部署友好代码”是什么意思。 What are you deploying? 你在部署什么? What do you mean by "deploying"? “部署”是什么意思?

If you mean that your code should be transferable between computers, I guess the best things to do would be to minimize unnecessary (with a given definition of "unnecessary") dependencies to external libraries, and document well the libraries that you do depend on. 如果你的意思是你的代码应该可以在计算机之间转移,我想最好的办法是尽量减少对外部库的不必要的(使用给定的“不必要”的“不必要”的依赖),并记录你依赖的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM