Encourage avoidance of duplicated code? #37
Replies: 3 comments
-
I think general development practices are out of scope for the docs site (there are already many great resources out there for this). Examples should be correct and not directly harmful, such as promoting insecure practices, but otherwise their primary purpose is educational. I've tried to create examples that you can easily copy-paste into your editor and start modifying, which I find to be easier with (reasonably) duplicated code. Your second point sounds like what I'm hoping to do with the Examples section. Basically more involved examples that combine several aspects of plugin development to show how they work together. Could we create another example like the "Insert link" one that includes context menus? Maybe together with some vault operations? One idea could be to add a menu item that lets you copy the contents to the clipboard? That would touch on at least three different features and could demonstrate how you'd do it in a more realistic setting? |
Beta Was this translation helpful? Give feedback.
-
I totally agree with all that! |
Beta Was this translation helpful? Give feedback.
-
Related to this topic, the |
Beta Was this translation helpful? Give feedback.
-
I’m not sure how much you want to focus on general good development practices…
But when I see the “Print file path” example in Context Menus I have the urge to refactor to remove the duplicated code… For lots of reasons, including foreseeing the inevitable future bug-fix or new feature where the two accidentally become inconsistent.
The current code is good from an explanatory perspective, though… So I wonder whether it’s worth a second example that shows doing the same thing, but having the common code moved to something like a local helper function - named so that it either creates the one menu item - or to add all the menu items, as the plugin grows.
Beta Was this translation helpful? Give feedback.
All reactions