You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regarding "Forward Declare When Possible", I think you should (almost) never forward declare for the following reasons:
It makes backward compatible refactorings more complicated and prone to breakage. This is the reason that the the C++ Standard Library and abseil forbid forward declarations. In C++ you can often refactor a function into a lambda or function object or into a template and keep backward compatibility with uses of the function. However, the signature will have changed.
It is dangerous. Forward declarations are an easy way to get hard to diagnose errors like ODR violations. In addition, if something changed in a header you were depending on, forward declarations postpone the error to link-time or to compile time.
It is a short term optimization. Hopefully modules in C++ will come soon and make this better. But even without modules, such techniques as pre-compiled headers are safer and work in more scenarios.
Based on these, I think better advice would be to avoid forward declarations.
The text was updated successfully, but these errors were encountered:
I think these are great points. I'm not as learned as some of you, but I subjectively respond negatively to forward declarations in code. I feels like dirty code that is masking circular references or something. Perhaps a little more substantially, the other c++ guide I like is Google's publication and they also suggest that forward declarations are to be avoided.
Regarding "Forward Declare When Possible", I think you should (almost) never forward declare for the following reasons:
It makes backward compatible refactorings more complicated and prone to breakage. This is the reason that the the C++ Standard Library and abseil forbid forward declarations. In C++ you can often refactor a function into a lambda or function object or into a template and keep backward compatibility with uses of the function. However, the signature will have changed.
It is dangerous. Forward declarations are an easy way to get hard to diagnose errors like ODR violations. In addition, if something changed in a header you were depending on, forward declarations postpone the error to link-time or to compile time.
It is a short term optimization. Hopefully modules in C++ will come soon and make this better. But even without modules, such techniques as pre-compiled headers are safer and work in more scenarios.
Based on these, I think better advice would be to avoid forward declarations.
The text was updated successfully, but these errors were encountered: