Backlinks (aka Incoming Links) revisited: DTTG

Thanks for the feedback, @chrillek. Indeed, this script is not optimized. I took a script by Bernardo_V that took one file and added backlinks to it, and simply slapped a repeat loop around it to work down a (potentially large) list of files. So things that for a single file update are completely irrelevant in terms of speed suddenly can become important.

Are you sure that you need the links sorted as per set theList to my sortlist(theList)? If not, you might just get rid of this line. Which might also make things run faster.

Easy to check! Just one line to comment out. I measure no improvement at all, despite having a few files with 20 or more backlinks that would require heavy sorting. On top of that, yes, I am sure that I want the links sorted!

I’d use a try … on error … end try block around the repeat ... end repeat loops

I commented out all the try instances and see not change in speed. To be honest, I’d be surprised if they made such a big difference, in code that undertakes such heavy operations such as calling a DT search in a loop. And note that some do have a useful function: For example, if a folder is included in the selection, the try...on error will fix that in part 1, without it the script will fail. For this to work, the try has to be inside the loop.

I don’t see why you’d put a set operation in a try block without a corresponding error handler

Yes, oversight during copy/paste.

The rest of your comments are more about choices and attitudes:

Instead of popping up windows with display notification , you could use log message for a less intrusive way to follow progress. The messages will then appear in DT’s log window.

Huh? Why not? Let this script run in DT, switch to a different virtual desktop to do something else, and get a nice system notification. Why should I have to go back to the DT log window? Comment it out, if you don’t like it.

I’m not sure why you’d use HTML entities (   in a non-HTML file)

To get rendered extra whitespace into Markdown source? If you use " | " (two whitespaces on each side of the vertical bar), Markdown and HTML will simply ignore anything beyond a single whitespace (because they are typesetters, not typewriters). Futhermore, HTML is entirely legal content of a Markdown file. How else would you for example enable MathJax rendering on an individual file by file level? Having said this, I now changed my script to put each link on a new line. I think I like that better.

Personally, I find comments stating the obvious (“return theName” and the like) more irritating than helpful. They make the script a lot longer than necessary and it’s very difficult to weed out the useless comments.

I should have removed those before posting. Those are not comments, but commented-out code; poor-man’s debugging, so to speak. I apologize for irritating readers :slight_smile: