Ex32: Why use a space before and after * when using the List struct?

This appears to be a stylistic decision, as there doesn’t appear to be a difference between:
void List_destroy(List * list);
and
void List_destroy(List *list);

later they seem mixed together on the line
void List_unshift(List * list, void *value);

I don’t recall seeing this elsewhere in the book, whats the deal?

relevant SO thread -> https://stackoverflow.com/questions/15212126/difference-between-char-var-and-char-var

I have the same issue with autoformatters. I use astyle (a standard tool) from vim-autoformat (a git repo) with the default setting (allman). This implies having the style you indicate here (List * list). Other styles use the concatenated notation (List *list). Semantically there is no difference: it’s just whitespace. I have even spoken to people that insist on appending the asterix to the type like this List* list.

In your mixed example, my suspicion is that Zed enters them in a hurry and just either forgets the extra space, or accidentally enters it.

In my experience, using an autoformatter like astyle resolves this issue. You can tell astyle what style you want to use on a very detailed level or on a global level. All files then come out the same style, whether with an extra space or without.

EDIT: if you are using vim, find vim-autoformat in github. It helps formatting every time you save. If that is what you want. You could also add astyle in a hook to git. then you could make it autoformat before going into commit. I have done this for ctags.

Hope this helps.

Yes, I use a formatter to make all the code wrap at specific lines and follow a consistent style for publishing, but it sometimes doesn’t do things consistently, or I make a change and forget to run it. Honestly, a lot of the formatting problems in this book are because of needs too format for the Kindle if you can believe that. It has a such a terrible format (mobi) that it’s mostly useless for code oriented books that need specific formatting.

Otherwise it’s mostly style choices, but I tend to prefer the asterisk next to the variable even though honestly that’s not the clearest way to write it. Mostly just my old C age at play. For example, if I write this:

List* list = List_create();

Then you can read that as a “List pointer named list” a little more easily since the * is next to the type. But this way:

List *list = List_create();

Kind of reads like “A List with a pointer variable named list.” Just seems off, but since I’ve been coding that way forever that’s how my hands force me to do it.

Then the style that’s like this:

List * list = List_create();

I don’t know, that’s the approved style for GNU I think (or whatever I chose, I forget) but I don’t like this. It reads more like “List multiplied by list.”

Ultimately though, these discussions over something so minor as the placement of a space around a single character are just so entirely pointless. I have no idea why some languages seems to attract weird rules lawyers who fixate on OCD points of style like this, but I am much more an advocate of the way Go and Rust do things: Your code is run through a single formatter program that does all this crap for you so stop debating spaces and just code.