[HN Gopher] Zig's dot star syntax (value.*)
       ___________________________________________________________________
        
       Zig's dot star syntax (value.*)
        
       Author : todsacerdoti
       Score  : 18 points
       Date   : 2025-03-07 11:25 UTC (1 days ago)
        
 (HTM) web link (www.openmymind.net)
 (TXT) w3m dump (www.openmymind.net)
        
       | copx wrote:
       | Tl;dr: It is just pointer dereferencing.
       | 
       | I.e. C's                 *ptr
       | 
       | is                 ptr.*
       | 
       | in Zig.
        
         | cardanome wrote:
         | Yeah, I kept on reading to find out if there is some Zig-
         | specific twist but it is literally just that.
         | 
         | Are there really that many Zig programmers that have never seen
         | C or know what pointers are?
        
           | spacedcowboy wrote:
           | And why change something like that? The world would be a
           | better place, IMHO, if there were less different ways to
           | write something from language to language.
           | 
           | Sometimes it seems like the change is just to make it
           | different, not better.
        
             | IshKebab wrote:
             | Same reason Rust uses foo.await instead of await foo. It's
             | clearly superior syntax.
             | 
             | The whole point of Zig is to fix C's mistakes. I don't know
             | why they'd repeat this one.
        
               | moomin wrote:
               | I've gotta say, when I first learned Rust had gone its
               | own way on await, I was heavily sceptical. But seeing the
               | actual examples was pretty compelling.
        
               | dcsommer wrote:
               | I think Rust could use some syntax improvements for
               | pointer manipulation. It has suffix .await, so maybe the
               | community is ready for suffix .* for dereference now too.
               | Visually scanning left and right, along with the extra
               | parentheses, makes pointer-based code in Rust worse than
               | C++ almost. A fully left-to-right syntax would be
               | amazing. EDIT: found https://github.com/rust-
               | lang/rust/issues/10011 and https://github.com/rust-
               | lang/rfcs/pull/3577
        
           | latch wrote:
           | Author here. I agree this is a less-than captivating piece. I
           | write a lot about Zig and wanted something I could reference
           | from other pieces.
           | 
           | But, to answer your question directly: absolutely. In
           | addition to writing a lot about it, I maintain some popular
           | libraries and lurk in various communities. Let me assure you,
           | beginner memory-related questions come up _all the time_. I'd
           | break them down into three groups:
           | 
           | 1 - Young developers who might have a bit of experience in
           | JavaScript or python. Not sure how they're finding their way
           | to Zig. Maybe from HN, maybe to do game development. I think
           | some come to Zig specifically to learn this kind of stuff
           | (I've always believed most programmers should know C.
           | Learning Zig gets you the same fundamentals, and has a lot of
           | QoL stuff).
           | 
           | 2 - Hobbyist. Often python developers, often doing embedded
           | stuff. Might be looking to write extensions in Zig (versus
           | having to do it in C).
           | 
           | 3 - Old programmers who have been using higher level
           | languages for _decades_ and need a refresher. Hey, that's me!
        
         | amjoshuamichael wrote:
         | Yeah I found this article super weird. Explaining pointers &
         | dereferencing is reasonable, but doing it in the context of Zig
         | specifically, like Zig is the first language to feature
         | dereferencing, is odd. Especially since pointers are such a
         | fundamental part of low-level (really, any) programming. Also
         | not sure why it's posted here?
         | 
         | Edit: Going through this author's website, it seems like a lot
         | of their posts are about rediscovering low-level programming
         | concepts through Zig. Like this article, where they discover
         | you can't compare strings directly, and you have to use memcmp:
         | 
         | https://www.openmymind.net/Switching-On-Strings-In-Zig/
         | 
         | They claim that they blog because they "find that [they] retain
         | things better when I write about them." No problem with that.
         | Just a little odd to see on the hn front page, I suppose.
        
       | markisus wrote:
       | Article says it's about stack addresses but I think it should
       | apply more generally to dynamically allocated memory as well.
        
       | loxodrome wrote:
       | Nice explanation of zig's dereferencing operator. Thanks!
        
       ___________________________________________________________________
       (page generated 2025-03-08 23:00 UTC)