3 ms·
This looks like it's coming from someone who doesn't know C++ well and is just coming up with reasons to fit their bias. The fact that he/she didn't mention any
by halayli 11y ago
This looks like it's coming from someone who doesn't know C++ well and is just coming up with reasons to fit their bias. The fact that he/she didn't mention any disadvantage to the C code written beside verbosity makes it clear.
For one, it's easy to forget to call zlist_destroy. Who owns what in C can get very complicated and you can run into dangling pointers. At least in the C++ version you can manage ownership easier in their case.
I am not defending one language over the other, I use them both and have experienced the advantages and disadvantages of each.
What's being shown in this book is not how typically you create link-lists. man queue(3) to see how it's generally done.
The C++ for-loop is not how you typically iterate over a list , again the author decided to show a bad example to confirm their bias:
for (const auto& i : List)
cout << i << " ";
- unscaled 11y agoMore likely, someone who hasn't programmed C++ in the last 10 years. Forgetting auto, and using the cumbersome 3-part for loop with iterator boilerplate when you only need value shows age. Initializing the list is also easier now, with initializer lists syntax, so you could just do: list<string> lst = { "tomato", "grape", "apple", "orange"}; and cut another 4 lines, making the C++ line count half of C version. Not a negligible difference, as the author claims.