Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Radical simplification of the C# syntax #13731

Closed
OJacot-Descombes opened this issue Sep 11, 2016 · 11 comments
Closed

Proposal: Radical simplification of the C# syntax #13731

OJacot-Descombes opened this issue Sep 11, 2016 · 11 comments
Labels
Area-External Resolution-External The behavior lies outside the functionality covered by this repository

Comments

@OJacot-Descombes
Copy link

OJacot-Descombes commented Sep 11, 2016

Well, that would be a new language of course. But a language with essentially the same semantics as C#. Let's call it D# (D-Sharp). Why: save typing, remove visual noise.

Instead of writing (C#):

using static System.Console;

namespace Example.CSharp // Namespace is nesting
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 20;

            if (a == 10) {
                if (b == 20) {
                    WriteLine("Value of a is 10 and b is 20");
                } else if (b > 50) {
                    WriteLine("Value of a is 10 and b greater than 50");
                } else {
                    WriteLine("Value of a is 10");
                }
            }

            switch (a)
            {
                case 0:
                case 1:
                case 2:
                    WriteLine("Low number");
                    break;
                case 3:
                case 4:
                case 5:
                    WriteLine("Medium number");
                    break;
                default:
                    WriteLine("Other number");
                    break;
            }

            while (a < 1000) {
                WriteLine(a);
                a *= 2;
            }

            do {
                WriteLine(b);
                b *= 2;
            } while (b < 1000)

            ReadLine();
        }
    }
}

we would write (D#):

using static System.Console

namespace Example.DSharp // Namespace is a not nesting, thus saving one indentation level.

class Program

    static void Main(string[] args)

        int a = 10
        int b = 20

        if a == 10
            if b == 20
                WriteLine("Value of a is 10 and b is 20")
            elsif b > 50
                WriteLine("Value of a is 10 and b greater than 50")
            else
                WriteLine("Value of a is 10")

        switch a
            case 0, 1, 2
                WriteLine("Low number")
            case 3, 4, 5
                WriteLine("Medium number")
            default
                WriteLine("Other number")

        while a < 1000
            WriteLine(a)
            a *= 2

        do
            WriteLine(b)
            b *= 2
        until b >= 1000 // Since while would be ambiguous, we use until instead.

        ReadLine()

The syntax would be line-oriented with smart line continuation. Blocks would solely be defined by indentation (as in python).

Of course there is a lot more to be nailed down, but this is only the starting point for a discussion. What do you think of it?

@OJacot-Descombes OJacot-Descombes changed the title Radical simplification of the C# syntax Proposal: Radical simplification of the C# syntax Sep 11, 2016
@HaloFour
Copy link

This is a dupe of #2974, which has already been closed because it's a ridiculously silly idea. C# is not, nor will it ever be, a whitespace sensitive language. It was not designed as such. So braces and semi-colons remain necessary to disambiguate the syntax.

If you want Python syntax on the CLR feel free to use IronPython. There's no reason to morph the C# compiler into compiling the grammar from other arbitrary languages.

@OJacot-Descombes
Copy link
Author

Of course C# will never be a whitespace sensitive language! The C# compiler remains as is. There would be a new D# compiler. This is a proposal for a new language called D# with similar semantics as C# (you can reuse all your C# knowledge!). Is it really silly to provide the same power, but with a much simpler syntax?

@HaloFour
Copy link

There would be a new D# compiler.

What does that have to do with this repo, then? Roslyn is specifically C# and VB.NET compilers. It's not generalized for other language implementations. You're free to fork Roslyn and modify the C# parser.

Is it really silly to provide the same power, but with a much simpler syntax?

In my opinion, yes. Whitespace sensitivity isn't simpler, it's just different. To have duplicity of functionality with only a difference in grammar sounds terribly redundant. There are already numerous CLR languages that are whitespace sensitive.

@vbcodec
Copy link

vbcodec commented Sep 11, 2016

switch to VB. There are much less braces and none semicolons. Despite more keywords, paradoxically there is less to type, because editor autogenerate most of them.

@alrz
Copy link
Member

alrz commented Sep 11, 2016

F# is whitespace significant and has a "simplified" syntax to an extent that seem like it infers program logic from developer's feelings.

@gafter
Copy link
Member

gafter commented Sep 11, 2016

@OJacot-Descombes Great idea. Can you please create a dedicated github repo for its development?

@OJacot-Descombes
Copy link
Author

Does someone know how to create a new repo for d-sharp as clone of C# roslyn? It should not be a fork, as the future work should not interfere with the existing C# compiler.

@dsaf
Copy link

dsaf commented Sep 12, 2016

Pretty sure someone could write a plugin for VS supporting *.ds files that would generate *.cs on save by adding punctuation marks.

@svick
Copy link
Contributor

svick commented Sep 12, 2016

@OJacot-Descombes

  1. Clone Roslyn into a directory: git clone https://github.com/dotnet/roslyn.git roslyn-not-a-fork, cd roslyn-not-a-fork
  2. Create a new repo on GitHub, I named it roslyn-not-a-fork
  3. Change the url of the origin remote using git config -e to that of the new repo, in my case, the new URL is git@github.com:svick/roslyn-not-a-fork.git
  4. Push: git push

The result looks like svick/roslyn-not-a-fork (compare with svick/roslyn, which is a fork).

@OJacot-Descombes
Copy link
Author

Since a lot of work has to be done before we can start to write a compiler (of course based on the C#/Roslyn compiler) I created an empty repository here. Let's continue the discussion and development of D# (D-Sharp) there.

@gafter
Copy link
Member

gafter commented Sep 12, 2016

Discussion redirected to OJacot-Descombes/dsharp#1

@gafter gafter closed this as completed Sep 12, 2016
@gafter gafter added the Resolution-External The behavior lies outside the functionality covered by this repository label Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-External Resolution-External The behavior lies outside the functionality covered by this repository
Projects
None yet
Development

No branches or pull requests

7 participants