5 ms·
The first time I read this, I was ready to be convinced and left disappointed. His entire argument is based on avoiding "the pernicious three dots." What's so
by protonfish 7y ago
The first time I read this, I was ready to be convinced and left disappointed. His entire argument is based on avoiding "the pernicious three dots."
What's so pernicious about them? They are short, clear, unambiguous, easy to type. Why don't we just get our computer languages to understand what "2, 3, ..., 12" means? Is there any other argument to start counting at 0 other than not defining a range using the three dots? If not, maybe starting at 1 (like everyone does outside of computing) is the better option.
- crooked-v 7y ago> Why don't we just get our computer languages to understand what "2, 3, ..., 12" means? Some languages already do: for example, in Ruby you can use (-5..-1) to get [-5, -4, -3, -2, -1]. It's lazy evaluation, so you can even do stuff like: Infinity = 1.0/0.0 (1..Infinity).step(2).take(5) #=> [0, 2, 4, 6, 8]
- burlesona 7y agoJust FYI you can get infinity without evaluating an expression: it’s defined on Float, Float::INFINITY
- acqq 7y ago> Ruby And before, Perl: https://perldoc.perl.org/perlop.html#Range-Operators https://perldoc.perl.org/perlop.html#Range-Operators I like ranges in Perl.
- noisem4ker 7y agoSame as in Haskell. https://wiki.haskell.org/List_comprehension https://wiki.haskell.org/List_comprehension
- mark-r 7y agoI remember seeing a rather convincing argument that 1.0/0.0 should not be infinity, but zero.
- jolmg 7y agoYou mean mathematically, or specifically for programming? For programming, I imagine it's better for it to be infinity than 0 since having 0 in the denominator implies that it's changing (who would write a constant 0 in a denominator?), and so as the denominator is approaching 0, the fraction is getting closer and closer to pos/neg infinity, not 0. Making it evaluate to zero would imply a change of direction for whatever the fraction represents. So, if it's a position, as the position goes 1000/1000, 1000/500, 1000/100, 1000/1, etc. it's getting closer to infinity. Having it suddenly go to 0 would break the pattern of movement. Mathematically, there is no x that satisfies x = 1/0 -> x * 0 = 1, since anything multipled by 0 is 0, so it's undefined.
- mark-r 7y agoYes, there's a discontinuity between the positive and negative numbers, that was part of the argument. Another part was that certain mathematical formulas get simpler when x/0 = 0.
- smabie 7y agoDo you remember seeing or do you remember?
- mark-r 7y agoIt was something on the internet. I wish I could come up with the proper search terms to find it again.
- QuinnWilton 7y agoThis is how Pony handles division. There's a good summary of possible motivations here: https://www.hillelwayne.com/post/divide-by-zero/ https://www.hillelwayne.com/post/divide-by-zero/
- QuinnWilton 7y agoI pasted the wrong link above, but my mobile app isn't letting me edit it. This is the link that describes their reasoning: https://tutorial.ponylang.io/gotchas/divide-by-zero.html https://tutorial.ponylang.io/gotchas/divide-by-zero.html
- burlesona 7y agoI would argue that starting at zero comes more naturally if you’ve been working in binary and are often using bits to select or signal things. In that case the single bit zero is a rather important piece of information and where everything starts. Then when you translate these ideas up into higher languages it continues to feel somewhat natural — just as the hardware may be selecting for register addressed as 000000000 etc, so the items in an array would start from zero. We go ahead and represent the indexes after one in decimal, for convenience, but there’s a feeling that they are like the hardware memory addresses under the hood. This isn’t so compelling in today’s world of mostly people who live in high level programming languages with no real notion of what goes on in the hardware. But backwards compatibility is a thing, and “following conventions” as well, so I see zero based indexing used in modern high level languages as a logical extension of where this all came from. What’s hard, really, isn’t using zero based indexing, it’s switching back and forth between systems.
- marcosdumay 7y ago> This isn’t so compelling in today’s world of mostly people who live in high level programming Array indexing is less compelling on higher level languages, so I think the needs of those languages can be safely ignored here anyway.
- goatlover 7y agoDon't R, Matlab & Julia make heavy use of array-like data structures?
- VHRanger 7y agoYes, but those arrays are based on the concept of the mathematical vector. Whereas C and descendents see arrays as chunks of memory. In C arrays it makes sense to think of the index as an offset (0 elements away from the start, etc.). In math its more consistent with classic matrix notation.
- goatlover 7y ago
- tlb 7y agoThey’re not unambiguous when the endpoints are variables. What is [1,2,...,x] when x=1? You probably want just [1] in this case if you’re iterating over indices.
- tkfu 7y agoAlso, I find his case that notation option A is best to be extremely unconvincing. He just lists 2 properties that he thinks are good: 0. Subtracting the lower bound from the upper yields the length of the sequence. 1. For adjacent sub-sequences, the upper bound of the lower sequence will equal the upper bound of the lower sequence. One could just as easily argue for option C (a ≤ i ≤ b) by pointing out that 0. It's much closer to natural language ("all the numbers from a to b"), and thus less likely to be casually misunderstood. 1. It uses the same inequality symbol twice, making it quicker and easier to understand. 2. If either of the bounds of one sub-sequence is inside the bounds of another sub-sequence, those two sub-sequences overlap.
- arh68 7y agoYes, I would agree. His logic is that we should cater to the empty sequence case, and it would be "unnatural" to write 2 <= x <= 1, so we have to write 2 <= x < 2. That is just not an improvement. Ask somebody to write down an empty sequence, starting at 2, they'll think you're crazy. The Common Case is give the First and Last. Option C is, to me, obviously best. How you can replace 2 .. 12 and not use 2 & 12 is beyond me. (/s Dijkstra's opinions considered harmful /s)
- dragonwriter 7y ago> Why don't we just get our computer languages to understand what "2, 3, ..., 12" What does that mean? 2,3,5,8,12? > starting at 1 (like everyone does outside of computing Non-computing science quite frequently uses offset-based indexing starting at zero, just as is frequently done in computing.
- tsimionescu 7y agoWhen I did maths in high-school and university, most indices were 0-based,not 1-based. 0-based indexing is so common in physics and engineering (e.g. the initial time of a system is T0, not T1). Note also that, in maths, both the cardinal and the ordinal numbers start at 0 - defined as the cardinality of the empty set and the set containing the empty set, respectively.