函数参数变量的命名约定? [英] Naming conventions for function parameter variables?

查看:109
本文介绍了函数参数变量的命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有命名约定或关于如何命名函数参数的准则?

Is there a naming convention or maybe some guideline on how to name function parameters?

从永远开始,我就一直这样:

Since forever, I have been doing it like this:

function divide( $pDividend, $pDivisor )
{ ... }

这样,我将始终知道哪些变量作为参数传递.

That way I'll always know which variables were passed as parameters.

(这是PHP,但它应适用于大多数编程语言)

(This one's PHP, but it should be applicable to most programming languages)

是否有一个主要的理由反对?

Is there one major reason against this?

是否有更好的方法可以做到这一点?或者最好是避免使用这种命名方案?

Is there a better way to do this or is it probably best to just avoid such naming schemes?

推荐答案

如果:

  1. 您的函数/方法编写得很好,并且简短(应该是应该的)
  2. 变量名称具有足够的描述性

不需要这种做法.

如果您需要此代码,则意味着编写的代码可读性不强(函数/方法太长),隐式变量/函数名称,错误的OO操作,快捷方式,代码负担等:)

If you need this, it means that the code written is not readable enough (functions/methods too long), cryptic variable/function names, bad OO practices, shortcuts, code debts, etc. :)

因此,这表明需要重构/改进代码.

So it would be a signal that the code needs to be refactored/improved.

这篇关于函数参数变量的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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