从函数返回值而不是返回void有什么好处吗?

Eri*_*air 1 oop coldfusion return function return-value

我主要使用ColdFusion,一种非编译语言,但这是所有语言的一般问题.

我正在使用getter/setter以及CRUD方法创建对象.这是一个示例:

<cffunction name="getPeriodStartDate" output="false" returntype="Numeric">
    <cfreturn VARIABLES.PeriodStartDate />
</cffunction>

<cffunction name="setPeriodStartDate" output="false" returntype="Void">
    <cfargument name="PeriodStartDate" type="Numeric" required="true" />

    <cfset VARIABLES.PeriodStartDate = ARGUMENTS.PeriodStartDate />
</cffunction>

<cffunction name="getDollarAmount" output="false" returntype="Numeric">
    <cfreturn VARIABLES.DollarAmount />
</cffunction>

<cffunction name="setDollarAmount" output="false" returntype="Void">
    <cfargument name="DollarAmount" type="Numeric" required="true" />

    <cfset VARIABLES.DollarAmount = ARGUMENTS.DollarAmount />
</cffunction>


<cffunction name="read" output="false" returntype="Query">
    <!---
    READ QUERY
    --->

    <cfreturn _qData />
</cffunction>

<cffunction name="create" output="false" returntype="Void">
    <!---
    INSERT QUERY
    --->
</cffunction>

<cffunction name="update" output="false" returntype="Void">
    <!---
    UPDATE QUERY
    --->
</cffunction>

<cffunction name="delete" output="false" returntype="Void">
    <!---
    DELETE QUERY
    --->
</cffunction>
Run Code Online (Sandbox Code Playgroud)

显然,get方法和read()方法将返回一个值.

但是,让其他方法返回一个值有什么好处 - 也许是一个布尔值?

我在的Flex/ActionScript中工作,记住,在大多数情况下,我需要从方法的变量,以防止从处理下一行代码,返回一些值,并设置为结果:

function myFunc() {
    x = getSomething();

    y = getSomethingElse(x);
}
Run Code Online (Sandbox Code Playgroud)

Hen*_*nry 5

如果您返回this您的安装者,您可以链接安装者.我认为CF10访问器this默认返回启用链接.

我读过void一段时间后返回会更有效率,但我不确定它是否真的存在.我怀疑差异会很明显.