Re: Why are structs and classes so different?

2022-05-16 Thread bauss via Digitalmars-d-learn
On Sunday, 15 May 2022 at 15:59:17 UTC, Alain De Vos wrote: Can i summarize , structs are value-objects which live on the stack. class instances are reference objects which live on the heap. But that's not entirely true as you can allocate a struct on the heap as well. The real difference is

Re: decimal type in d

2022-05-16 Thread IGotD- via Digitalmars-d-learn
On Sunday, 15 May 2022 at 13:26:30 UTC, vit wrote: Hello, I want read decimal type from sql db, do some arithmetic operations inside D program and write it back to DB. Result need to be close to result as if this operations was performed in sql DB. Something like C# decimal. Exists this kind of

Re: decimal type in d

2022-05-16 Thread bauss via Digitalmars-d-learn
On Monday, 16 May 2022 at 09:46:57 UTC, IGotD- wrote: On Sunday, 15 May 2022 at 13:26:30 UTC, vit wrote: Hello, I want read decimal type from sql db, do some arithmetic operations inside D program and write it back to DB. Result need to be close to result as if this operations was performed in

Re: What are (were) the most difficult parts of D?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 04:00:12AM +, cc via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: > > What are you stuck at? What was the most difficult features to > > understand? etc. > > > > To make it more meaningful, what is your experience with other

Re: Why are structs and classes so different?

2022-05-16 Thread Kevin Bailey via Digitalmars-d-learn
Great responses, everyone. I'll try to address all of them. Mike, I know the rules. I was asking, "Why is it this way? Why was it designed this way? What bad thing happens the other way?" When I think about most things in D, I can at least think of a reason, even if I don't agree with it. But

Re: decimal type in d

2022-05-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/15/22 9:26 AM, vit wrote: Hello, I want read decimal type from sql db, do some arithmetic operations inside D program and write it back to DB. Result need to be close to result as if this operations was performed in sql DB. Something like C# decimal. Exists this kind of library ind D? (id

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:40:59 UTC, SvGaming wrote: On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced form [1] everybody who is willing to help must guess wildly

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced form [1] everybody who is willing to help must guess wildly what the unposted parts of your program does and how it

Re: Why are structs and classes so different?

2022-05-16 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 16 May 2022 at 15:18:11 UTC, Kevin Bailey wrote: I would say that assignment isn't any more or less of an issue, as long as you pass by reference: What I mean is if you write your code for the superclass, and later add a subclass with some invariants that depends on the superclass

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:44:13 UTC, SvGaming wrote: On Monday, 16 May 2022 at 16:40:59 UTC, SvGaming wrote: On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced for

Re: Why are structs and classes so different?

2022-05-16 Thread IGotD- via Digitalmars-d-learn
On Sunday, 15 May 2022 at 16:08:01 UTC, Mike Parker wrote: `scope` in a class variable declaration will cause it to the class to be allocated on the stack. Common practice is that a class has class members itself. So where are they allocated? Most likely is only the top class that is on t

Re: Why are structs and classes so different?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 05:02:57PM +, IGotD- via Digitalmars-d-learn wrote: > On Sunday, 15 May 2022 at 16:08:01 UTC, Mike Parker wrote: > > > > `scope` in a class variable declaration will cause it to the class > > to be allocated on the stack. > > > > Common practice is that a class has cl

D WebAssembly working differently than C++, Zig

2022-05-16 Thread Allen Garvey via Digitalmars-d-learn
I'm working on a comparison of WebAssembly performance for error propagation dithering using D, C++ and Zig. So far C++ and Zig work as expected, but for D, despite using the same algorithm and similar code the output is different. You can see the differences here https://wasm-error-propagati

Re: Why are structs and classes so different?

2022-05-16 Thread Johan via Digitalmars-d-learn
On Sunday, 15 May 2022 at 16:36:05 UTC, Ali Çehreli wrote: On 5/15/22 08:26, Kevin Bailey wrote: > structs and classes are so different. I think a more fundamental question is why structs and classes both exist at all. If they could be the same, one kind would be sufficient. And the answer is

Re: D WebAssembly working differently than C++, Zig

2022-05-16 Thread Adam D Ruppe via Digitalmars-d-learn
I would suspect it is something to do with your memset... even if it needs to take the int (wtf but ldc is weird) you might want to reinterpret cast it to float to avoid any extra conversions.

Re: D WebAssembly working differently than C++, Zig

2022-05-16 Thread kinke via Digitalmars-d-learn
The problem is the memset signature. You assume the length is the number of floats, while it's the number of *bytes* to be set to the specified value. https://en.cppreference.com/w/c/string/byte/memset

Re: D WebAssembly working differently than C++, Zig

2022-05-16 Thread Allen Garvey via Digitalmars-d-learn
On Monday, 16 May 2022 at 18:05:00 UTC, Adam D Ruppe wrote: I would suspect it is something to do with your memset... even if it needs to take the int (wtf but ldc is weird) you might want to reinterpret cast it to float to avoid any extra conversions. I was thinking memset might be the case,

