News for hackers. Stuff that matters.
Re:I open sourced my game along with a tutorial on how to ma... by shakna on Tuesday July 07, 2020 @03:32AM (#23756619)
> I mentioned your comment is wrong. I do not know why you are turning it into 0-indexing vs 1-indexing, looks like changing topic for me.

... That's exactly where this topic started:

> 1-index kept throwing me off though

---

> There is no difference between array and string access in ruby, python, js.

There's no difference in Lua either:

    s:sub(1, 1)
    tbl:select(1, 1)
But it doesn't use offset, and I find that more useful for preventing off-by-one errors.
Re:I open sourced my game along with a tutorial on how to ma... by sergeykish on Tuesday July 07, 2020 @05:21AM (#23757235)
I am to used to 0-indexing to judge. If it is not clear already - I am not going to participate in who is better. My thread is

>>>> a string will always be:

    s:sub(1, #s)
>>> In a language that used the half-open interval convention we would end up with:

    s:sub(0, #s)
>> You would end up with:

     s:sub(0, #s - 1)
> That would be strange, in Ruby

    s[0, s.length]
Your argument against 0-index is just plain wrong. No one creates such API. It would be to awkward - either #s should be `length + 1` or `sub` should expect `length + 1`.

----

>>>> Once you get used to it, ... you don't need math when grabbing a range.

I assure you once you get used to 0-indexing there is no need for math when grabbing a range

    s[0..s.length] # that is identity through range in ruby 
----

>>>>> 1-index kept throwing me off though

>>>> it does help prevent a whole bunch of off by one errors

You claim superiority, it is not. I can't remember such errors in my life. It may be easier to describe to children but I doubt it. My first encounter with 0-indexing was with ruler - "why it starts with 0?" - pre-school. I can claim 0-index is natural. I would not.

There is no better model just "happy accidents".