How do you decide what to use: UDF or custom tag?

WACK says:

If you feel that you need a lot of arguments, consider creating a CT instead.

...

CT scans are significantly more powerful and flexible than user-defined functions. Try using UDF for simple questions ... Use CT and Components for more processes, especially those that you might rather consider discrete actions than a simple "massage"

Good, but how do you usually make decisions? It is interesting to know real practice and examples.

For me, this happens when a function has many optional arguments, so I have to call them myFunc (arg1 = "foo", arg2 = "bar"). Sometimes the syntax <cfmodule>just becomes more readable, but not always.

Another reason is that I don't like long (say, more than 2 code screens) UDF.

But all these thoughts are very subjective, so I'm interested in the opinions of other people. Maybe the rule is better for this?

Thanks in advance.

+3
source share
7 answers

, , , , . , , , "" - , . UDF . , , 8 CF, . , , , .

UDF, , , , UDF ( , )? , UDF , , , , , , , .

: , CFWACK ( ) ?

+5

, , UDF, . . UDF, , , ( , ).

UDF

<cfif myUdf(myVariable)>

, .

<h1>Order Page</h1>
<cf_basket_nav>
  <ul>
  <cfloop ...>
    <li>
    <cf_basket_item item="#items[i]#">
    </li>
  </cfloop>
  </ul>
</cf_basket_nav>

, CFC "utils" UDF.

+2

udfs cfc , , , , . , :

<cfmenubar ... >
  <cfloop array="menuitems" ...>
    <cfmenubaritem url="#i.url#">
      #i.label#
    </cfmenubaritem>
  </cfloop>
</cfmenubar>

, , , dhtml , , . cfassociate , "" , executemode = "end" . .

, , ... , , = ", html (, <a> ), - html ... , href target , PDF ( ) ... slick! html-, Dreamweaver , , - coldfusion, html - , " ", .

, ( ), chunck html... thistag.generatedcontent ""

... , , cfcs, ... (, , cfcs)

+1

cfmodule ; cfinvoke .

, cfimport , , : open/close .

, , .

0

: HTML CT. , , . , CT.

, , cfscript. UDF , cfscript-ed. UDF.

0

UDF. , , .. ..

- , CFC . OO-. CFC , , .

0

Not sure why I got into this template, but overall I use custom tags (always with cfmodule) for everything that outputs HTML and UDF for everything that just returns simple data / objects. I understand that UDFs can draw conclusions as well, but I don't like my functions to have any side effects, and that seems to be one thing. For the same reasons, I now use custom tags wherever I used to use cfinclude, since they provide data encapsulation.

0
source

Source: https://habr.com/ru/post/1704800/


All Articles