Live data from Hacker News

Zig's Lovely Syntax

matklad.github.io

121–130 of 246 posts

Re: Zig's Lovely Syntax

#121
post #69

Earlier quoted context omitted.

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.

But those are two different slashes? \\ for strings and // for comments?

Re: Zig's Lovely Syntax

#122
post #108
post #88

Earlier quoted context omitted.

> There's no need to design the syntax for grep because Kotlin is intended to be used with a good IDE that can answer this query instantly and precisely. On large projects its still cheaper and faster to grep from the CLI than to use Intellij IDE search. Esp if you wish to restrict search to subsets of dirs. Command-line greppability is a serious use case. Zig is also 5-10x faster to compile than Kotlin. On function…

> On large projects its still cheaper and faster to grep from the CLI than to use Intellij IDE search. Esp if you wish to restrict search to subsets of dirs. You must never have used Intellij to say that... it hurts me to hear this. If I catch a developer "grepping" for some type in the CLI, I will sit down with them for a few hours explaining how to use an IDE and how grep is just dumb text search without any of the…

Umm..I _am_ talking about the free text search. Miles superior is NOT miles faster when you want speed. You need not change tabs, fiddle laboriously with the finicky scope drop-down and create custom scopes. Instead you execute an ripgrep command with filter directories (or load alias/from history), pipe to neovim and get auto-preview of results, including surrounding preview code. You don't have to load a huge project and wait for looong code-indexing.

if you can't see how this is miles superior to IDE grep (esp when exploring a number of large projects), then there's no use arguing as you've made up your mind you just love being in the IDE for no actual rational reason.

Re: Zig's Lovely Syntax

#123
post #90

Earlier quoted context omitted.

Walter is showing the equivalent function declaration... you will eventually create a generic type as you say, but in the Zig example, that was a function, not a struct.

If my understanding of D's template syntax is correct, then Walter is showing a the declaration of a function called ArrayListType which is generic over T and returns a T. The original Zig code returns the struct type itself, so it is functionally equivalent to my example, provided I understood how D templates work.

The Zig code returns any `type`, it's impossible to say what that is without looking at the implementation. It can be different types completely depending on the comptime arguments.

But I agree it probably returns a struct type.

Assuming that's the case, you're right and the equivalent would be:

Zig:

    fn ArrayListType(comptime T: type) type {
D:

    ArrayList!T ArrayListType(T)() {
But now the D version is more specific about what it returns, so it's still not exactly equivalent.

Re: Zig's Lovely Syntax

#124
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…

I may be missing something but come Go has a simple:

    `A
       simple
          formatted
             string
    `

?

Re: Zig's Lovely Syntax

#125
post #108

Earlier quoted context omitted.

> On large projects its still cheaper and faster to grep from the CLI than to use Intellij IDE search. Esp if you wish to restrict search to subsets of dirs. You must never have used Intellij to say that... it hurts me to hear this. If I catch a developer "grepping" for some type in the CLI, I will sit down with them for a few hours explaining how to use an IDE and how grep is just dumb text search without any of the…

Umm..I _am_ talking about the free text search. Miles superior is NOT miles faster when you want speed. You need not change tabs, fiddle laboriously with the finicky scope drop-down and create custom scopes. Instead you execute an ripgrep command with filter directories (or load alias/from history), pipe to neovim and get auto-preview of results, including surrounding preview code. You don't have to load a huge proje…

> Instead you execute an ripgrep command with filter directories (or load alias/from history), pipe to neovim

Talk about moving the goal posts.

Re: Zig's Lovely Syntax

#126
post #42
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.

> fancy function types If the syntax were straightforward, plain old function types wouldn't be ‘fancy’ :)

Ambiguous parse. I don't mean that all function types are fancy, I mean that some are fancy (when you have a function pointers in the arguments or return value, or several layers of indirection), and that those which are fancy are helped by typedefs.

Re: Zig's Lovely Syntax

#127
post #125

Earlier quoted context omitted.

Umm..I _am_ talking about the free text search. Miles superior is NOT miles faster when you want speed. You need not change tabs, fiddle laboriously with the finicky scope drop-down and create custom scopes. Instead you execute an ripgrep command with filter directories (or load alias/from history), pipe to neovim and get auto-preview of results, including surrounding preview code. You don't have to load a huge proje…

> Instead you execute an ripgrep command with filter directories (or load alias/from history), pipe to neovim Talk about moving the goal posts.

> Talk about moving the goal posts.

Hey, you are the one who moved the goal posts fist by bringing up use-cases like surrounding preview. You can use ripgrep -> fzf -> bat in one single command if you want to stick to the CLI for fast search previews. But I personally like neovim's comfort better and it is extremely fast to load compared to Intellij. (Not to mention, you can keep feeding the quickfix list more search results from other places)

Re: Zig's Lovely Syntax

#128
post #89
post #79

Earlier quoted context omitted.

> it's even worse that they landed on // for the syntax .. it is using \\

I worked with browsers since before most people knew what a browser was and it will never cease to amaze me how often people confuse slash and backslash, / and \ It’s some sort of mental glitch that a number of people fall into and I have absolutely no idea why.

I wonder if it's dyslexia-adjacent. Dyslexic people famously have particular difficulty distinguishing rotated and reflected letterforms.

Re: Zig's Lovely Syntax

#129
post #56

Weird the author finds it lovely and compares to Kotlin, but doesn't find Kotlin superior. Kotlin invested heavily in a really nice curly brace syntax. It is actually the nicest out there. In every point the author makes, it feels like Kotlin did it the same or better. For example: 1. Integer literals. "var a = 1" doesn't work, seems absurd. In Kotlin literals do have strong types, but coercion is allowed when defini…

It is not just syntax that matters. For one I dislike JVM-based languages. I still write it sometimes for work.

There is also Kotlin/Native, but yes, I am only talking about syntax here.

Re: Zig's Lovely Syntax

#130
post #14
post #7

Earlier quoted context omitted.

I am an exception then. Rust may be my favourite language but the syntax is pretty awful and one of its biggest weaknesses. I also love Ruby but I am pretty meh about its syntax.

I don't think many people would start to use a language unless the found the syntax at least a little simpatico - but I guess they could be drawn by the semantics it provides.

I mostly chose languages due to semantics.
Post reply on HN