Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++11: Improve exception safety with smart pointers #1191

Closed
elfring opened this issue Jul 28, 2018 · 8 comments
Closed

C++11: Improve exception safety with smart pointers #1191

elfring opened this issue Jul 28, 2018 · 8 comments
Assignees
Labels
TransByAI Translated by AI/GPT. Won't fix We won't fix it.
Milestone

Comments

@elfring
Copy link

elfring commented Jul 28, 2018

Would you like to wrap any pointer data members with the class template “std::unique_ptr”?

TRANS_BY_GPT3

@winlinvip
Copy link
Member

We use C++98.

@elfring
Copy link
Author

elfring commented Aug 5, 2018

  • How do you think about to improve implementation details also by other software design approaches then besides the usage of smart pointers?
  • Will any more pointers be set in member initializer lists?

@winlinvip
Copy link
Member

winlinvip commented Aug 9, 2018

I think it's more important to keep it simple, so it's not worth to introduce smart pointer, and SrsAutoFree works well right now. SrsAutoFree is a simple, stupid pointer manager, it simply free object in this scope. In fact, SrsAutoFree really works well in SRS.

@elfring
Copy link
Author

elfring commented Aug 9, 2018

The software could become safer and more efficient if a recent C++ version would be applied, couldn't it?

@winlinvip
Copy link
Member

I think the basic OOAP features are ok to use, like inherit, consturctor, destructor, virtual function, STL. I know and I used template and multiple inheritance in past years, these new features confused many people, and I think it's more simple and easy to understand when we only use basic OOAP features.

So, I insist to use C++98 and no C++11 or advanced OOAP features.

@elfring
Copy link
Author

elfring commented Aug 10, 2018

I find your change resistance questionable in this case.
🔮 I hope that further evolution will be supported also for this software together with recent C++ versions.

@winlinvip winlinvip changed the title Improve exception safety with smart pointers C++11: Improve exception safety with smart pointers Sep 11, 2021
@winlinvip
Copy link
Member

winlinvip commented Sep 11, 2021

After 2 years, looking at this issue again, SRS now also supports the C++11 compilation options. Has your opinion on this changed?

No, I still firmly believe that if we can use C++98, we should definitely not use C++11. The more complex language features we use, the smaller the target audience of developers becomes. Even the senior brother finds C++98 too complicated, let alone C++11. I hope all C programmers can easily modify the code of SRS.

In fact, SRS only used a portion of the functionality of C++98.

  1. Constructors and destructors, in C, are released using goto, which is equivalent to language-level support, making it very convenient and significantly reducing problems.
  2. Basic inheritance, which is not available in C, is also easy to understand. Although SRS uses multiple inheritance, they are all pure virtual classes, which means it does not count as multiple inheritance.
  3. A template of several dozen lines, similar to C++11's smart pointers, SrsAutoFree can be used to release objects in most scenarios. Actually, this is really easy to understand, as it is the implementation of destructors.

Why should SRS 4.0 support C++11 compilation options? The main reason is to support RTC. Some WebRTC algorithms that need to be ported are written in C++11 or even C++14. It would be unnecessary to rewrite the WebRTC algorithms, right?

In addition, I found it inconvenient to have to inherit an interface every time for coroutine functions. If we want to start coroutines more conveniently, using C++11 lambdas might be a better option. However, the benefits of this need to be evaluated, as it would only be introduced if it is clearly convenient.

From my own technical background, those familiar with C would think that SRS should be degraded to C, while experienced C++ programmers would use 98. The new generation of C++ programmers who are accustomed to 11 would consider it necessary. In reality, programming languages have always been a matter of faith, as belief comes with a cost.

The philosophy of SRS is practicality, because practicality leads to simplicity. Don't bother with useless things, just use whatever is simple and easy to use. Simplicity and practicality should not be biased by beliefs. Let the code speak and prove how it can be done better, whether it is truly good or not, everyone can see it.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Sep 11, 2021
@winlinvip winlinvip added the Won't fix We won't fix it. label Sep 11, 2021
@winlinvip winlinvip added this to the 3.0 milestone Sep 11, 2021
@suzp1984
Copy link
Contributor

suzp1984 commented Apr 10, 2023

Just thought of this issue and found out that there is already an issue for it. Personally, I think modern C++ starts from C++11 (generally speaking, C++11 should include C++14, I forgot where I read it, C++14 is just a supplement to C++11), which can be considered as a redefinition of C++. SRS should keep up with the trend, of course, this is just my opinion as a C++ beginner, developers may consider more about product promotion and the prosperity of the open-source community. I completely understand and agree with the author's viewpoint, but personally, I hope SRS can move towards Modern C++.

TRANS_BY_GPT3

@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT. Won't fix We won't fix it.
Projects
None yet
Development

No branches or pull requests

3 participants