$set > $let - A word of advice

Don’t take this…

<$set name=my-name value={{{ [complex filter transclusion leading you astray] }}}>

And rewrite it like this…

<$let name=my-name value={{{ [complex filter transclusion leading you astray] }}}>

It’ll take you forever to find it when you’ve changed hundreds of them.

image

Unless, of course, you really do want two variables, one called name, the other called value.

All hail the mighty $log widget!

1 Like

Well, I’m likely the facepalm poster-child …

Giggles aside: I haven’t upgraded my TiddlyWiki instances yet, and was planning on moving from $vars to $let.

Now that I see how similar “let” and “set” look, way too similar-looking for my cognitive hiccups (I need more obvious visual cues to distinguish things), “let” won’t be appearing in any of my TiddlyWiki instances.

Thanks for sharing your story ! What don’t kill you make you stronger ???

Thanks for sharing, and I didn’t know log widget, I was always using

<$list filter="">
<<currentTiddler>>
</$list>

We used $set in 5.1.18 when we were working on Tiddler Commander!
(we is not a royal we :wink: it refers to several developers helped to implement commander)
$set at that time was a very powerful widget and lets us to implement complex logics!
Dynamic tables uses alot of $set widget!

Still I love it and I use it!

See also:

2 Likes

There is a saying: “Don’t fix it, if it ain’t broke.” … If the vars widget works in your code it will still do so with a new version.

If you write new code you can use the let-widget, but IMO there is no need to rewrite your existing code. …

The same thing is true, for the set-widget … except you have 3 or more of them nested … vars or let will likely make the code more readable. If you use <$set name=x filter="..." you should keep it, since it can’t be done in the exact same way with vars or let

just my thoughts.

2 Likes

Much! And that was the case here, for the most part – complexity is the enemy of comprehension. For a lone $set, a little further into the logic, I hadn’t made the complete conversion, and left it as noted above :poop:

And you’re right, there is such a saying, but like most sayings, it doesn’t capture all truth. There are many non-broken things we try to fix – coronavirus is working very successfully, for example :wink:

My intent in posting, was to $let folks know how easily the eye is deceived and not least because, the “broken” statement is perfectly valid code (just not what was intended). @Charlie_Veniot got it right away.

It’s vital - gone are the days when I struggled to de-nest complex code in my head. Here, I wrap $log in a macro to make it carry its call-site[1] so I can find them later and remove them easier:

\define log(msg) 
<$log 
  $$message="$msg$" (call-site goes here)
  $$all=yes
  $$filter="list of things I always want to see like currentTiddler transclusion etc" 
/>
\end

The call-site is _sv in the following screenshot:

[1] call-site: the location in the code where a call is made.

$set IS a very powerful widget.

1 Like

In relation to Set to Let, I would not try and change existing code to make use of let as a rule, so often when people revisit code, they can waste time introducing new errors, and at least you need to thoroughly test again.

Clearly vars was always somewhat limited and most likely let will be a better replacement moving forward in many cases. However sometimes if something’s behaviour is limited it immediately tells you something about the code, since vars can’t inherit the previous values, that is, there is no internal order dependency.

I would also suggest moving set to vars or let also only has some use cases, not for all cases. For example when nesting variables or setting only one variable, this differentiation is good, if for no other reason so you know what closed what. ie a set inside a let you will see </$set></$list></$let>

Its long being a convention for the close widget to not include any parameters but I have often wondered if it would help self documentation eg;

<$set name=varname value={{{ what ever }}}>
blah blah
</$set varname>

The above does not work;
The following should but I am not sure its reliable.

<$set name=varname value={{{ what ever }}}>
blah blah
</$set><!-- /varnname -->

Also let does not address emptyValue, index and subtiddlers, although there are equivalents they are less readable.

I expect I will still use vars in the particular case of setting variables for a macro or transclusion where there is no dependencies.

<$vars tiddlername="mytiddler" mode="update">
   <<macrocall>>
  or {{||transclusion}}
</$vars>

So if I see a $set or list of sets or a $let then I should expect interrelationships between variable’s.

Is there any other compelling reason to move from $vars to $let except as the need arises?

See a simple example of $let in Looking for Some Working Examples: Modifier Key - #4 by Mohammad