当可以使用库函数代替时,使用system()函数是一种不好的做法吗?为什么? [英] Is it bad practice to use the system() function when library functions could be used instead? Why?

查看:106
本文介绍了当可以使用库函数代替时,使用system()函数是一种不好的做法吗?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,正在开发的应用程序需要一些功能,这些功能可以通过对命令行程序或使用库进行系统调用来实现.假设效率不是问题,那么简单地对程序进行系统调用而不是利用库是否是错误的做法?这样做的缺点是什么?

Say there is some functionality needed for an application under development which could be achieved by making a system call to either a command line program or utilizing a library. Assuming efficiency is not an issue, is it bad practice to simply make a system call to a program instead of utilizing a library? What are the disadvantages of doing this?

为了使事情更加具体,这种情况的一个示例是需要从Web服务器下载文件的应用程序,为此可以使用cURL程序或libcURL库.

To make things more concrete, an example of this scenario would be an application which needs to download a file from a web server, either the cURL program or the libcURL library could be used for this.

推荐答案

除非只为一个操作系统编写代码,否则无法知道您的系统调用是否可以正常工作.当系统更新或操作系统升级时会发生什么?
如果有可以执行相同功能的库,则从不使用系统调用.

Unless you are writing code for only one OS, there is no way of knowing if your system call will even work. What happens when there is a system update or an OS upgrade?
Never use a system call if there is a library to do the same function.

这篇关于当可以使用库函数代替时,使用system()函数是一种不好的做法吗?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