5 ms·
> Never, ever, ever use [closed, closed] intervals I’m not really a fan of “never,” or “always” rules, when it comes to programming. I’ve found it’s usually be
by ChrisMarshallNY 4y ago
> Never, ever, ever use [closed, closed] intervals
I’m not really a fan of “never,” or “always” rules, when it comes to programming. I’ve found it’s usually better to have a “make sure to justify deviations from” heuristics.
I usually use [closed..open) ranges (as they are called in Swift), but sometimes, an inclusive range is a lot more appropriate, for expressing an operation (for example, I may express a range as start...end, as opposed to start..<(end + 1)).
- Tuna-Fish 4y ago> as opposed to start..<(end + 1) This is not just a convenience thing. ..(end+1) is dangerous, if end is the largest representable number.
- teddyh 4y agostart..<inf
- mananaysiempre 4y agoSee also “My least favourite Rust type”[1] for an argument that Rust’s (polymorphic) range type should have used inclusive bounds. [1] https://ridiculousfish.com/blog/posts/least-favorite-rust-type.html https://ridiculousfish.com/blog/posts/least-favorite-rust-ty..., discussed two years ago in https://news.ycombinator.com/item?id=24546928 https://news.ycombinator.com/item?id=24546928
- vasergen 4y agoAgree, in programing you can always find a contrargument to any "never ever use X". I noticed that people often treat such phrases godmatically and then use it in another context, where it might not be true. I like more phrasing it like this "in 90 % of the cases it is better to use X over Y", to leave the room for other options. But it is not a catchy phrase if you want to write a blog post. Nevertheless I really like the points the author gave, something I didn't thought about before.
- inanutshellus 4y agoI've moved away from this. Advice is supposed to convey information simply and efficiently, and "asterisks" for every edge case just muddle it. Now my pet peeve has moved to folk wheedling about 100% accuracy in advice. ;-) e.g. Great advice: "Never run a red light" vs Technically-correct-but-will-never-be-read advice: "Don't run a red light, unless you're on a bicycle and you know that the intersesction you're at is on a weighted sensor that you're not going to set off. In which case, check your local laws on how to get through the intersection. Also, this likely applies to motorcycles. But not all motorcycles, so check your motorcycle's weight and cross-reference it to the weight sensors in your intersection (you'll need to contact your municipal engineering corps to get this). Also, one should look up for falling pianos at this point as well, just in case, because I can't say the word 'never'."
- carpenecopinum 4y agoThere is still a difference between leaving out special cases to give more succinct advice and going out of your way to repeat the words "never"/"ever" three times to imply the absolute absense of any exceptions.
- JackFr 4y agoYeah. I'm on board for 'never', but by the second 'ever' you lose me.
- deleted 4y ago[deleted]
- kylebyproxy 4y agoYou could just say "Generally don't run a red light"
- ChrisMarshallNY 4y agoThat's why I have “make sure to justify deviations from” in there. It's easy enough to make that policy, but you run the risk of making the development process too unwieldy to implement (See: Taligent's Style Guide). I would hope that most style guides have caveats for deviation (disclaimer: I haven't read a style guide in eons, so I don't know what they generally say, these days). I'd say that "We should do it this way, but, if you think your way is better, convince me." is a good approach. Really, I see a lot of problems, caused by corporations' obsession with hiring lots of bad programmers, and trying to force them to be good programmers, by setting up strict boundaries, as opposed to just hiring a few good programmers, in the first place (which, admittedly, has its own issues). This is nothing new. I have seen this since the 1980s. The really cool thing about software, is its flexibility. I feel that the enormous toolbox at my disposal, along with my experience in using said tools, makes it possible for me to develop some pretty good stuff. If someone tried to force me to do a "lowest common denominator" approach, I don't think the results would be good.
- HelloNurse 4y agoIt's better to say that if you are using closed intervals without properly using open and half-open ones too there's usually a serious problem. In general, splitting existing intervals and specifying practical ranges require all four types.
- hyperrail 4y agoI like Raymond Chen's formulation of this point: > Good advice comes with a rationale so you can tell when it becomes bad advice. If you don't understanding why something should be done, then you've fallen into the trap of cargo cult programming, and you'll keep doing it even when it's no longer necessary or even becomes deleterious. from: https://web.archive.org/web/20100104031036/http://blogs.msdn.com/oldnewthing/archive/2009/11/04/9917052.aspx https://web.archive.org/web/20100104031036/http://blogs.msdn...
- ChrisMarshallNY 4y agoTwain's Corollary: "We should be careful to get out of an experience only the wisdom that is in it -and stop there; lest we be like the cat that sits down on a hot stove-lid. She will never sit down on a hot stove-lid again -and that is well; but she will never sit down on a cold one anymore." -Mark Twain