Skip to content

Conversation

@ShenMian
Copy link
Contributor

Summary

None

Purpose of change

Parameters passed by value do not need the const modifier, which simplifies the code and maintains a more consistent coding style.

Describe the solution

Describe alternatives you've considered

Testing

Additional context

@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership Info / User Interface Game - player communication, menus, etc. Translation I18n Missions Quests and missions Bionics CBM (Compact Bionic Modules) Map / Mapgen Overmap, Mapgen, Map extras, Map display Vehicles Vehicles, parts, mechanics & interactions Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves Scenarios New Scenarios, balancing, bugs with scenarios Character / World Generation Issues and enhancements concerning stages of creating a character or a world Player Faction Base / Camp All about the player faction base/camp/site Mechanics: Weather Rain, snow, portal storms and non-temperature environment Game: Achievements / Conducts / Scores Player goals and how they are tracked. Mechanics: Enchantments / Spells Enchantments and spells Martial Arts Arts, Techniques, weapons and anything touching martial arts. Limbs Limbs, mutable limbs, and code related to them. EOC: Effects On Condition Anything concerning Effects On Condition labels Apr 19, 2025
@github-actions github-actions bot requested review from KorGgenT and dseguin April 19, 2025 20:50
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @wapcaplet @andrei8l

@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 19, 2025
@GuardianDll GuardianDll merged commit 9ce770a into CleverRaven:master Apr 21, 2025
31 checks passed
@ShenMian ShenMian deleted the refactor/const-1 branch April 21, 2025 14:18
@akrieger
Copy link
Member

I wouldn't call them unnecessary. Although it's not strictly enforced there is a mild preference to use const for local variables which are logically not meant to be mutated. That includes value args like a bare string_view. This isn't really an improvement imo

@ShenMian
Copy link
Contributor Author

ShenMian commented Apr 21, 2025

@akrieger I agree with part of what you said. According to Cpp Core Guidelines, local variables should be declared with const, but function parameters might be an exception.

To maintain consistency in the code style, most of the parameters passed by value in this project are not declared with const. This is to ensure uniformity and simplify the code.

std::string_view inherently contains an immutable reference to a string and is itself a simple pass-by-value parameter, so it should not be treated as an exception.

@akrieger
Copy link
Member

akrieger commented Apr 21, 2025

I'm aware that string_view does not allow mutating the viewed range but it is reassignable to view a different range. const std::string_view is like const char* const whereas std::string_view is const char*.

We don't explicitly follow any external style guides nor do we automatically consider their suggestions as meaningful to consider just because of the source. We have project local conventions we follow and consider each on a case by case basis.

@ShenMian
Copy link
Contributor Author

This PR was simply made to maintain consistency with the code style of other parts of the same project. The Cpp Core Guidelines are just an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions Bionics CBM (Compact Bionic Modules) [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world Crafting / Construction / Recipes Includes: Uncrafting / Disassembling EOC: Effects On Condition Anything concerning Effects On Condition Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. Game: Achievements / Conducts / Scores Player goals and how they are tracked. Info / User Interface Game - player communication, menus, etc. Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves json-styled JSON lint passed, label assigned by github actions Limbs Limbs, mutable limbs, and code related to them. Map / Mapgen Overmap, Mapgen, Map extras, Map display Martial Arts Arts, Techniques, weapons and anything touching martial arts. Mechanics: Enchantments / Spells Enchantments and spells Mechanics: Weather Rain, snow, portal storms and non-temperature environment Missions Quests and missions Monsters Monsters both friendly and unfriendly. Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site Scenarios New Scenarios, balancing, bugs with scenarios Translation I18n Vehicles Vehicles, parts, mechanics & interactions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants