On Wednesday, 18 May 2022 at 10:53:03 UTC, forkit wrote:
Here is a very interesting article that researches this subject.
Yeah, he got it right. It is syntax sugar that makes verbose C++
code easier to read. Use struct for internal objects and tuple
like usage and class for major objects in y
On Sunday, 15 May 2022 at 21:33:24 UTC, Ali Çehreli wrote:
I still think my answer is the real one. My implied question
remains: Why does C++ have struct and class disticnction? I
know they have different default access specifications but does
that warrant two kinds?
Here is a ver
On Monday, 16 May 2022 at 21:20:43 UTC, Ali Çehreli wrote:
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 `
On 5/17/22 07:40, Kevin Bailey wrote:
> Foo foo;
>
> is undefined behavior waiting to happen, that I can't detect at a glance.
Foo is null there. (I don't remember whether accessing through null
reference is undefined or segmentation fault (on common systems).) Using
foo will not do some rando
On Tuesday, 17 May 2022 at 14:40:48 UTC, Kevin Bailey wrote:
Foo foo;
is undefined behavior waiting to happen, that I can't detect at
a glance.
It is actually perfectly well defined - for the class, it will be
null, and this will kill the program if you use it.
You might not like that defi
Hi again Ali!
On Monday, 16 May 2022 at 21:58:09 UTC, Ali Çehreli wrote:
I for one misunderstood you. I really thought you were arguing
that struct and class should be the same.
To be specific:
- My *primary* concern is that:
Foo foo;
is undefined behavior waiting to happen, that I can't d
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
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
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
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
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
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 "="
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
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
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
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
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
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
On Sunday, 15 May 2022 at 21:33:24 UTC, Ali Çehreli wrote:
D programmers don't write move constructors or move assignment.
Such concepts don't even exist.
Never say never :
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1040.md
Walter is one of the authors of the DIP
Also, there's `op
On 5/15/2022 8:26 AM, Kevin Bailey wrote:
I'm trying to understand why it is this way.
Great question.
The difference, in a nutshell, is a struct is a value type, and a class is a
reference type. This difference permeates every facet their behavior.
In C++, a struct can designed to be a valu
On Sunday, 15 May 2022 at 15:26:40 UTC, Kevin Bailey wrote:
I've done some scripting in D over the years but I never dug
into D until recently. I'm going through Learning D and I was
reminded that structs and classes are so different.
- struct methods are non-virtual while class methods are vi
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.
the real difference, is that structs, being value types, are
passed by value, and classes, being refere
On Sun, May 15, 2022 at 08:05:05PM +, Kevin Bailey via Digitalmars-d-learn
wrote:
[...]
> But I asked a different question: Why can't I put a class object on
> the stack? What's the danger?
[...]
You can. Use core.lifetime.emplace.
Though even there, there's the theoretical problem of stack
On 5/15/22 13:05, Kevin Bailey wrote:
> I've been programming in C++ full time for 32 years
Hi from an ex-C++'er. :) I managed to become at least a junior expert in
C++ between 1996-2015. I don't use C++ since then.
I still think my answer is the real one. My implied question remains:
Why do
On Sunday, 15 May 2022 at 20:05:05 UTC, Kevin Bailey wrote:
One question is, how should we pass objects - by value or by
reference? In C++, you can do either, of course, but you take
your chances if you pass by value - both in safety AND
PERFORMANCE. The bottom line is that no one passes by
On Sunday, 15 May 2022 at 20:05:05 UTC, Kevin Bailey wrote:
I've been programming in C++ full time for 32 years, so I'm
familiar with slicing. It doesn't look to me like there's a
concern here.
Yes, slicing is not the issue. Slicing is a problem if you do
"assignments" through a reference tha
Hi Mike (and Guillaume, since you posted the same link),
Thanks for the long explanation.
I've been programming in C++ full time for 32 years, so I'm
familiar with slicing. It doesn't look to me like there's a
concern here.
There seem to be a couple different questions here. I suspect
that
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 there are value types and there are reference types in
pro
On Sunday, 15 May 2022 at 15:26:40 UTC, Kevin Bailey wrote:
I'm trying to understand why it is this way. I assume that
there's some benefit for designing it this way. I'm hoping that
it's not simply accidental, historical or easier for the
compiler writer.
There's a problem that arises with
On Sunday, 15 May 2022 at 15:26:40 UTC, Kevin Bailey wrote:
I'm trying to understand why it is this way. I assume that
there's some benefit for designing it this way. I'm hoping that
it's not simply accidental, historical or easier for the
compiler writer.
Perhaps someone more informed will c
Can i summarize ,
structs are value-objects which live on the stack.
class instances are reference objects which live on the heap.
I've done some scripting in D over the years but I never dug into
D until recently. I'm going through Learning D and I was reminded
that structs and classes are so different.
- struct methods are non-virtual while class methods are virtual
- Thus, structs can't inherit, because how would you fi
32 matches
Mail list logo