re: Code snippets or nah? VIEW POST


I love snippets--they help me write more consistently and quickly, eliminate some errors, and leaves more mental CPU and enjoyment for me to spend on writing the code I care about and want to focus on. I try to avoid them in a language until I'm comfortable enough to tell where I would want them, and I personally won't use them unless I know what I am... snippeting?..., and usually I prefer writing my own regardless.

Some are trivial and I don't give a second thought too--stuff like a barebones HTML skeleton, or for public static void main(String[] args){...} in Java, etc etc. Some are to prevent mistakes are quick for me to make--if I'm doing Javascript and adding event listeners, I'd just as soon type addevi and expand it out so I don't forget the last parenthesis after the anonymous function (which at least now is how I usually write them, until I know if I'm going to be reusing it), etc etc.

Some stuff is for consistency--I have one set up for forms, where I type labin and it expands into the label, the input (defaulted to text), and all I have to do is type in what I want in the name spot, and it prepopulates the ID and label content for me as well. Stuff like that I super recommend, because it helps so much to keep things consistent--I have fallen into a rhythm for my naming conventions for forms (this past semester was PHP and MySQL, so all the forms ever), and like things super explicit, and know that my id attribute will almost certainly be whatever the name is with _id appended, and using a snippet means I'm typing that once and it populates it the way I expect it.

At the end of the day, I feel like snippets are just autocomplete for variables and functions with a lot more layers and customizability; same way I embrace autocomplete to make sure I'm not suddenly calling the method calculateTotal instead of calculateTotals, I'm all for snippets and anything else that outsources details that human brains largely suck at to the computer, so that the human brains can do what they're good at, the actual coding parts.

I also appreciate them for coursework where I know the teacher wants a certain comment style to align with a certain method format, for example, and I can get that set up and make sure it matches right off the bat.

Code of Conduct Report abuse