> tests never catch unanticipated parts
No, but calling a function with arguments of the wrong type is something tests would catch.
No, but calling a function with arguments of the wrong type is something tests would catch.
Or the compiler.
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp = fopen("outfile", "w");
fclose(fp);
do_something(fp);
return 0;
}
int do_something(FILE *f)
{
fprintf(f, "This should work if you know what you're doing");
}
And it won't work. struct WithOpenFile {
FILE *fp;
WithOpenFile(const char *fileName) : fp(fopen(fileName, "w")) {}
~WithOpenFile() { fclose(fp); }
};
int do_something(FILE *f)
{
fprintf(f, "This should work if you know what you're doing");
}
int main(int argc, char *argv[])
{
{
WithOpenFile file("outfile");
}
do_something(file.fp);
return 0;
}
But Lisps will happily accept this: (defun do-something (foo)
(1+ foo))
(with-open-file (file "outfile")
(do-something file))