Skip to main content
14 events
when toggle format what by license comment
Apr 24, 2024 at 14:20 comment added Caleth @JimmyJames well C only has the keyword struct, and has no member functions nor access modifiers. So for compatibility with C, C++ has structs that default to public and a convention that they have no member functions. Nowadays those are called DTOs, but they weren't at the time
Apr 24, 2024 at 14:18 comment added JimmyJames @Caleth Is the DTO approach something that came out of C++? I always assumed it came from the Java world.
Apr 24, 2024 at 8:12 comment added Caleth @JimmyJames it's literally true from the language standpoint, but conventions very quickly arose to distinguish DTOs from behavioural classes. You can even exchange class and struct in a forward declaration (but many compilers will warn you've mixed them)
Apr 23, 2024 at 19:22 comment added JimmyJames Absolutely. The difference between what you can do and what you should do is one metric of the language's usability. There's more to it than that, of course, but I think it's clear that a device or machine that prevents users from making errors is superior, all else being equal.
Apr 23, 2024 at 18:25 comment added candied_orange @JimmyJames he refused to call c++ a high level language. Always insisted it was a "wide language". It could go low or high. My problem was c++ let you do so many things you shouldn't do. I mean, why isn't undefined behavior at least a warning?
Apr 23, 2024 at 18:07 comment added JimmyJames Apparently you can have virtual methods on a struct. C++ never stops surprising.
Apr 23, 2024 at 17:51 comment added candied_orange @JimmyJames well this was decades ago. Many new c++ versions have come out. But he was on the language steering committee so I'm confident he knows what he's talking about. Still, it looks weird when you hang methods on a struct.
Apr 23, 2024 at 17:29 comment added JimmyJames Hmm. I'm not sure I believe that. But it's been a long time since I wrote any C++ and I'm quite certain I didn't really understand it then either.
Apr 23, 2024 at 17:25 comment added candied_orange @JimmyJames as my c++ professor loved to tell us, "The only difference between a class and a struct is a class defaults to private"
Apr 23, 2024 at 17:24 comment added JimmyJames The reason I point that out is if one only uses dataclasses for DTOs, would your recommendation then be to default to private on all 'normal' classes?
Apr 23, 2024 at 17:17 comment added candied_orange @JimmyJames true. And in Java I've become a fan of using LinkedHashMap. Turns out maps can be ordered.
Apr 23, 2024 at 16:15 comment added JimmyJames W/ regard to DTOs, Python (3.7 and beyond) has dataclasses which I think are preferrable to hand-coded DTOs. I really like pydantic which is essentially an extension of dataclasses.
Apr 23, 2024 at 14:16 history edited candied_orange CC BY-SA 4.0
added 464 characters in body
Apr 23, 2024 at 12:08 history answered candied_orange CC BY-SA 4.0