Ask HN: Does anyone still use code snippets?
33 points| davidrjenni | 1 year ago
I noticed that I still like them and rely on them and was wondering if that’s the same for someone else.
33 points| davidrjenni | 1 year ago
I noticed that I still like them and rely on them and was wondering if that’s the same for someone else.
stevekemp|1 year ago
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.
figassis|1 year ago
ZYbCRq22HbJ2y7|1 year ago
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.
js8|1 year ago
That's how it should be, actually 100%. If you need scaffolding (and snippets) it means your language doesn't have (or worse, can't have) the right abstractions in its library.
atoav|1 year ago
My issue with the code they generate is mostly that the style of abstractions chosen is inconsistent and seems to replicate whatever was the source at any given point. Programming is still about understanding what is going on, not about just writing code, so either way you need to put in the brainwork to understand it.
But as a "just show me an example"-helper it can save you a lot of time, especially if you load highly undocumented and convoluted codebases into it.
In some cases I had the LLM hallucinate functions that would have been wonderful if they existed, but hey.
Leftium|1 year ago
- 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/
nicbou|1 year ago
beardyw|1 year ago
jasonjmcghee|1 year ago
pradyun_|1 year ago
Terr_|1 year ago
When I am working on new stuff... Well, my typing is mostly on autopilot, I use the time to think about what I'm going to put next, or else I've reached a spot where I would be making decisions anyway, e.g. naming a method.
johncoltrane|1 year ago
wahnfrieden|1 year ago
theycameback|1 year ago
`af` expands to `() => `
`naf` expands to `export const foobar = () => {};`
The expanded snippets can be tabbed through as well
It feels like a big timesaver
j_leboulanger|1 year ago
I also use the nest cli to create new modules, services, ... which are king of snippets also.
al_borland|1 year ago
I think a lot of the standard snippets from years past were already taken over by things like IntelliSense, or various other IDE plugins.
masutaka|1 year ago
note - gh:
> [!NOTE] > Highlights information that users should take into account, even when skimming.
ruby - html:
<ruby>WORD<rp>(</rp><rt>CAPTION</rt><rp>)</rp></ruby>
wruza|1 year ago
This is a result of a process I call experience distillation. I notice what code I write often but tend to either forget (bash) or outthink much faster than I can type (common syntax, libs, boilerplate), and routinely add it to snippets in hope that it sticks. Then I learn to actually use it. Once in a while I delete the unused or reshape it for second attempt with the understanding why it failed the first time.
asukachikaru|1 year ago
Copilot have not been able to generate arrow functions when I intend to, in my experience. I found it pretty incompetent, and unable to provide relevant assistance if there is any bit of abstraction. YMMV.
I reckon my need for this specific snippet could be replaced with a more competent agent. I recently subscribed to cursor and so far it seems promising.
chrismorgan|1 year ago
someothherguyy|1 year ago
you have a snippet for four characters? `()=>`?
Shakahs|1 year ago
zxexz|1 year ago
That’s not to say that “AI” assisted coding isn’t useful -in fact it can be indispensable. For me, the value is mostly it being a seemingly perpetually slightly drunk, yet prescriptive, pair coding partner.
sedatk|1 year ago
ivolimmen|1 year ago
Sakos|1 year ago
petepete|1 year ago
I have some configured to enter the names of colleagues I've paired with to commit messages in the format GitHub expects too.
qrobit|1 year ago
When doing some quick experiment in C/C++, scaffolding `int main ...` and classes is nice too.
In nicer languages I use snippets only if I forget syntax, than snippet serve as a quick reminder(e.g. for loop in lua)
sweeter|1 year ago
If I ever do use llms it's for searching for something like "what kind of expression is this called: (i = 0; I < x; i++)" so that I can do better research myself.
wvenable|1 year ago
x3n0ph3n3|1 year ago
somenameforme|1 year ago
No clue if it's true, but this is why I assumed a lot of older computing stuff is often abbreviated to the point of obfuscation.
bemmu|1 year ago
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<tab>" 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.
senectus1|1 year ago
someoneontenet|1 year ago
_hao|1 year ago
shagmin|1 year ago
nesk_|1 year ago
Additionally, AI doesn't know how to produce the same output on each execution.
unknown|1 year ago
[deleted]
patagonianboy|1 year ago
theshrike79|1 year ago
The rest I can just do with whatever AI I'm currently using, they'll usually guess the variables right the first time too.
self_awareness|1 year ago
With AI, you never know what you'll get. OTOH snippets were created by hand by me. I know what to expect of them and what not to expect. They are always the same.
bandrami|1 year ago
hkchad|1 year ago
progx|1 year ago
Refusing23|1 year ago
we dont use AI at my work
wahnfrieden|1 year ago
wilg|1 year ago