Thread overview
Extending the language syntax for easy programming and code readability.
Apr 15
Orion
5 days ago
Atila Neves
April 15

For me, in the D language, one of the key features of the language is the ability to use internal classes (although I would also like to have internal structures)

However, writing extra nesting levels (class in class) does not look attractive (especially if there is more than one nesting level).

In this regard, I would like to have the ability to have an alternative syntax for writing
internal and possibly nested classes and structures,
for textual alignment of them in a line (getting rid of nesting).

The proposed syntax for internal classes:

class A;  //outer
{
    fields;
    ...
    class B; //inner prototype
}

class A.B //inner
{
  fields;
  ...
  class C; // 2-th inner prototype
  class D;
}

class A.B.C
{
  fields;
  ...
}

class A.B.D
{
  fields;
  ...
}

Well, to avoid getting up twice, a similar mechanism can be implemented for nested functions:

type f(type var)
{
  instructions;
  type g(type var); //  nested prototype
}

type f.g(type var)
{
  instructions;	
}

Naturally, the scopes for these nested definitions are limited to modules.

April 16

On Tuesday, 15 April 2025 at 06:49:30 UTC, Orion wrote:

>

[...]
for textual alignment of them in a line (getting rid of nesting).
[...]

Can you prove, that no development system or smart enough text editor will be able to emulate the described behaviour, but every compiler can do?
Otherwise: how high is the upper bound for the count of syntactical sugars every maintenance programmer has to be avair of?

-manfred

5 days ago

On Tuesday, 15 April 2025 at 06:49:30 UTC, Orion wrote:

>

For me, in the D language, one of the key features of the language is the ability to use internal classes (although I would also like to have internal structures)

However, writing extra nesting levels (class in class) does not look attractive (especially if there is more than one nesting level).

If one has to worry about how many nesting levels there are for classes, I would say that one should probably reorganise the code so that no such problems exist.

See the arrow anti-pattern: https://wiki.c2.com/?ArrowAntiPattern