by verdverm · 3y ago · 0 comments
I always get squeamish when I see magic comments
You should be squeamish about running the code without reading it first, given that you're pair-programming with a bot.
It's funny, the first version of this project[0] let you do exactly that, e.g.,
def main(path: str):
#<<filenames = a list of filenames under path>>
for fn in filenames:
#<<size = size of fn in bytes>>
print(fn, size)
#<<use argparse and call main>>
and then run that program like any other Python script (using import magic): $ python -m examples.file_sizes /etc
…
/etc/wgetrc 4942
/etc/nsswitch.conf 542
/etc/adduser.conf 3028
/etc/ethertypes 1816
But yeah, it never felt exactly practical. :)The decorator invokes AI completion only the first time the function is run.
edit: I lost interest before I was able to get arguments to work ¯\_(ツ)_/¯
The potential issue I see here is that comments are valid anywhere while decorators may not be, but the parser is hopefully resilient to that. You could see a multi-phase LLM that uses the interpreter to ensure the code runs / works as expected
you can alternatively split generated code from human written code with files, keep the mapping in something more structured like a config file
I just normally see a better way to do the same thing a magic comment does, generally speaking. There is typically a better language construct if you limit yourself to that language (most common), and config files offer much more structure with existing tooling (mostly decode in your preferred language)