On Sunday, 5 February 2023 at 23:53:35 UTC, Ali Çehreli wrote:

I understand disabling the programmer to do certain things are beneficial e.g. to prevent bugs but those above can all be seen as features. What is so terrible about giving the programmer those powers?

Ali

Interestingly, in Swift, you cannot (as far as I can tell) disable init() like you can in D. Thus you cannot prevent the programmer from creating an instance of a class.

And you can forget about 'C# like' static classes in Swift also.

That leaves the question of why 'any' programming language would allow you to instantiate a class that has only static members. What exactly are you going to do with that instance? (i.e. there are no 'instance' members, just 'type' members).

At least in D you CAN disable the initialiser with @disable.

But even after you've done that, the compiler still:
- allows you to declare a variable of that type
- allows you to declare an array with elements of that type
- allows you to use that type as a type argument
- allows you to use that type as a parameter
- allows you to use that type as a return type

So, getting back to your statement.. under what circumstance would a programmer want the 'power' to do any or all of this things, if the programmer has explicately disabled the initialiser, and the type has only static 'type' members?

              • ... ProtectAndHide via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... ProtectAndHide via Digitalmars-d-learn
              • ... Ali Çehreli via Digitalmars-d-learn
              • ... Ali Çehreli via Digitalmars-d-learn
              • ... ProtectAndHide via Digitalmars-d-learn
              • ... Ali Çehreli via Digitalmars-d-learn
              • ... ProtectAndHide via Digitalmars-d-learn
              • ... thebluepandabear via Digitalmars-d-learn
              • ... thebluepandabear via Digitalmars-d-learn
              • ... ProtectAndHide via Digitalmars-d-learn
    • Re: Non-ugl... thebluepandabear via Digitalmars-d-learn
  • Re: Non-ugly way... zjh via Digitalmars-d-learn
    • Re: Non-ugl... zjh via Digitalmars-d-learn
      • Re: Non... thebluepandabear via Digitalmars-d-learn
        • Re:... zjh via Digitalmars-d-learn
          • ... thebluepandabear via Digitalmars-d-learn
            • ... Adam D Ruppe via Digitalmars-d-learn
              • ... thebluepandabear via Digitalmars-d-learn
              • ... Adam D Ruppe via Digitalmars-d-learn
              • ... thebluepandabear via Digitalmars-d-learn

Reply via email to