Live data from Hacker News

Zig's Lovely Syntax

matklad.github.io

61–70 of 246 posts

Re: Zig's Lovely Syntax

#62
I much prefer C# 11's raw string literals. It takes the indentation of the first line and assumes the subsequent ones have the same indentation.

  string json = $"""
      {title}
      
          Welcome to {sitename}.
      
      """;
And it even allows for using embedded curly braces as real characters:

  string json = $$"""
      {{title}}
      
          Welcome to {{sitename}}, which uses the {sitename} syntax.
      
      """;
The $ (meaning to interpolate curly braces) appears twice, which switches interpolation to two curly braces, leaving the single ones untouched.

Re: Zig's Lovely Syntax

#63
post #15

> C uses a needlessly confusing spiral rule Libellous! The "spiral rule" for C is an abomination and not part of the language. I happen to find C's type syntax a bit too clever for beginners, but it's marvellously consistent and straightforward. I can read types fine without that spiral nonsense, even if a couple of judicious typedefs are generally a good idea for any fancy function types.

It's not context free though.

It is context free, just ambiguous.

Re: Zig's Lovely Syntax

#64
post #54

> Raw or multiline strings are spelled like this: const still_raw = \\const raw = \\ \\Roses are red \\ \\ Violets are blue, \\ \\Sugar is sweet \\ \\ And so are you. \\ \\ \\; \\ ; This syntax seems fairly insane to me.

Maybe if you've never tried formatting a traditional multiline string (e.g. in Python, C++ or Rust) before.

If it isn't obvious, the problem is that you can't indent them properly because the indentation becomes part of the string itself.

Some languages have magical "removed the indent" modes for strings (e.g. YAML) but they generally suck and just add confusion. This syntax is quite clear (at least with respect to indentation; not sure about the trailing newline - where does the string end exactly?).

Re: Zig's Lovely Syntax

#65

const x: i32 = 92; D has less syntax: const int x = 92; Just for fun, read each declaration out loud.

"less syntax" isn't necessarily better. The goal isn't to have as few characters as possible.

I agree. I'm not a fan of minimized syntax (see Haskell). But I am a fan of easy to read syntax!

Re: Zig's Lovely Syntax

#66
post #28

I like Zig as well, but I won't call its syntax lovely. Go shows you can do pretty well without ; for line breaks, without : for variable types etc. But sure, if you only compare it with Rust, it is a big improvement.

Removing stuff doesn't necessarily make the syntax better, otherwise we'd all use Lisp and the space bar wouldn't exist: https://en.wikipedia.org/wiki/Scriptio_continua

Re: Zig's Lovely Syntax

#67

const x: i32 = 92; D has less syntax: const int x = 92; Just for fun, read each declaration out loud.

"less syntax" isn't necessarily better. The goal isn't to have as few characters as possible.

True, it is subjective. I prefer C, Go, PHP, ... and OCaml, Erlang, Elixir, Perl, and sometimes Ada and Common Lisp.

I like the syntaxes of each, although Ada is too verbose to me, and with Factor and Common Lisp I have a skill issue.

Re: Zig's Lovely Syntax

#68
> As Zig has only line-comments, this means that \n is always whitespace.

Do I read this correctly that it replaces `\n` at the end of the line with a whitespace? CJK users probably won't be happy with the additional whitespaces.

Re: Zig's Lovely Syntax

#69
post #54

> Raw or multiline strings are spelled like this: const still_raw = \\const raw = \\ \\Roses are red \\ \\ Violets are blue, \\ \\Sugar is sweet \\ \\ And so are you. \\ \\ \\; \\ ; This syntax seems fairly insane to me.

Maybe if you've never tried formatting a traditional multiline string (e.g. in Python, C++ or Rust) before. If it isn't obvious, the problem is that you can't indent them properly because the indentation becomes part of the string itself. Some languages have magical "removed the indent" modes for strings (e.g. YAML) but they generally suck and just add confusion. This syntax is quite clear (at least with respect to i…

Even if we ignore solutions other languages have come up with, it's even worse that they landed on // for the syntax given that it's apparently used the same way for real comments.

Re: Zig's Lovely Syntax

#70
post #68

> As Zig has only line-comments, this means that \n is always whitespace. Do I read this correctly that it replaces `\n` at the end of the line with a whitespace? CJK users probably won't be happy with the additional whitespaces.

that's not correct.
Post reply on HN