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

General refactors. #4

Open
3 of 20 tasks
HexDecimal opened this issue Oct 29, 2022 · 0 comments
Open
3 of 20 tasks

General refactors. #4

HexDecimal opened this issue Oct 29, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@HexDecimal
Copy link
Contributor

HexDecimal commented Oct 29, 2022

Making a list of various changes to make this code more up-to-date. Most of these are easy on their own. It will just take time to do them all. I've already finished most of these kinds of changes to Umbra.

  • TCODList should be replaced with std::vector in all cases.
  • Remove new/delete from libtcod types. These can be treated as values without major issues. Any exceptions can use smart pointers instead of new.
  • Pointer types should express ownership, ideally with std::unique_ptr, but also std::shared_ptr if necessary. Non-owning pointers would still be raw of course.
  • Class attributes should be initialized. Just put {}; at the end of simple types rather than = nullptr; or = 0;. Any defaults should be moved from the class constructor code to the class itself.
  • Pointers to strings should be replaced with std::string in many cases. Mostly in non-contexpr cases such as class attributes or local variables. In some cases null strings should be replaced with empty strings. Always replace strdup.
  • #define X Y constants should generally be replaced with static constexpr auto X{Y};/static constexpr auto X = Y; constants.
  • #define macros should all be replaced with constexpr functions.
  • Low level calls such as memcpy and strcmp should generally be replaced with high level operations.
  • C-style arrays like int foo[2] should be replaced with std::array<int, 2> foo{}, etc.
  • File operations should use C++17 <filesystem>.
  • For-loops over containers should prefer ranged-based loops. for (auto& x : y);
  • Many class methods are missing const, noexecpt, and [[nodiscard]] qualifiers.
  • Empty constructors and destructors should use = default;, they should not have an empty function in the source.
  • Small functions with few or no dependencies should be moved inline.
  • Functions which take pointers, but don't handle nullptr, should be changed to take references.
  • Macros such as MIN or CLAMP should be replaced by their C++ functions.
  • Virtual class overrides are missing the override qualifier.
  • String formatting functions should use fmt.
  • Temporary local variables which don't change should be qualified with const.
  • Unions should be replaced with std::variant.

In general follow the C++ Core Guidelines.

@HexDecimal HexDecimal self-assigned this Oct 29, 2022
@HexDecimal HexDecimal added the enhancement New feature or request label Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant