macros vs. transclusions?

101 views
Skip to first unread message

HC Haase

unread,
Apr 22, 2020, 7:57:36 AM4/22/20
to TiddlyWiki
I am in the process of updating on of my plugins and I wondered

if you don't use any parameters, is there any point in making a macro instead of transcluding a snippet of code?

is there a best practice? Or could anyone give me some pro/cons? I wouldn't want to complicate things unnecessarily.


Jed Carty

unread,
Apr 22, 2020, 8:01:12 AM4/22/20
to TiddlyWiki
In practice it is just preference.

In extreme cases where you have hundreds of macros and make them all global you can have some problems because all of the macros have to be loaded with import variables if they are used or not, this is done without your intervention.
So if you have lots and lots of macros it can cause some more overhead than transclusions.

But the number of macros you would need to have a noticeable effect is almost certainly outside of what is reasonable to do.

PMario

unread,
Apr 22, 2020, 8:27:11 AM4/22/20
to tiddl...@googlegroups.com
Hi,
As Jed pointed out, it's about "your preferences". ... But I think, if others need to use your plugins, macros are probably simpler for them. They produce more "descriptive" code. eg:

{{test||xx}}  ... means transclude the tiddler named: test and use the template: xx to display the content.

<<show tiddler:"test" template:"xx">> .. imo, doesn't need additional description, for users to make sense of it.

While the first one is less characters, the second one describes itself. If the macros is global you need to take care, that your names are "unique" enough, to avoid "name clashes"

Just some thoughts

have fun!
mario

HC Haase

unread,
Apr 24, 2020, 2:41:57 AM4/24/20
to TiddlyWiki
Thanks for the input

I think Mario have a good point. I have seen (and adopted) Mohammad put documentation of the macro after the /end. This makes it much easier to reuse the code.

--example of macro doc--


TonyM

unread,
Apr 24, 2020, 5:38:52 AM4/24/20
to TiddlyWiki
HC,

A Few related points

A New tag exists SystemTag: $:/tags/Macro/View

You can use import variables to bring macro definitions into a tiddler rather than the tags/macro

I backup my macro writing with a field macro-macroname containing the syntax, on tiddlers where I define them
<<macroname [filter]>> where filter defaults to [all[current]]>>
 I have a list that shows the macos and their syntax

In my documentation I like to present the macrocall version as well especially if it may be needed.
<$macrocall $name=macroname filter={{!!filter-field}} />

If a template needs to act on a specific tiddler you can use the {{tiddlername||templatename}} format, but this is often just as well serviced by a viewtemplate item. Although I have reused this as {{parameter||templatename}} where the parameter becomes currentTiddler in the template, and of course there is {{||templatename}}

There are so many ways to achieve something similar that I think the best approach is that it is ultimately self documenting. For this reason I would be less likely to use transclusion and more likely to use macros except where I have built a "work horse". 

For example I have created a template called {{||$:/autotags}} which uses the currentTiddler to create a tag name $:/tags/currentTiddler that transcludes all tiddlers tagged $:/tags/currentTiddler  that is, it remains an active transclusion, but a transclusion none the less.

Ie curly braces tend to represent transclusions, macro's tend not to, just macros. It can reduce the complex for the memory.

I hope this help informs your thinking

Regards
Tony
Reply all
Reply to author
Forward
0 new messages