Live data from Hacker News

Ask HN: Does anyone still use code snippets?

news.ycombinator.com

21–30 of 61 posts

Re: Ask HN: Does anyone still use code snippets?

#22

No snippets, no LLMs, no autocomplete.

For things you write a lot, learning how to quickly autocomplete them can pay off.

I don't autocomplete everything, as picking things from a list is if not slower then at least more annoying than just typing that thing, but for common things it's helpful. For instance I type "game.ReplicatedStorage" all the time, so taking a few moments to learn that "game.reso" is the same has saved time.

What upped my motivation to learned some shortcuts was switching from one keyboard layout to another (qwerty->colemak) and having 20-30 WPM for a week. Typing everything was so painful that I could doubly appreciate it.

Re: Ask HN: Does anyone still use code snippets?

#23
post #5

I tried using Copilot a bit, but I found it tried to do too much. As often as it got things right it got them irritatingly wrong. Something pared back giving context sensitive snippets would do fine.

You can swap it to only run on shortcut. You get used to when it will save you time / be accurate relatively quickly. It's a nice little autocomplete that saves me time- but I couldn't stand the automatic mode.

Re: Ask HN: Does anyone still use code snippets?

#24
For scaffolding? I still use snippets (with tooling ofc).

Around 85% of the time, it seems like it takes me more time to write what I want to code in natural language to an AI prompt (and then correct it) than it would to actually code what I want.

The 15% of the time when I want something like "Write test cases to cover this module" is something a snippet couldn't do anyway.

Re: Ask HN: Does anyone still use code snippets?

#25
I use snippets off & on. They came in very handy at a previous company I worked with. Curious on the other answers because I've had some vague ideas for making snippets better but haven't looked deeper into what else is out there and a little wary of AI.

Re: Ask HN: Does anyone still use code snippets?

#26
I use https://emmet.io snippets to save a lot of typing all the time:

- You can just type a CSS selector (actually a superset of CSS), then expand it into the analogous HTML.

- In VS code if you select some HTML then hit ALT-W, you can enter an Emmet snippet that surrounds that HTML.

Examples: https://docs.emmet.io/cheat-sheet/

Re: Ask HN: Does anyone still use code snippets?

#27
I find snippets really useful compared to AI because you have placeholders. You simply have to press Tab to switch from one placeholder to another and fill your snippet with your own values.

Additionally, AI doesn't know how to produce the same output on each execution.

Re: Ask HN: Does anyone still use code snippets?

#28
I actually never really understood how to use snippets (and honestly never really tried). Before AI I just used whatever code generator functions there were in Intellij and with AI it's trivial to get scaffolding and boiler plate that isn't covered by those code generators. I still use the code gen stuff for things like getters and setters or constructors though.

Re: Ask HN: Does anyone still use code snippets?

#30
Emacs is my editor, and I have it configured to use snippets in two ways:

1. When loading an empty file it inserts boiler-plate based on mode (largely that is based on the filename suffix). So if I open a buffer "t.pl" it will insert "#!/usr/bin/perl", along with "use strict; use warnings;", etc.

2. Completion for LSP-modes via yasnippet. So in golang mode I type "iferr[TAB]" and it expands into "if err != .." and moves my cursor to the proper spot when I type TAB.

Post reply on HN