refactor cvector_at#75
Conversation
|
Hmm, interesting usage of assert and comma operator there. I'll take a closer look in a little while |
1. `cvector_at` return element itself intead its address 2. `cvector_front` and `cvector_back` will no longer NULL
|
Can you explain what you believe was broken about: vs what you changed it to: Given that the |
|
Also, it appears that your PR requires adding an |
The compiler gives me warning. |
|
Thanks! |
|
This has been merged, but I propose that this change be reverted. Previously, With the current API, we have to do this, which gives the library user fewer options and IMO is more awkward: With this Before this change, if you wanted to get the value of some index in the vector you could just use the Also, I believe this broke/changed Thanks for the great library! I'd be happy to submit a PR reverting this. |
|
Hmm, I don't think there are any difference between
and
In my opinion, writing out of bounds of an array is an unrecoverable error that should cause the program to crash immediately, alerting the programmer to a fatal issue instead of throwing an exception (especially it's error code). But if you do want to revert it, I don't mind. The only reason I'm using this library is to complete my homework. I rarely write pure C because it lacks abstraction capabilities. For example, using macros to embed code in C (like with cvector) can lead to binary bloat. |
|
Hmm, interesting thoughts on both sides. First and foremost, if front and back are currently broken, we need to fix that! Beyond that, I'll have to think on which version of the API I think is better because you both make a compelling argument. So please, if it's not too much effort, make a PR for the revert so if I decide to revert, it's ready to go. |
|
my opinions are as follow:
|
Sure, I'll see if I have time to get that out in the next few days. |
|
Some counterarguments:
I disagree with this in principle, I think that handling "errors" gracefully is more important in any program of significant size, especially in C where the abort procedures are fairly limited. With
C and C++ are different languages. I personally haven't used C++ in years. Just because a C++ library is designed a certain way should have little bearing on how to design a C library. Exceptions, templates, and RAII are all factors in the decision of how to design a C++ library. Those decisions shouldn't carry over to a C library without good reason.
Maybe, but in the use-case that prompted me to write this, that's not how I was thinking about the problem. An explicit size check asks the question: "Is the vector at least this big?" But calling and checking
I agree, the
Eh, kinda, but I don't really like the idea of referencing the result of a macro like that. |
|
哎,累了,毁灭吧,赶紧的。(这是一个梗 |
|
See #76. |
|
@smlavine I am inclined to agree with your position, thanks for the PR. @GoodenoughPhysicsLab I appreciate both your efforts to improve the library and your understanding that there is no solution that will seem best to everyone. As I said, I agree with @smlavine views, but that isn't to say that you're "wrong", only that his suggestion feels more natural to me. Thanks again to both of you, i'll be merging #76 shortly. |
|
Also, @smlavine small world! I went to RIT as well (a long time ago though...) |
I also appreciate your efforts to this library and your friendly sentence and I actually learned some knowledge from it. You may feel curious to my extreme terminating-style checking. The most important reason I guessed is that I against using C++ exception but it's the core to cpp because I can't return error code in constructor or overload function, which forced me to terminate the program if some errors have been detected. Another reason is that Herb Sutter have given a report in cppcon2019 and he negated std::logic_error because he thought that exception is a recoverable error, which means when the abstract machine is broken, people can't recover it by catching std::logic_error. I agree with Herb Sutter's thinking and expand it to every unrecoverable error like writing out of bounds of an array. But now, I think that terminating the program just awkward users, which is not good. Thanks for the great library! |
|
On Thu Feb 13, 2025 at 1:55 AM EST, Evan Teran wrote:
Also, @smlavine small world! I went to RIT as well (a long time ago though...)
No way! Go Tigers. :)
|

After I closed my issue, I suddenly had an idea.
Now,
cvector_atcan be used as follow: