vlang / vscode-vlang

V Language extension for Visual Studio Code.
MIT License
386 stars 52 forks source link

snippets: add unimplemented and unreachable asserts #489

Closed l1mey112 closed 1 year ago

l1mey112 commented 1 year ago

I want to add two snippets to the VSCode extension, I use these quite a lot.

snippet.unimpl

assert false, 'unimplemented'

snippet.unreach

assert false, 'unreachable'

Let me know if this is helpful!

danieldaeschle commented 1 year ago

For what?

l1mey112 commented 1 year ago

I apologise for not going further in depth.

These two assertions are used to guard branches or functions at runtime.

It allows you to easily block out your program and work the parts you need to. The entire function signature can be written out, then have it's body marked as unimplemented. Or A match case's else branch be marked as unreachable. It conveys an intent of implementing the functionality later and allows V to type check stub functions marked as such.

It's pretty niche but used quite a lot in other languages. For example, rust has unreachable!() and unimplemented!('reason') macros, in python raise NotImplementedError. A common method I use in C programs is assert(0 && "reason");

Since it's a snippet, it will be super quick to write. Like I said, maybe it's too niche, but it would be incredibly useful to have.

- lm