Skip to main content
10 events
when toggle format what by license comment
Aug 10, 2012 at 1:09 comment added David Cowden @sepp2k Yes, I agree, I was using web developer as an example simply to hint at the point you just made explicite (= What it comes down to is that it's a design decision personal to each language how integer division is handled. If one disagrees with how a certain language handles things, there should be no trouble finding another one (=
Aug 10, 2012 at 0:05 comment added sepp2k @DavidCowden Not only web developers might disagree. What a well versed programmer does or doesn't find surprising depends entirely on what programming language he's well versed in. (Obviously all design decisions of a given language are not astonishing to people who are completely familiar with that particular language, so that's a meaningless metric). Dividing two ints resulting in an int is only least astonishing to you because you're used to it. Mathematically speaking it's completely astonishing. Integer division is not even associative.
Aug 9, 2012 at 22:46 comment added David Cowden @sepp2k "I think to most newcomers.." << It's not the newcomers, but rather the people who are well versed in the use of a language and it's application domain that should define its' rules. To me, dividing two ints should result in an int and is the least astonishing result. If you want a double, cast the ints to a double and divide them. Simple. And yes, a web developer may disagree.
Aug 9, 2012 at 13:19 comment added K.Steff The Haxe language is strongly (albeit inferred) typed, and yet it has no integer division, only float. So there you go.
Aug 9, 2012 at 12:57 comment added sepp2k @JackManey I think to most newcomers it is way more surprising that 1/2 should equal 0 than it is if dividing two integers results in a double. After all integers aren't closed under division in maths either. Also as delnan points out, Haskell is an example of a strongly typed language in which / on two integers, doesn't produce an integer. And Python 3 is another.
Aug 9, 2012 at 9:07 comment added user7043 Weak/strong typing is ill-defined (as wiki also implies), please avoid it and be specific. I take it your definition bans implicit conversion, but not ad-hoc polymorphism? If so, consider Haskell, which has no implicit conversions but pretty well-executed (as in, works 99% of the time and can be comprehended by mortals) numeric polymorphism. And why would this be astonishing? It would be far more astonishing (not to say annoying) to me if I had to add a number of dots to every single instance of any operator, depending on the exact precision I wish.
Aug 9, 2012 at 9:00 comment added user11946 @delnan - en.wikipedia.org/wiki/Weak_typing I suppose it might be possible to have a strongly typed language in which / is automatically overloaded depending on the types of the arguments, but that seems like a violation of the Principle of Least Astonishment to me...
Aug 9, 2012 at 8:55 comment added user7043 Why the heck would weak typing (whatever that's supposed to mean) be necessary? Just define / to (also) mean float division in the case of both arguments being integers.
Aug 9, 2012 at 8:44 history edited user11946 CC BY-SA 3.0
added 175 characters in body
Aug 9, 2012 at 8:37 history answered user11946 CC BY-SA 3.0