IMHO having the "/" operator return a float was an excellent design 
decision in Julia. The amount of time I've seen people waste (with other 
languages) tracking down bugs caused by doing a/b with a<b and everything 
being 0 in the end ... because they didn't remember they were dealing with 
integers and/or forget to cast one of the arguments to float/double ...

I appreaciate Julia's theme of keeping things safe, even at the cost of a 
little performance (array bounds checks, range checks during value 
conversions, etc.) - while allowing programmers to switch the safeguards 
off if they need max performance and clearly state in the code (@inbounds, 
...) that they know what they're doing. I feel like "/" returning floating 
point values fit in with this perfectly. If people really want an int, the 
"div" in the code will clearly state that fact. It saves less experienced 
programmers (read students) a lot of time, and their supervisors, too. ;-)

On Sunday, April 3, 2016 at 6:20:44 PM UTC+2, Stefan Karpinski wrote:
>
> I question the alleged ubiquity of integer division. This is not an 
> operation I find myself needing all that often. Of course, everyone's 
> programming needs are different, but I just don't find myself wanting the 
> integer quotient of a and b more often than I want to do a/b and get their 
> ratio as a float.
>
> On Sun, Apr 3, 2016 at 12:09 PM, Tim Holy <[email protected] <javascript:>
> > wrote:
>
>> Indexing with // is a bit undesirable because 6//3 gets simplified to 
>> 2//1 upon
>> construction, and there's no reason to pay the cost of that operation.
>>
>> With \\, would you worry about confusion from the fact that in a \\ b, a 
>> is in
>> the denominator? Especially if it gets called the "integer division 
>> operator."
>>
>> One could use ///, but that's starting to be pretty comparable to 
>> \div[TAB],
>> and less pretty to read.
>>
>> --Tim
>>
>>
>> On Sunday, April 03, 2016 05:56:26 AM Scott Jones wrote:
>> > For some reason, my posts are getting sent prematurely!  Continuing:
>> >
>> > Since the integer division operator // of Python (2&3) and Lua already
>> > means something important in Julia, and \ is also taken, I'd like to
>> > propose \\ as an integer division operator for Julia.
>> > Having to always type \ d i v <tab> in the REPL, and something 
>> different in
>> > Emacs, or write things out as `div(a, b)` (6 characters typed!), is 
>> rather
>> > annoying, \\ is just a syntax error currently in Julia
>> > and could easily be added to the parser and made a synonym to div (÷).
>>
>>
>

Reply via email to