6 ms·
It could hardly be more C-like. Are you getting distracted by the syntax?
by balfirevic 7y ago
It could hardly be more C-like. Are you getting distracted by the syntax?
- kelnos 7y agoWhen we talk about something being "C-like", the syntax is what we're talking about. Being "distracted by the syntax" doesn't make sense when the syntax is the entire point of the statement being made.
- balfirevic 7y agoWhen "we" talk? I suggest that in the future if you mean syntactically similar you say syntactically similar. But then, of course, it wouldn't have much to do with Zig's "appeal as better C than C", which prompted this whole discussion.
- dnautics 7y agoAdmittedly it's been decades since I've done any C (literally since 1999, except for an LD_PRELOAD shim I wrote about 5 years ago) but being someone who prefers C and other ALGOL-syntax derivates I find the syntax to be relatively easy to grok. One advantage over C is that the confusing pointer/array/function pointer thing has a well-defined order in Zig, there's no "spiral order" nonsense going on.
- naniwaduni 7y agoThere is no spiral. C's pointer declaration syntax is arguably backwards ("declaration follows usage") but fundamentally follows normal precedence rules. The so-called spiral is total nonsense misinformation.
- saagarjha 7y agoWhat about this do you find disagreeable? http://c-faq.com/decl/spiral.anderson.html http://c-faq.com/decl/spiral.anderson.html
- dnautics 7y agoThe fact that it's wrong if you try to generalize it beyond the examples given?
- saagarjha 7y agoDoes it? Here's one that I grabbed from cdecl.org: char * const (*(* const bar)[5])(int ) And its translation: declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char This seems like what I'd get from the spiral technique.
- palotasb 7y agoThe spiral rule works if "pointer to" and "function returning"/"array of" alternate but it breaks if they don't, i.e., if you have arrays of arrays or pointers to pointers. int** arr1_of_arr2_of_arr3_of_ptr_to_ptr_to_int[1][2][3] In this case, spiraling between [1], ×, [2], ×, [3], int is obviously wrong, the correct reading order is [1], [2], [3], ×, ×, int. (Edit: read × = *) The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html
- diegoperini 7y agoI would name that algorithm "inside-out" instead of "right-left" if my understanding of its behavior is correct.
- saagarjha 7y agoAren't you supposed to treat multiple array or pointers as a group?
- dnautics 7y agoThat's exactly my point. It's confusing enough that someone e made a bullshit claim that was totally wrong and confused noobs for years. That won't happen with zig.
- pjmlp 7y agoThat won't happen with any sane systems language all the way back to Algol dialects. The only thing that C has taken from Algol, was structured control and data.
- ant6n 7y agoThey are both close-to-the-metal, few-abstractions, procedural, imperative Systems programming languages with explicit memory management and layout.
- agapon 7y agoExactly. I would appreciate an explanation what makes zig c-like if its syntax is nothing like c? What does "c-like" even mean then?