Re: D WebAssembly working differently than C++, Zig

2022-05-16 Thread Allen Garvey via Digitalmars-d-learn
On Monday, 16 May 2022 at 18:14:13 UTC, kinke wrote: The problem is the memset signature. You assume the length is the number of floats, while it's the number of *bytes* to be set to the specified value. https://en.cppreference.com/w/c/string/byte/memset Thanks so much, that fixed the problem

Re: Why are structs and classes so different?

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
A new syntax like "*" should introduce something new. If it's not needed for classes why introduce it. If you don't know if something is a class name it class_blabla. Just remember the effect of "="

Re: Why are structs and classes so different?

2022-05-16 Thread Kevin Bailey via Digitalmars-d-learn
On Monday, 16 May 2022 at 19:06:01 UTC, Alain De Vos wrote: A new syntax like "*" should introduce something new. If it's not needed for classes why introduce it. Hi Alain! I have to sympathize with Johan. If you see: Foo foo = get_foo(); call_function(foo); can 'foo' change in 'call_functio

Re: Why are structs and classes so different?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 10:35, Johan wrote: > What is very problematic is that you cannot see the difference in > syntax. In my opinion it would have been much better if the language > required using a `*` for class types: for example `Foo* a`, and `Foo a` > would simply give a compile error. I see. Is it re

Re: Why are structs and classes so different?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 13:48, Kevin Bailey wrote: > a large code-base written > by thousands of other people. I do every day. I can't make them name > things in any special way. I think we need a comparable D project to know whether this is really an issue. > But when I see the above code, I need to know

Re: Why are structs and classes so different?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 08:18, Kevin Bailey wrote: > I was asking, "Why is it this way? Why was it > designed this way? I for one misunderstood you. I really thought you were arguing that struct and class should be the same. > What bad thing happens the other way?" C++ is proof that it can indeed work th

Re: Why are structs and classes so different?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/15/22 21:20, Tejas wrote: > Never say never : > > https://github.com/dlang/DIPs/blob/master/DIPs/DIP1040.md Thanks! I am reading it now. > Also, there's `opPostMove` already within the language I see: It indeed appears on some pages on dlang.org but the language spec has no mention of it

Re: Why doesn't this piece of code work?

2022-05-16 Thread kdevel via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:53:15 UTC, SvGaming wrote: [...] https://github.com/svgaming234/ezusb forgot to post it in the previous reply, I am kind of stupid In main your program reads an integer: ``` int n; writef("Pick an option: "); readf(" %s", &n); ``` but your console/Termina

Re: Why doesn't this piece of code work?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 15:25, kdevel wrote: > string a; > a = readln(); > writeln(a); > consumes that newline from your first input resulting in variable a > containing the empty string ending with a newline. Great catch! I should put this combination in my chapter. > I am not sure, why %s fit

Re: freebsd dub linker error

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
The problem re-appeared and i have totally no idea what caused it. ldc2 test.d ld: error: undefined hidden symbol: __start___minfo referenced by test.d test.o:(ldc.register_dso) ld: error: undefined hidden symbol: __stop___minfo referenced by test.d test.o:(ldc.regi

Question on shapes

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ?

Re: freebsd dub linker error

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
The following worked , and i don't know what is going on: ``` ldc2 --gcc=gcc11 ```

Re: freebsd dub linker error

2022-05-16 Thread Alain De Vos via Digitalmars-d-learn
Bugs in the clang/llvm toolchain but not in the gcc toolchain ?

Re: Question on shapes

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 17:10, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? There are many ways of achieving thi

Re: Question on shapes

2022-05-16 Thread matheus via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: ... 2) If you want to have a shape hierarchy, then you can start by defining its interface and implement that interface by concrete shape types. Drawing is ordinarily handled by member functions: ... Hi Ali, I'm not the author but I

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 22:25:23 UTC, kdevel wrote: On Monday, 16 May 2022 at 16:53:15 UTC, SvGaming wrote: [...] [...] In main your program reads an integer: ``` int n; writef("Pick an option: "); readf(" %s", &n); ``` [...] Thanks for the help!

Re: Question on shapes

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 22:08, matheus wrote: > interface Shape { >void draw(); >void draw(float scale); > } Interfaces can have 'final' functions: interface Shape { void draw(float scale); final void draw() { draw(1); } } Obviously, for that to work, now Circle.draw() etc. required to r

Re: Question on shapes

2022-05-16 Thread bauss via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? In addition

Re: Question on shapes

2022-05-16 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 05:08:30 UTC, matheus wrote: In D there would be a better way to do such thing? Nothing really specific to D, but for one or two properties, you might just add them as function parameters with default values: ```d void draw(float scale = 1.0f); ``` If you have

Re: What are (were) the most difficult parts of D?

2022-05-16 Thread cc via Digitalmars-d-learn
On Monday, 16 May 2022 at 15:08:15 UTC, H. S. Teoh wrote: If you find yourself having to cast to/from immutable, you're using it wrong. I clearly was, which is why I'm not using it anymore. The question was "What are you stuck at? What was the most difficult features to understand? etc.", so I