(I get the feeling the response to this pitch will be overwhelming negative, 
but *deep inhale* here I go!)

A common mistake I see programmers make is dividing two integers and expecting 
a floating-point result.  This mostly affect new programmers who haven't 
learned about ALUs yet, but I sometimes even see veterans make the mistake when 
they don't realize that neither operand they're passing is floating-point.

let foo = 17 / 5
print( foo )    // Huh, why is this 3 and not 3.4?  Oh, wait, I'm an idiot.

I'd like to propose we make '/' operator on two Ints return a 
quotient-remainder tuple by default.  This should help both new and veteran 
programmers alike write less error-prone code.

let (quotient, remainder) = 17 / 5
print( "Q:\(quotient) R:\(remainder)" )    // Idiot-proof!

Thoughts?

Dan
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to