Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
whimsical174333dIt's maybe more clear if you read it as length. "ABC"[0:1]>"a". Second parameter is just length and it starts from zero so. But also making the mistake still often. Can happen.
-
lorentz1516533dTop-exclusive ranges are the standard because they make more sense than bottom-exclusive ranges, and because making exactly one side of the range inclusive makes all sorts of math a lot easier. If both ends were included, an empty slice would have to be either unrepresentable or it would be encoded as end + 1 = start where neither end nor start are actually included. -
CaptainRant483632d@lorentz I knew it would be math. lol. It reminded me of (,] and [,) notations. -
Lensflare2131431d@jestdotty no, what you said was
(int)(randomFloat() * numberOfThings)
where randomFloat() gives you a number in the range of 0.0 to 1.0 -
lorentz1516530dNow thinking about it, I wonder though if there's a broad category of problems where it's useful to represent ranges with A..B containing X where (B < X) == (X < A), which is to say, double-inclusive if A<B and double-exclusive if B<A.
On an additional tangent from my tangent, I wonder if it's feasible to conduct niche elimination via algebraic invariants this way, i.e. we know that a standard range has low<high, so you can tag a union of a range and anything that fits into two fewer bits than it by setting low.msb=1 and high.msb=0 and then populating the rest of the range with the alternatve value. -
Lensflare2131430d@lorentz I‘m not gonna pretend that I understand (I never do), but I like your thoughts.
Related Rants

It changed my life, really. ๐
No questions asked
Pretty annoying when a programming language's constructs do things that are unintuitive, for example, Java substring:
str.substring(startIndex, endIndex); // oops, character at endIndex not included.
Or some other Python data science Google library (I used this at work) that decided their way is the best way, where they have a simple method but in the facade behind it is a nightmare monstrosity of complexity. How fun to debug or customize that!
Weird design decisions. They don't help because it makes them harder to immediately understand them.
rant
code
unintuitive