创建使用其他函数的函数是不是很好? [英] is it good practice to create functions which use other functions that you built?

查看:90
本文介绍了创建使用其他函数的函数是不是很好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我很想知道这样做是否合适,因为它使得代码的可移植性降低了。



谢谢 解决方案

非常好的练习。 b
$ b

它被称为代码重用,这就是编程的全部内容。



至于你的观点, ,只有在汇编等非常低级的语言中才有意义,即便如此,它也使得它更具可移植性,因为您可以将特定于平台的代码分离到函数中。

良好的代码由小而易懂的函数组成。有些人说,超过30行的函数太长。


Is it good practice to create functions which use other functions that you built?

I was wondering if it was good to have this since it makes code less portable.

Thanks

解决方案

Very good practice.

It is called code reuse and this is what programming is all about.

As for your argument about it making "code less portable", that only makes sense in a very low level language such as assembly, and even then it makes it more portable as you can isolate platform specific code into functions.

Good code is made of small, understandable functions. Some people say that a function that is longer than 30 lines is too long.

这篇关于创建使用其他函数的函数是不是很好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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