I'm implementing a programming language and I'm considering the following syntax:
@NamespaceX
{
+@ClassY <> : BaseTypeA
{
+@NestedClassW<>
{
}
+@MethodZ() : ReturnTypeC
{
//".?" is a null-coallescing member access operator
@varD : ClassY = predicateP ? objectQ.?PropertyS
: predicateR ? valueB;
@varE = predicateP ? varD : throw Exception1();
@f : ClassY -> ClassZ = param1 => MethodV(param1);
}
}
+@UnitTest() [Test]
{
}
}
The following is the equivelant code in C# 3.0:
namespace NamespaceX
{
public class ClassY : BaseTypeA
{
public class NestedClassW
{
}
public ReturnTypeC MethodZ()
{
ClassY varD = predicateP ? ((objectQ!=null) ? objectQ.PropertyS
: null)
: predicateR ? valueB
: null;
ClassY varE;
if (predicateP) varE = varD;
else throw new Exception1();
Func<ClassY,ClassZ> f = param1 => MethodV(param1);
}
}
public _NamespaceX() //non-type namespace members
{
[Test]
public void UnitTest() {}
}
}
Which one would you rather write in? Which one is more readable? The code is terse in both examples but in the case of the C# example, once you're familiar with the idioms used I think it should be readable enough. I just want to know what you find good or bad about this syntax, not necessarily suggested improvements although those are fine, too, to explain what you're more into.
The language I'm designing is primarily an alternative to C# (but not necessarily meant for existing C# users to wholeheartedly adopt). The main consideration I had for readability is for having a single character declaration operator "@" with a single character accessibility operator ("+" for public or "-" for private) so that the name is close to the left margin where it can be easily scanned for instead of rooting through "public static void TheName ()" and such. I think that the "@" also makes it easier to scan for declarations of any kind as opposed to using a keyword which is indistinguishable from other keywords when scanning.
I'm going for both the stream-of-consciousness writing and at-a-glance reading aspects so I want feedback on more than just the "+@" part—for me, english keywords get in the way for these two activities (moreso in VB than C#) so I've decided to go with terse symbols to imply the declaration constructs:
@foo { } //namespace foo {}
+@foo() : Bar {} //public Bar foo() {}
+@Foo<> : Bar {} //public class Foo : Bar {}
@foo : Bar = baz; //Bar foo = baz;
@foo = p ? bar //var foo = p ? bar : null;
@foo = bar.?baz; //var foo = (bar != null) ? bar.baz : null;
foo = p ? bar : throw E(); //if (p) foo = bar; else throw new E();
Feel free to change the identifiers to something more meaningful but please preserve the code's structure. I am open to suggestions, however, for making the C# example more readable while remaining faithful as a translation of the first example.
[I put in a close vote for this "being no longer relevant" since to really do this justice would take too much work for my purposes - Mark]