On Monday, 1 January 2018 at 16:47:40 UTC, Adam D. Ruppe wrote:
On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote:
If you use .ptr then you get zero detection, even in debug builds.

It is limited to the one expression where you wrote it, instead of on the ENTIRE program like the build switches do.

It is a lot easier to check correctness in an individual expression than it is to check the entire program, including stuff you didn't even realize might have been a problem.

With the .ptr pattern, it is correct by default and you individually change ones you (should) look carefully at. With -boundscheck, it is wrong by default and most people don't even look at it - people suggest it to newbies as an optimization without mentioning how nasty it is.

It won't be just one line though. When you pretty much have to use it EVERYWHERE to get the optimization you want. It makes more sense to just turn off the check for the entire program and use your own asserts() where they are actually needed. That way you still get the checks in debug builds and have asserts where they are actually necessary.

I'd rather there be a potential bug than the program running to slow to be usable

That's a ridiculous exaggeration. In this program, I saw a < 1% time difference using those flags. -O -inline make a 50x bigger difference!

Read the sentence right before this.. Jesus. People only read what they want.

or have zero debugging for indices in debug builds.

You shouldn't be using .ptr until after you've carefully checked and debugged the line of code where you are writing it. That's the beauty of the pattern: it only affects one line of code, so you can test it before you use it without affecting the rest of the program.

It won't just be one line, and that's not beautiful. What happens when code gets refactored? You are constantly going to be flip-flopping the source code rather than a compiler flag or using multiple build configurations? How long are you even going to test for? The error that might happen for the code is probably difficult to detect, if it wasn't then having bounds checking at all wouldn't be necessary. Just test your code, that's the beauty of testing!

Reply via email to