Re: Comparing Exceptions and Errorsj

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 6 June 2022 at 04:59:05 UTC, Ola Fosheim Grøstad wrote: An assert only says that the logic of that particular function is not meeting the SPEC. Actually, the proper semantics are weaker than that, the spec would be preconditions and post conditions. Asserts are actually just steps

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 23:57:19 UTC, Steven Schveighoffer wrote: It basically says "If this condition is false, this entire program is invalid, and I don't know how to continue from here." No, it says: this function failed to uphold this invariant. You can perfectly well recover if you

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 6:09 PM, kdevel wrote: On Sunday, 5 June 2022 at 20:53:32 UTC, Steven Schveighoffer wrote: [...] For this purpose nobody needs a separate subclass named `Error`. That works with `Exception`s. You can use Exceptions instead. But the difference is they are part of the program instead

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 21:08:11 UTC, Steven Schveighoffer wrote: [...] Just FYI, this is a *different discussion* from whether Errors should be recoverable. The wording of this "question" bothers me really. What does "Errors" mean here? If you mean thrown object having a (sub)type of

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 20:53:32 UTC, Steven Schveighoffer wrote: [...] For this purpose nobody needs a separate subclass named `Error`. That works with `Exception`s. You can use Exceptions instead. But the difference is they are part of the program instead of considered a check on the

Re: Copy Constructor

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 14:39, Ali Çehreli wrote: > Actually, both are copy construction: I am wrong there. I did confuse myself. >Foo one = Foo(1), two = 2; As my rewrite shows, they are both construction with an int: >auto one = Foo(1); >auto two = Foo(2); Ali

Re: Copy Constructor

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 11:43, Alain De Vos wrote: > Does Foo(3) lives on the stack or the heap ? It depends. > there is a > conversion. Suche conversions are called "construction" in D. > And what happes with > Foo[3] arr = [one, two, Foo(3)]; Foo[3] is a static array. Static arrays are value types.

Re: Copy Constructor

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 12:00, Salih Dincer wrote: > On Sunday, 5 June 2022 at 18:43:19 UTC, Alain De Vos wrote: >> Does Foo(3) lives on the stack or the heap ? I depends. I will respond to your other message. > Definitely not stack because that's what happens when the new operator > is used. Article 14.3:

Re: Copy Constructor

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 14:04, Alain De Vos wrote: > Could it be the copy constructor is only called during assignments (like > C++). The assignment operator is used during assignments both in C++ and D. A confusion comes from the fact that construction uses the same operator as assignment: a = b; //

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 11:03, kdevel wrote: > On Sunday, 5 June 2022 at 17:04:49 UTC, Ali Çehreli wrote: >> On 6/5/22 08:07, kdevel wrote: > [...] >> Like many other programmers who include me, Sean Parent may be right.[1] >> >> Other than being a trivial example to make a point, the code I've >> shown may be

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 21:08:11 UTC, Steven Schveighoffer wrote: Just FYI, this is a *different discussion* from whether Errors should be recoverable. Ok, but do you a difference between being recoverable anywhere and being recoverable at the exit-point of an execution unit like an

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 12:27 PM, Ola Fosheim Grøstad wrote: Ok, so I am a bit confused about what is Error and what is not… According to core.exception there is wide array of runtime Errors: ``` RangeError ArrayIndexError ArraySliceError AssertError FinalizeError OutOfMemoryError

Re: Copy Constructor

2022-06-05 Thread Alain De Vos via Digitalmars-d-learn
Could it be the copy constructor is only called during assignments (like C++). And for one, two there is an explicit assignment. But not for three where there is a conversion ?

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 8:45 AM, kdevel wrote: On Sunday, 5 June 2022 at 01:43:06 UTC, Steven Schveighoffer wrote: [...] But you aren't perfect, and so maybe you make a mistake, and trigger an Error. The compiler handles this unexpected condition by unwinding the stack back to the main function, printing

Re: Copy Constructor

2022-06-05 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 5 June 2022 at 18:43:19 UTC, Alain De Vos wrote: Does Foo(3) lives on the stack or the heap ? Definitely not stack because that's what happens when the new operator is used. Article 14.3: https://dlang.org/spec/struct.html#intro SDB@79

Re: Copy Constructor

2022-06-05 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 5 June 2022 at 18:50:13 UTC, Salih Dincer wrote: On Sunday, 5 June 2022 at 15:45:17 UTC, Salih Dincer wrote: Hi, Let be the structure Foo that wraps an int pointer. Let's setup Foo in 3 different ways: 1. Foo one = Foo(1); 2. Foo two = 2; 3. [ Foo(3) ]; There is a fourth

Re: Copy Constructor

2022-06-05 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 5 June 2022 at 15:45:17 UTC, Salih Dincer wrote: Hi, Let be the structure Foo that wraps an int pointer. Let's setup Foo in 3 different ways: 1. Foo one = Foo(1); 2. Foo two = 2; 3. [ Foo(3) ]; There is a fourth possibility: ```d int[] arr = [ one, two, Foo(3), *(new Foo(4)) ];

