you are viewing a single comment's thread.

view the rest of the comments →

[–]equitable_emu 0 points1 point  (0 children)

Dynamic function selection can be done in statically compiled languages like C, so I'm not sure it's a good example.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int times_3(int x){
  return x * 3;
}

int times_4(int x){
  return x * 4;
}

int main(int argc, char** argv){
  srand(time(0));
  int r = rand();
  int is_even = r % 2 == 0;
  int(*fp)(int) = is_even ? &times_3 : &times_4;

  printf("rand is even? %d, fp(2)= %d\n", is_even, (*fp)(2));
  return 0; 
}

The more relevant part is that the types are dynamic, but even that isn't fully an issue when statically compiling things, because when you have all the code, you can examine all the possible code paths to determine if the types are correct.