Freya Holmér
Freya Holmér

@FreyaHolmer

9 Tweets Dec 15, 2022
vibe check - what would you expect?
r = new intRange( start: 2, end: 4 )
print( r.Length + ", " + r.Count )
(assuming it has both Count and Length, and it's not an IEnumerable. whether or not it *should* have/be any of these is a separate topic~)
see it's easier with a float range, but with an int range we run into all of these off-by-one fencepost issues
we've all been damaged by indexing 😔
not liking the answers to this, maybe I need to redesign, hmm
new vibe check!
(reread this carefully, words have changed)
r = new intRange( start: 2, count: 3 )
print( r.Distance + ", " + r.End )
man it's really hard to pull people out of programming array indices w. exclusive end ranges mindset
to back up a little - this is for my math library, and I've had a FloatRange for a long time to represent a range of values on the mathematical number line
of course, this naturally extends to making a similar variant for an IntRange
but this is made hard ;-; because of all programming paradigms and standards set by things like C#s Range/Index/Span/IEnumerable behavior
if I want to represent the number range
{2,3,4}
to me, from a mathematical number line perspective:
Start = 2
End = 4
Count = 3 (integers in this range)
Length = 2 (distance from 2 to 4)
this is consistent with FloatRange.Length which does the same (though there's no Count)
if I say "integers 2 to 4" you generally wouldn't think I'm referring to the two numbers {2,3}
but because we're in programming array 0-indexing mode, we're used to things called "int range" to behave like this, and Count = Length = Size
;-;

Loading suggestions...