4 ms·
This is the ugliest thing about zig. Can you come up with a better proposal to capture the semantics? I'd love to see it. I've tried and this is the best I can
by AndyKelley 9y ago
This is the ugliest thing about zig. Can you come up with a better proposal to capture the semantics? I'd love to see it. I've tried and this is the best I can do.
- hawski 9y agoA keyword maybe? 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 b
- oblio 9y agoAgreed. A short keyword is generally better than a symbol. Yes, you do get used to symbols, but words come naturally. "a and b" is easy to read, easy to explain and read by newbies and overall much, much nicer in my opinion than the 1-letter-shorter "a && b". Keywords 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.
- AndyKelley 9y agoThese are good ideas. we also need alternatives for these : %defer %return
- hawski 9y agoSome may fit previous propositions. 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);
- ant6n 9y agoEx sounds a lot like example, rather than exception. 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.
- iainmerrick 9y agoHow about "catch"? Zig doesn't have the usual try/catch blocks but the meaning is similar. catch defer dealloc(foo);
- e12e 9y agoAm I right in assuming that single ampersand is taken (like in C and/or for bitwise ops)? 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]
- iainmerrick 9y agoFrom the docs, the prefix %return is a shortcut for: 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;
- explainplease 9y ago"must" might be a good alternative for "%%", as in, "this call must return without an error." or "this call must work." For "%return", perhaps "should" or "handle", as in, "This function should return without an error, but if it does, handle it."
- iainmerrick 9y agoI specifically like the similarity between ?? and %% -- they do do similar things! -- so please keep that in some way if you can.