Is It a good Idea to use velocity macro to create UI components, what's about performance and code maintability
for example, in place of
<input type="text" name="$name" value="$value" />
we will write
#text($name $value)
Join Stack Overflow to learn, share knowledge, and build your career.
It is certainly convenient if you have branching logic or long html that you want to simply hide. Suppose you want a generic navigation button formatter, you only need to change the code in one place. IMHO, For refactoring it is easier, for portability and new team-members, maybe harder.
Here is a sample code I use that illustrate this:
#macro( viewCtrlButton $butId $butText $style) ##style is optional
##configuration phase
#if ($style == "save") #set($type = "icon-buttons cat-save")
#elseif($style == "cancel") #set($type = "icon-buttons cat-cancel")
#elseif($style == "next") #set($type = "buttonz but_naviR")
#end
#if ($butId.contains("."))
#set($link = "super_link")
#else
#set($link = "submit_link")
#end
##the actual code to construct
<a id="$butId" href="#" class="$type $link">
<span> $butText </span>
</a>
#end
There's no "good" or "bad", there's "appropriate for the circumstances".
Unless there's a lot of logic involved, or a large amount of simplification, I would not simply replace standard tags with a macro or template--I'd need enough functionality to wrap up to make the extra work, extra time, and extra cognitive load worth it.
("Cognitive load" just means that if I'm looking at the template file it'll take me longer to completely understand what it's doing if I have to look up the macros. That's not necessarily bad, and if I know the app's code, it's not relevant.)