Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread zjh via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 12:44:19 UTC, zjh wrote: Right... They greatly increase your code maintenance work! Many people left D because of these small details! Their encapsulation can actually leakage class members. Programmers in other languages will laugh cry!

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Thursday, 16 February 2023 at 02:56:28 UTC, ProtectAndHide wrote: What a joke. Even Javascript can do this (and the compile will enforce it too). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Thursday, 16 February 2023 at 02:26:44 UTC, Mike Parker wrote: On Wednesday, 15 February 2023 at 20:10:31 UTC, ProtectAndHide wrote: What Mike is arguing, is that I don't need a 'data hiding' mechanism for a user-defined type, because that is already provided to me by the 'data hiding' m

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Thursday, 16 February 2023 at 02:26:44 UTC, Mike Parker wrote: On Wednesday, 15 February 2023 at 20:10:31 UTC, ProtectAndHide wrote: What Mike is arguing, is that I don't need a 'data hiding' mechanism for a user-defined type, because that is already provided to me by the 'data hiding' m

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 16 February 2023 at 02:26:44 UTC, Mike Parker wrote: Wrong. I'm arguing things: Geez. "I'm arguing 2 things:"

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 20:10:31 UTC, ProtectAndHide wrote: What Mike is arguing, is that I don't need a 'data hiding' mechanism for a user-defined type, because that is already provided to me by the 'data hiding' mechanism of the module. That is his argument. My argument is tha

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 20:34:13 UTC, thebluepandabear wrote: On Wednesday, 15 February 2023 at 20:06:18 UTC, bachmeier wrote: On Wednesday, 15 February 2023 at 07:13:41 UTC, thebluepandabear wrote: Time to move on to OCaml programmers telling us D doesn't have floating point arithmet

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 20:06:18 UTC, bachmeier wrote: On Wednesday, 15 February 2023 at 07:13:41 UTC, thebluepandabear wrote: Time to move on to OCaml programmers telling us D doesn't have floating point arithmetic because there's no `+.` operator. that's not the same thing though,

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 20:10:31 UTC, ProtectAndHide wrote: ... this is not to be personal, just to make an analogy about the point being made: if Mike was a car salesperson, he'd be arguing that I don't need an automatic transmission. I can already do it manually. Why should we

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 20:01:12 UTC, bachmeier wrote: On Wednesday, 15 February 2023 at 19:44:50 UTC, ProtectAndHide wrote: A user-defined type is a type that has a mechanism to keep it representation private. D does not support this. It only enables it. You (and others) may well

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 07:13:41 UTC, thebluepandabear wrote: Time to move on to OCaml programmers telling us D doesn't have floating point arithmetic because there's no `+.` operator. that's not the same thing though, you've created a great false equivalence! Congrats. Only if you

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 19:44:50 UTC, ProtectAndHide wrote: "The basic support for programming with data abstraction consists of facilities for defining a set of operations (functions and operators) for a type and for restricting the access to objects of the type to that set of op

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 19:44:50 UTC, ProtectAndHide wrote: A user-defined type is a type that has a mechanism to keep it representation private. D does not support this. It only enables it. You (and others) may well argue that D should not enable this (directly), it should only s

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 10:17:30 UTC, Mike Parker wrote: I referenced that in my post. The exact same problem exists *inside* the class when your class file is very long. You can easily manipulate the private member even when it's only supposed to be accessed by a specific function.

Debugging memory leaks

2023-02-15 Thread Hipreme via Digitalmars-d-learn
I want to know if there is some way to debug memory leaks in runtime. I have been dealing with that by using a profiler and checking D runtime function calls. Usually those which allocates has high cpu usage so it can be easy for those bigger ones. While for the smaller ones, this approach do

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread zjh via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 09:57:56 UTC, ProtectAndHide wrote: In a module that contains a class, and other code as well (perhaps other tightly coupled classes), you can know **nothing** at all about that type (or any other class) without knowing **everything** else in the module. If o

Re: toString best practices

2023-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 9 February 2023 at 17:49:58 UTC, Paolo Invernizzi wrote: ``` import std.format, std.range.primitives; struct Point(T) { T x, y; void toString(W)(ref W writer, scope const ref FormatSpec!char f) const if (isOutputRange!(W, char)) { put(writer, "(");

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 08:56:00 UTC, Mike Parker wrote: Our friend of many forum handles misses no opportunity to return to this putrid horse corpse to beat it some more, but the meaning of private isn't going to change. This is D's approach to encapsulation. It seems the only be

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 08:56:00 UTC, Mike Parker wrote: Our friend of many forum handles misses no opportunity to return to this putrid horse corpse to beat it some more, but the meaning of private isn't going to change. This is D's approach to encapsulation. It seems the only be

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 10:17:30 UTC, Mike Parker wrote: We keep repeating the same arguments over and over and over again on this. I still haven't seen any convincing argument for changing things when it's already possible to do what you want to do. I repeat for the umpteenth time:

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread zjh via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 10:17:30 UTC, Mike Parker wrote: I referenced that in my post. The exact same problem exists *inside* the class when your class file is very long. You can easily manipulate the private member even when it's only supposed to be accessed by a specific function.

Re: How can I easily determine the last charachter of a file?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Tuesday, 14 February 2023 at 18:30:05 UTC, seany wrote: Hello Consider the content of a file First line \n Second line data data data data ... last char My goal is to find out whether the last character is a new line or not. Please not, it will be sufficient if this w

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 09:51:41 UTC, zjh wrote: What if two classes in the module that are several meters apart make `mistakes` that change the privite variable of `another class`? No one can guarantee that after `a few months`, even if you are the author, you will not make mist

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 09:51:41 UTC, zjh wrote: On Wednesday, 15 February 2023 at 08:57:27 UTC, Mike Parker wrote: I meant to say, it "wouldn't add more". What if two classes in the module that are several meters apart make `mistakes` that change the privite variable of `another

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 07:23:39 UTC, thebluepandabear wrote: On Wednesday, 15 February 2023 at 02:14:30 UTC, Mike Parker wrote: On Wednesday, 15 February 2023 at 01:16:00 UTC, thebluepandabear wrote: I think what you could say is that D lacks _encapsulation_ which is also an OOP

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread zjh via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 08:57:27 UTC, Mike Parker wrote: I meant to say, it "wouldn't add more". What if two classes in the module that are several meters apart make `mistakes` that change the privite variable of `another class`? No one can guarantee that after `a few months`, e

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread ProtectAndHide via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 08:57:27 UTC, Mike Parker wrote: On Wednesday, 15 February 2023 at 08:56:00 UTC, Mike Parker wrote: If private were restricted to the class/struct, it would add anything more for encapsulation in D. I meant to say, it "wouldn't add more". Well, to quote St

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 08:56:00 UTC, Mike Parker wrote: If private were restricted to the class/struct, it would add anything more for encapsulation in D. I meant to say, it "wouldn't add more".

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 07:23:39 UTC, thebluepandabear wrote: Why is the unit of encapsulation the module though? Makes no sense. What is the purpose of encapsulation? To keep the implementation details hidden behind the public API, such that changing the implementation doesn't