Disclaimer: I have programmed in both Ruby and Python, but not enough to be familiar with their conventions, so the following could be a serious misunderstanding on my part.

Any Python or Ruby programmers out there able to explain why these languages default to integer math?

$ python -c 'print 7/2'
3

$ ruby -e 'puts 7/2'
3

Those languages default to integer math unless you explicitly use a float. For example:

$ python -c 'print 7.0/2'
3.5

Why should the default be to silently discard information? Now I can understand that in C. For example, run gcc -Wall on the following:

#include <stdio.h>

int main(int argc, char *argv[]) {
    printf("%f\n", 7/2);
    return 0;
}

You’ll get the following warning (is this something I could enable in Python or Ruby?):

divide.c: In function 'main':
divide.c:4: warning: format '%f' expects type 'double', but argument 2 has type 'int'

C pretends to be a statically typed language and if you get confused about types, your language will misbehave. So you either want to be explicit and cast the result, (float)7/2, or better still, use floats in the first place (some argue that the ability to cast data types means a type system is broken). If you use integers in division, it will give you an integer result. If you use more than one data type, the result of the expression is the one which loses the least information:

#include <stdio.h>

int main(int argc, char *argv[]) {
    double numerator   = 7.0;
    int    denomenator = 2;

    // no warnings with -Wall because the result is a double
    printf("%f\n", numerator/denomenator);
    return 0;
}

In Perl, because it’s dynamically typed, the result of an mathematical expression is simply whatever result has the most information (that’s an oversimplification):

$ perl -le 'print 7/2'
3.5

If you need the occasional performance benefit you can gain from integer math you can tell Perl to discard the extra information:

$ perl -Minteger -le 'print 7/2'
3

In other words, you request “incorrect” answers, rather than assuming them. That strikes me as far more intuitive for a ‘dynamically typed’ language, so I’m clearly misunderstanding something here. What’s the benefit of defaulting to integer math?

As an aside, the counter-argument I could see is the following:

perl -le 'print 4 + "3 apples"'
7

Issues like that are why we encourage programmers to enable warnings:

$  perl -wle 'print 4 + "3 apples"'
Argument "3 apples" isn't numeric in addition (+) at -e line 1.
7