Rubberduck: Snippets

Created on 13 Mar 2019  ·  8Comments  ·  Source: rubberduck-vba/Rubberduck

Please, consider adding option for inserting a snipets like product vbeTwister4vba does.

duplicate enhancement

Most helpful comment

@SmileyFtW, that's actually a candidate for a template (cf #4549 ).

All 8 comments

@kostas505 thanks for the suggestion! As we are discussing the pros and cons of implementing this feature, a number of questions arise:

  • What kind of code would be a "snippet"? Any arbitrary user code? Any length?
  • How would this feature differ from what would essentially be a "copy-pasta" enabler?
  • Would automatic block completion (if...end if, for...next, etc.) reduce the need for snippets?
  • Would more class/module templates reduce the need for snippets?

We're finding there are several cons and little pros to a snippets feature, seeing how easily it can be abused, notably to enable poor coding habits, including copy/paste-coding and cargo-cult error handling, to name a few common coding practices that work against what Rubberduck is promoting.

We could all be wrong and this might be a killer feature, so we need help understanding what makes snippets a useful feature. I for one, have never used them, be it in VB6, VBA, or C#. I do extensively use automatic block/scope completion in Visual Studio though - is that what you had in mind?

I have used this feature in MZTools and found it useful. I can think of one snippet that would be one I might set up:

‘@Folder(“Models”)
Private Type TModel
     Parent As IObjectReference
End Type

Private this as TModel

Private Sub Class_Initialize()
    Set this.Parent = New IObjectReference
End Sub

Private Sub Class_Terminate()
    Set this.Parent = Nothing
End Sub

Public Property Get Parent() As SpecificObject’ change declaration to appropriate object
    Set Parent = this.Parent.object
End Property

Public Property Let Parent(ByVal object As SpecificObject’) ’ change declaration to appropriate object
    Set this.Parent = ObjectReference.Create(object)
End Property

@SmileyFtW, that's actually a candidate for a template (cf #4549 ).

@SmileyFtW thanks! as @bclothier noted, this does reinforce the impression that class/module templates are a better idea though... what do you typically use MZ-Tools snippets for?

Based on the description of snippets on the vbeTwister4vba website here, the feature seems to be more like customizable auto-completion.

@comintern aaaah! well, that's already on the roadmap then, albeit not exactly like that; looks like a combination of what we'll have as block completion and "autocorrect".

@kostas505 I'll be closing this issue, since this functionality is already on the roadmap. Thanks for the suggestion!

Basically, what i have in mind is how to reduce time in writing the same lines of code over and over again. For example: shortcut key combination for inserting skeleton for subs or functions with basic error handling code.
Anyway, thank you for prompt answer and for great work done so far.

@SmileyFtW thanks! as @bclothier noted, this does reinforce the impression that class/module templates are a better idea though... what do you typically use MZ-Tools snippets for?

Before RD I used MZTools to hold all my bad habits... I have moved away from MZT in favor of RD. Henceforth, I will look into module templates to hold my newly acquired better (RD) habits...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

retailcoder picture retailcoder  ·  3Comments

retailcoder picture retailcoder  ·  3Comments

retailcoder picture retailcoder  ·  4Comments

ghost picture ghost  ·  3Comments

susnick picture susnick  ·  3Comments