For unary case:
// original:
%%io.stdout.printf("Hello, world!\n");
// my favorite ideas:
try io.stdout.printf("Hello, world!\n");
dare io.stdout.printf("Hello, world!\n");
// others:
err io.stdout.printf("Hello, world!\n");
ex io.stdout.printf("Hello, world!\n");
bet io.stdout.printf("Hello, world!\n");
bid io.stdout.printf("Hello, world!\n");
For the binary operator: // my favorite ideas:
a yet b
a odd b
a but b
a ex b // extra or except
a err b
a bail b
// others:
a else b // Would overloading the meaning have sense?
a esc b // escape
a alt b // alternate
a aux b // auxiliary
a sub b // substitute
a prox b // proxy
a then b
a eor b // error or
a repl b // replacement
a supp b // supplemental
a %or bKeywords can also benefit from the fact that 99% of programmers know at least the basic English words, while special characters are not necessarily international. They might not be used, they might not have the same meaning. I'm speaking more about "&" here, but it applies to other characters as well.
%defer %return
For %defer:
error defer deallocateFoo(foo);
but defer deallocateFoo(foo);
ex defer deallocateFoo(foo);
failsafe deallocateFoo(foo);
bail defer deallocateFoo(foo);
For %return: fn doAThing(str: []u8) -> %void {
const number = try parseU64(str, 10);
// ...
}
"try" could mean "return an error in case of an error" aka "%return". Then "dare"
could mean "panic in case of an error" aka "%%foo();".Or use "ex" or "but" everywhere:
ex foo();
const num = foo() ex 42;
const num = ex foo();
ex defer bar(baz);
but foo();
const num = foo() but 42;
const num = but foo();
but defer bar(baz);I really like the use of keywords, leveraging our extensive understanding and intuition of language to make a language more clear and intuitive.
Symbolic operators work well if they are borrowed from math (e.g. third grade), making up new ones often results in a painful learning phase.
catch defer dealloc(foo);I think things like "a|b" and "a&b" for or/and is fine - but when you need to stack them two and three deep, keywords starts to look more attractive... I think this holds true even for the relatively benign tripple-equal (===) used as a kind of stand-in for "a is b".
BTW, did I miss an obvious short intro to what these things are supposed to mean in zig? I feel I've overlooked an obvious quick-start document?
[ed: never mind - the post is just a bit hard to read on a cellphone - but nothing reader mode in Firefox can't fix]
const number = parseU64(str, 10) %% |err| return err;
Keeping the %% syntax, how about: const number = parseU64(str, 10) %% throw;
(Or "raise" maybe)I think that ordering is more readable than having the %return tucked away in the middle of the line (even more so if it becomes a plain keyword, no % sign).
Edit to add: a "throw" keyword could also be used to shorten normal error returns too:
return error.InvalidChar;
Becomes: throw InvalidChar;For "%return", perhaps "should" or "handle", as in, "This function should return without an error, but if it does, handle it."