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 ans
here is good reason I use
classes -- usually when I need inheritance, which is also when by-value
types would encounter truncation issues. Since it *is* possible to pass
around pointers to structs, I don't really see much reason for using
classes if you don't need inheritance, i.e., when you'
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 m
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
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, becaus
On 07/26/2017 02:54 AM, Houdini wrote:
On Tuesday, 25 July 2017 at 17:16:00 UTC, Kagamin wrote:
On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote:
Yes, but it isn't the default way in C++ to do dynamic instanciation.
https://github.com/isocpp/CppCoreGuidelines this? It's only 2 years
ol
On Monday, 24 July 2017 at 17:42:30 UTC, Steven Schveighoffer
wrote:
On 7/24/17 11:45 AM, Houdini wrote:
On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer
wrote:
Because types with inheritance generally don't work right if
you pass by value (i.e. the slicing problem).
structs do
On Tuesday, 25 July 2017 at 17:16:00 UTC, Kagamin wrote:
On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote:
Yes, but it isn't the default way in C++ to do dynamic
instanciation.
https://github.com/isocpp/CppCoreGuidelines this? It's only 2
years old. The new operator predates it by deca
On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote:
Yes, but it isn't the default way in C++ to do dynamic
instanciation.
https://github.com/isocpp/CppCoreGuidelines this? It's only 2
years old. The new operator predates it by decades.
On Tuesday, 25 July 2017 at 15:15:59 UTC, Kagamin wrote:
C++ is big, there's always something you don't know about it.
Java actually instantiates classes the C++ way:
http://en.cppreference.com/w/cpp/language/new
Yes, but it isn't the default way in C++ to do dynamic
instanciation. Usually,
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote:
D is very similar to C++ (and also grabs godd ideas from
Python), but I have a naive question : why does Walter Bright
chose to instanciate classes like in Java ?
C++ is big, there's always something you don't know about it.
Java actuall
On Monday, 24 July 2017 at 17:42:30 UTC, Steven Schveighoffer
wrote:
In D, I would use classes for any time I need polymorphism, and
use structs otherwise.
OK, I'll adhere to this method. :)
Thanks to all for your answers.
On 7/24/17 11:45 AM, Houdini wrote:
On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote:
Because types with inheritance generally don't work right if you pass
by value (i.e. the slicing problem).
structs don't support inheritance or virtual functions, so they can be
safely pa
On Mon, Jul 24, 2017 at 03:45:29PM +, Houdini via Digitalmars-d-learn wrote:
> But in C++, we pass them by reference also to avoid copies (const &).
Exactly... in C++ you basically always pass by reference, so D made that the
default.
On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer
wrote:
Because types with inheritance generally don't work right if
you pass by value (i.e. the slicing problem).
structs don't support inheritance or virtual functions, so they
can be safely passed by value.
But in C++, we pass
On Monday, 24 July 2017 at 15:37:51 UTC, Andrea Fontana wrote:
Maybe this will help you:
https://stackoverflow.com/questions/10965577/usage-preference-between-a-struct-and-a-class-in-d-language
Thanks for this informative link.
On 7/24/17 11:21 AM, Houdini wrote:
Hello,
I am a C++ coder, and I am learning D (just reading a book, for now).
D is very similar to C++ (and also grabs godd ideas from Python), but I
have a naive question : why does Walter Bright chose to instanciate
classes like in Java ? And why is it dif
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote:
Hello,
I am a C++ coder, and I am learning D (just reading a book, for
now).
D is very similar to C++ (and also grabs godd ideas from
Python), but I have a naive question : why does Walter Bright
chose to instanciate classes like in Ja
Hello,
I am a C++ coder, and I am learning D (just reading a book, for
now).
D is very similar to C++ (and also grabs godd ideas from Python),
but I have a naive question : why does Walter Bright chose to
instanciate classes like in Java ? And why is it different for
structs ?
On 1/31/2012 7:45 PM, Mars wrote:
Hello everybody.
I couldn't really think of a good title for this. It's just a little
question, about this example code:
http://pastie.org/private/4xqtze47dlx9fy9pn53sq
Apperantly I get a copy of Bar, when I call bar(), and it doesn't modify
the actual variable
Hello everybody.
I couldn't really think of a good title for this. It's just a
little question, about this example code:
http://pastie.org/private/4xqtze47dlx9fy9pn53sq
Apperantly I get a copy of Bar, when I call bar(), and it doesn't
modify the actual variable of the object. But if I define B
48 matches
Mail list logo