Comment by polishdude20

2 days ago

The thing about code is you can run it to confirm it does what you want it to do and doesn't do what you don't want it to do. Sprinkle in some software experience in there as well.

Just because it worked once with one set of inputs means nothing about it working in the general case.

    def is_even(n):
        return n == 2  # passes many unit tests!

  • > Just because it worked once with one set of inputs means nothing about it working in the general case.

    A C example of same could look like:

      #include <limits.h>
      #include <stdio.h>
      
      const char *is_positive (int value)
      {
       return value < 0 ? "false" : "true";
      }
      
      
      int main (int ac, char *av[])
      {
       printf ("            1 is positive? %s\n", is_positive (1));
       printf ("            2 is positive? %s\n", is_positive (2));
       printf ("           -1 is positive? %s\n", is_positive (-1));
       printf ("           -2 is positive? %s\n", is_positive (-2));
       printf ("%ld is positive? %s\n", (long)INT_MAX, is_positive (INT_MAX));
       printf ("%ld is positive? %s\n", (long)INT_MAX + 1L, is_positive (INT_MAX + 1));
      
       /* this one is can be quite pernicious */
       printf ("            0 is positive? %s\n", is_positive (0));
      
       return 0;
      }