Re: Copy Constructor

2022-06-05 Thread Alain De Vos via Digitalmars-d-learn
I don't know the answer. But some questions come to my mind. Does Foo(3) lives on the stack or the heap ? There is also no assignment from Foo to Foo for Foo(3), there is a conversion. And what happes with Foo[3] arr = [one, two, Foo(3)]; Foo[] arr= [one, two, Foo(3)]; and Foo x=Foo(3).dup()

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 17:04:49 UTC, Ali Çehreli wrote: On 6/5/22 08:07, kdevel wrote: [...] Like many other programmers who include me, Sean Parent may be right.[1] Other than being a trivial example to make a point, the code I've shown may be taking advantage of the "structure of

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 14:24:39 UTC, Ali Çehreli wrote: void add(int i) {// <-- Both arrays always same size a ~= i; b ~= i * 10; } void foo() { assert(a.length == b.length); // <-- Invariant check // ... } Maybe it would help if we can agree that this assert

Re: How to call a GDI+ function from D ?

2022-06-05 Thread Vinod K Chandran via Digitalmars-d-learn
On Sunday, 5 June 2022 at 11:33:14 UTC, Vinod K Chandran wrote: For future readers of this thread, rikki cattermole helped me to findthe solution to this problem. I Do not need the C++ classes or their methods for this. There is a set of C functions in gdiplus.dll. Check this link.

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 08:07, kdevel wrote: > On Sunday, 5 June 2022 at 14:24:39 UTC, Ali Çehreli wrote: > [...] >> struct S { >> int[] a; >> int[] b; >> >> void add(int i) {// <-- Both arrays always same size >> a ~= i; >> b ~= i * 10; >> } >> >> void foo() { >> assert(a.length ==

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
Ok, so I am a bit confused about what is Error and what is not… According to core.exception there is wide array of runtime Errors: ``` RangeError ArrayIndexError ArraySliceError AssertError FinalizeError OutOfMemoryError InvalidMemoryOperationError ForkError SwitchError ``` I am not sure that

Re: Comparing Exceptions and Errors

2022-06-05 Thread matheus via Digitalmars-d-learn
On Sunday, 5 June 2022 at 15:07:13 UTC, kdevel wrote: ... I would refactor the code: I really liked this one. The way it solves and at same time restrict the "external access" with that struct of (a,b) makes the code easier to maintain too. Glad I keep lurking around this forum. Matheus.

Copy Constructor

2022-06-05 Thread Salih Dincer via Digitalmars-d-learn
Hi, Let be the structure Foo that wraps an int pointer. Let's setup Foo in 3 different ways: 1. Foo one = Foo(1); 2. Foo two = 2; 3. [ Foo(3) ]; Pretty clean, right? So why it's not run copy-constructor in 3? Also, when we write to the screen with writeln(), why four times

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 14:24:39 UTC, Ali Çehreli wrote: [...] struct S { int[] a; int[] b; void add(int i) {// <-- Both arrays always same size a ~= i; b ~= i * 10; } void foo() { assert(a.length == b.length); // <-- Invariant check // ... } } void main() {

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/5/22 04:43, kdevel wrote: > On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: > [...] >> Errors are thrown when the program is discovered to be in an invalid >> state. > > The following program throws an `Error` in popFront: > > import std.range; > > void main () > { >

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ali Çehreli via Digitalmars-d-learn
On 6/4/22 23:31, Ola Fosheim Grøstad wrote: > On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: >> Errors are thrown when the program is discovered to be in an invalid >> state. We don't know what happened and when. For example, we don't >> know whether the memory has been overwritten by

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 07:21:18 UTC, Ola Fosheim Grøstad wrote: [...] The reality is that software is layered. Faults at different layers should have different consequences at the discretion of a capable programmer. +1

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 01:43:06 UTC, Steven Schveighoffer wrote: [...] But you aren't perfect, and so maybe you make a mistake, and trigger an Error. The compiler handles this unexpected condition by unwinding the stack back to the main function, printing the error and exiting, so you

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: [...] Errors are thrown when the program is discovered to be in an invalid state. The following program throws an `Error` in popFront: import std.range; void main () { int [1] a; auto q = a[1..$]; // line 6

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 11:13:48 UTC, Adam D Ruppe wrote: On Sunday, 5 June 2022 at 10:38:44 UTC, Ola Fosheim Grøstad wrote: That is a workaround that makes other languages more attractive. It is what a lot of real world things do since it provides additional layers of protection while

Re: How to call a GDI+ function from D ?

2022-06-05 Thread Vinod K Chandran via Digitalmars-d-learn
On Sunday, 5 June 2022 at 10:57:16 UTC, rikki cattermole wrote: Bitmap is a class, not a namespace. The function you want is actually a constructor. https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/gdiplus/gdiplusheaders.h#L179 Thank you for the reply. Well, I know

Re: Comparing Exceptions and Errors

2022-06-05 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 5 June 2022 at 10:38:44 UTC, Ola Fosheim Grøstad wrote: That is a workaround that makes other languages more attractive. It is what a lot of real world things do since it provides additional layers of protection while still being pretty easy to use. *Correctness **is**

Re: How to call a GDI+ function from D ?

2022-06-05 Thread rikki cattermole via Digitalmars-d-learn
Bitmap is a class, not a namespace. The function you want is actually a constructor. https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/gdiplus/gdiplusheaders.h#L179

How to call a GDI+ function from D ?

2022-06-05 Thread Vinod K Chandran via Digitalmars-d-learn
Hi all, I want to call the Bitmap function from gdi+. This is the syntax of the function in C++. ```c++ void Bitmap( [in] const WCHAR *filename, [in] BOOLuseEmbeddedColorManagement ); ``` And this is the mangled name which I got from goldbolt compiler. `?Bitmap@@YAXPEB_WH@Z ` Now,

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 00:18:43 UTC, Adam Ruppe wrote: Run it in a separate process with minimum shared memory. That is a workaround that makes other languages more attractive. It does not work when I want to have 1000+ actors in my game server (which at this point most likely will be

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 07:28:52 UTC, Sebastiaan Koppe wrote: Go has panic. Other languages have similar constructs. And recover. So D will never be able to provide actors and provide fault tolerance. I guess it depends on the programmer. But it isn’t if you cannot prevent Error from

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 07:21:18 UTC, Ola Fosheim Grøstad wrote: You can make the same argument for an interpreter: if an assert fails in the intrrpreter code then that could be a fault in the interpreter therefore you should shut down all programs being run by that interpreter. Typo: if

Re: Comparing Exceptions and Errors

2022-06-05 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Sunday, 5 June 2022 at 06:31:42 UTC, Ola Fosheim Grøstad wrote: On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: That is not very probable in 100% @safe code. You are basically saying that D cannot compete with Go and other «safe» languages. Go has panic. Other languages have

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 03:43:16 UTC, Paul Backus wrote: See here: https://bloomberg.github.io/bde-resources/pdfs/Contracts_Undefined_Behavior_and_Defensive_Programming.pdf Not all software is banking applications. If an assert fails that means that the program logic is wrong, not that the

Re: Does D programming language have work steal queue?

2022-06-05 Thread mw via Digitalmars-d-learn
I will try it. It's in dub now: https://code.dlang.org/packages/liblfdsd Also added queue_umm: unbounded,manyproducer,many_consumer, lock-free queue

Re: Comparing Exceptions and Errors

2022-06-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: Errors are thrown when the program is discovered to be in an invalid state. We don't know what happened and when. For example, we don't know whether the memory has been overwritten by some rogue code. That is not very probable in