This is old-fashioned (uses C89 instead of C99) and some of its "idioms" are questionable, like this one: list *p; list l = (list) malloc(sizeof(struct list)); l -> val = val; for(p = &the_list; *p && (*p) -> val next)) ; l -> next = *p; *p = l; Here p is a doubly indirect pointer and I would personally think this is an unwarranted cleverness. Furthermore this is the year 2019. Why would you still manually traverse a…
You're comparing an implementation to an interface. Do you really think that's valid?
Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
11–20 of 35 posts
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#12This is old-fashioned (uses C89 instead of C99) and some of its "idioms" are questionable, like this one: list *p; list l = (list) malloc(sizeof(struct list)); l -> val = val; for(p = &the_list; *p && (*p) -> val next)) ; l -> next = *p; *p = l; Here p is a doubly indirect pointer and I would personally think this is an unwarranted cleverness. Furthermore this is the year 2019. Why would you still manually traverse a…
FWIW personally i prefer the C code. It is explicit at what it does, whereas the C++ one is harder to follow exactly what it does - and also very ugly (i never liked C++'s iterators). The double indirect pointer is hairy but at least everything you need to know to "parse" the code is right there.
And, for most of us, if you want to just write it and have it work, the C++ code is better. Sure, I might have to find an example of the iterator code in order to get the syntax right, but it's a lot easier to mess up the double indirect pointer code. Worse, when I mess up the iterator code, it likely doesn't compile. If I mess up the double indirect pointer code, it it likely to silently corrupt memory somewhere.
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#13This is old-fashioned (uses C89 instead of C99) and some of its "idioms" are questionable, like this one: list *p; list l = (list) malloc(sizeof(struct list)); l -> val = val; for(p = &the_list; *p && (*p) -> val next)) ; l -> next = *p; *p = l; Here p is a doubly indirect pointer and I would personally think this is an unwarranted cleverness. Furthermore this is the year 2019. Why would you still manually traverse a…
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#14Earlier quoted context omitted.
You're comparing an implementation to an interface. Do you really think that's valid?
Generic collections in C implemented with macros are so heinous, I think this comparison may actually be fairer to C. I say that as an abuser of C macros, and someone who genuinely likes C.
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#15This is old-fashioned (uses C89 instead of C99) and some of its "idioms" are questionable, like this one: list *p; list l = (list) malloc(sizeof(struct list)); l -> val = val; for(p = &the_list; *p && (*p) -> val next)) ; l -> next = *p; *p = l; Here p is a doubly indirect pointer and I would personally think this is an unwarranted cleverness. Furthermore this is the year 2019. Why would you still manually traverse a…
FWIW personally i prefer the C code. It is explicit at what it does, whereas the C++ one is harder to follow exactly what it does - and also very ugly (i never liked C++'s iterators). The double indirect pointer is hairy but at least everything you need to know to "parse" the code is right there.
but why do you want to spend time parsing code that
- does textbook-level things ?
- has a thousand different places where a typo can end up
- needs to be rewritten for every kind of list
those are the red flags. Do you also go read your graphics driver's code when you push pixels to the screen ?
> and also very ugly (i never liked C++'s iterators).
ignoring the jump from what you like to a global assertion (the C version makes my eyes bleed), in C++ 20 you can also just do
list.insert(std::lower_bound(list, val), val);Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#16Earlier quoted context omitted.
Generic collections in C implemented with macros are so heinous, I think this comparison may actually be fairer to C. I say that as an abuser of C macros, and someone who genuinely likes C.
Not a huge fan of those kind of macros myself, because they still leave too much of the implementation exposed. The other alternative is pointer-arithmetic implementations, which do hide the implementation better but often come with limitations (e.g. list members have to be first and you can't be on two lists at once). But either way, that's C for you. The language has its limitations, and there's only so much you ca…
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#17[1] https://github.com/immunant/c2rust
[2] https://c2rust.com/manual/quickstart.html
[3] https://c2rust.com/manual/c2rust-refactor/index.html
[4] https://c2rust.com/manual/c2rust-refactor/doc/scripting_api....
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#18This is old-fashioned (uses C89 instead of C99) and some of its "idioms" are questionable, like this one: list *p; list l = (list) malloc(sizeof(struct list)); l -> val = val; for(p = &the_list; *p && (*p) -> val next)) ; l -> next = *p; *p = l; Here p is a doubly indirect pointer and I would personally think this is an unwarranted cleverness. Furthermore this is the year 2019. Why would you still manually traverse a…
You're comparing an implementation to an interface. Do you really think that's valid?
Re: Modular C: Reusable and Maintainable Code Using the C Language (1994) [pdf]
#19At this point it's better just to convert the code into the proper modern programming language without all C drawbacks - Rust. Amazing c2rust[1] tool offers automated conversion[2] and refactoring[3] capabilities. It even allows you to script[4] the refactoring with Lua. All while preserving ability to run and (probably) pass the tests. [1] https://github.com/immunant/c2rust [2] https://c2rust.com/manual/quickstart.h…
I understand wanting to advocate for your favorite programming language but this kind of elitist attitude doesn't do the cause any favors, it's more likely to turn people away than anything.
Rust is not "the proper programming language". It's just one of many excellent choices.