Re: Providing implicit conversion of - memory-safety

2024-01-24 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 09:28:57 UTC, Renato wrote: If you have "widespread" arithmetics which may overflow, something like https://dlang.org/phobos/core_checkedint.html is useful, yes, but in this case it's overkill. To make use of this, one needs to already anticipate an

Re: Providing implicit conversion of - memory-safety

2024-01-24 Thread Renato via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 00:34:19 UTC, bachmeier wrote: On Tuesday, 23 January 2024 at 21:40:46 UTC, Renato wrote: While I can understand your frustration, it seems to me D is not to blame in this instance because the code is quite patently using unsafe constructs (D does not claim to

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Renato via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 23:40:55 UTC, Danilo wrote: How did you make it correct? Write 2 different versions for `signed` and `unsigned` types? Or could you utilize `core.checkedint` somehow for checking overflow? ```d double value(T)(T index, double * x) { bool overflow;

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 23:40:55 UTC, Danilo wrote: On Tuesday, 23 January 2024 at 17:54:25 UTC, bachmeier wrote: Here's a reduced version of one of the most bizarre bugs I've dealt with in any language. The only reason I didn't move on to another language was because I was too busy at

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 21:40:46 UTC, Renato wrote: While I can understand your frustration, it seems to me D is not to blame in this instance because the code is quite patently using unsafe constructs (D does not claim to be fully safe). It pretends to be safe. Consider this: ```

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Danilo via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 17:54:25 UTC, bachmeier wrote: Here's a reduced version of one of the most bizarre bugs I've dealt with in any language. The only reason I didn't move on to another language was because I was too busy at the time. The code allows for initial values if the index

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Siarhei Siamashka via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 21:40:46 UTC, Renato wrote: While I can understand your frustration, it seems to me D is not to blame in this instance because the code is quite patently using unsafe constructs I wouldn't blame bachmeier, because many reduced testcases distilled from the real

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Renato via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 21:18:53 UTC, bachmeier wrote: There are two things things that cause the problem. One is the use of a template and the other is passing an unsigned type. The reason the first parameter uses a template is because there are a lot of types I could send as the first

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 19:27:26 UTC, Renato wrote: Here's a reduced version of one of the most bizarre bugs I've dealt with in any language. The only reason I didn't move on to another language was because I was too busy at the time. The code allows for initial values if the index is

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Renato via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 17:54:25 UTC, bachmeier wrote: On Tuesday, 23 January 2024 at 12:34:38 UTC, Nick Treleaven wrote: But I'm strongly in favour of catching any bugs at compile-time (and have been since before I discovered D). I just object to anyone trying to downgrade the

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 12:34:38 UTC, Nick Treleaven wrote: But I'm strongly in favour of catching any bugs at compile-time (and have been since before I discovered D). I just object to anyone trying to downgrade the importance of automated memory-safety checking. I'm not downgrading

Re: Providing implicit conversion of

2024-01-23 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 22 January 2024 at 19:49:19 UTC, Siarhei Siamashka wrote: The two's complement wraparound behavior mandated by the D language spec is a non-technical political decision, intended to make life easier for the DMD compiler developers, but ignoring the needs of the users. Actually it

Re: Providing implicit conversion of - memory-safety

2024-01-23 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 22 January 2024 at 19:11:50 UTC, Siarhei Siamashka wrote: On Monday, 22 January 2024 at 16:39:10 UTC, Nick Treleaven wrote: Memory safety issues are a worse class of bug than arithmetic bugs. The latter are reproducible if you feed them the same input. Memory safety bugs are

Re: Providing implicit conversion of

2024-01-22 Thread Danilo via Digitalmars-d-learn
On Monday, 22 January 2024 at 17:15:55 UTC, bachmeier wrote: I get incorrect results, and when I'm lucky, my program segfaults because I accessed something I shouldn't. When I'm not, it silently and happily gives me the wrong answer. Maybe a compiler warning (not error) would help with

Re: Providing implicit conversion of

2024-01-22 Thread Siarhei Siamashka via Digitalmars-d-learn
On Monday, 22 January 2024 at 01:14:06 UTC, Steven Schveighoffer wrote: On Sunday, 21 January 2024 at 16:05:40 UTC, Gavin Gray wrote: The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in

Re: Providing implicit conversion of

2024-01-22 Thread Siarhei Siamashka via Digitalmars-d-learn
On Monday, 22 January 2024 at 16:39:10 UTC, Nick Treleaven wrote: Memory safety issues are a worse class of bug than arithmetic bugs. The latter are reproducible if you feed them the same input. Memory safety bugs are reproducible with the tools like `valgrind`. Whereas arithmetic overflow

Re: Providing implicit conversion of

2024-01-22 Thread bachmeier via Digitalmars-d-learn
On Monday, 22 January 2024 at 16:39:10 UTC, Nick Treleaven wrote: I've said multiple times that it's silly to spend so much time on memory safety if the language is going to allow stuff like this without a simple way to prevent it. Memory safety issues are a worse class of bug than

Re: Providing implicit conversion of

2024-01-22 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 22 January 2024 at 01:14:06 UTC, Steven Schveighoffer wrote: The language should not allow unary unsigned anything. This is unlikely to get fixed, just due to the nature of D's philosophy when it comes to C compatibility. It would also break a lot of existing code. I think the

Re: Providing implicit conversion of

2024-01-22 Thread bachmeier via Digitalmars-d-learn
On Monday, 22 January 2024 at 06:43:17 UTC, thinkunix wrote: Gavin Gray via Digitalmars-d-learn wrote: The following code:   ulong charlie = 11;   long johnstone = std.algorithm.comparison.max(0, -charlie);   writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)):

Re: Providing implicit conversion of

2024-01-21 Thread Danilo via Digitalmars-d-learn
On Sunday, 21 January 2024 at 16:05:40 UTC, Gavin Gray wrote: The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)): johnstone -11 However you choose to look at

Re: Providing implicit conversion of

2024-01-21 Thread thinkunix via Digitalmars-d-learn
Gavin Gray via Digitalmars-d-learn wrote: The following code:   ulong charlie = 11;   long johnstone = std.algorithm.comparison.max(0, -charlie);   writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)): johnstone -11 However you choose to look at it, this means -11

Re: Providing implicit conversion of

2024-01-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 22 January 2024 at 01:14:06 UTC, Steven Schveighoffer wrote: On Sunday, 21 January 2024 at 16:05:40 UTC, Gavin Gray wrote: The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in

Re: Providing implicit conversion of

2024-01-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 January 2024 at 16:05:40 UTC, Gavin Gray wrote: The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)): johnstone -11 However you choose to look at

Providing implicit conversion of

2024-01-21 Thread Gavin Gray via Digitalmars-d-learn
The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)): johnstone -11 However you choose to look at it, this means -11 > 0 (regardless of all arguments concerning