ES.25 -- Is it truly beneficial to always employ const for objects?
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- cpp
調査の方向性
まず、この issue の議論と、参照されている CppCoreGuidelines issue 19 を読むことから始めてください。レポートには、ファイル、テスト、エントリーポイントの名前がありません。この作業ではまず、const ローカル変数に関するガイダンスを変更すべきかどうかを決定し、その後、合意した結果を文書化する必要があります。
索引モデルが issue の本文から書いたものです。
説明
"Yes, certainly!". This was my initial reaction upon encountering the recommendation. However, as I delved deeper into C++ development, engaged in code reviews, and studied existing programs in the language, I started to question whether this recommendation is universally beneficial. Seeking insights from seasoned C++ developers, I discovered that the use of const for local variables is subjective, driven by personal preferences, individual tastes, and even ideological beliefs, rather than being an unequivocally superior practice (in their opinion). Here are a few tips based on these discussions:
constcreates a lot of "visual noise" in the code. For example,const int* const pointer = &variable;. This is harder to read thanint * pointer = &variable;. But maybe it makes sense to sacrifice readability for something more significant?- "
constallows you to monitor in the code which variables are changing and which are not." This is justified in large chunks of code (which it is recommended to avoid), where it is problematic to keep track of everything. But is it really worth inflating the amount of code and sacrificing readability in small methods, where it is easy to keep track of the local variables constancy? constwon't help optimize the code. Modern compilers themselves are able to do static analysis and optimize constants.
Being a lead programmer, in my team I allowed to write const for local variables at will and no longer pay attention to it in code reviews. The colleagues with whom I discussed this issue have the same opinion. Writing const for local variables is a programmer's personal matter.
What's your opinion?
IMHO: In a language, it is better to have a mutable modifier rather than const. Then this problem did not exist at all. But c++ cannot afford such an approach.
P.S. Something similar was discussed in https://github.com/isocpp/CppCoreGuidelines/issues/19.
- 主要言語
- CSS
- スター
- 45.3k
- フォーク
- 5.6k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
isocpp/CppCoreGuidelines のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 75/100
isocpp/CppCoreGuidelines#2338 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
isocpp/CppCoreGuidelines#2205 · コメント 8 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 64/100
isocpp/CppCoreGuidelines#1649 · コメント 3 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 42/100
isocpp/CppCoreGuidelines#2336 · コメント 4 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
isocpp/CppCoreGuidelines#2335 · コメント 2 件 ·
isocpp/CppCoreGuidelines の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
letsencrypt/cp-cps#353 ·
-
Link Checker Reportオープンautomated issue report
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
[Docs] - Document minimum Terraform/OpenTofu version (>= 1.11) required by write-only argumentsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
MagaluCloud/terraform-provider-mgc#323 ·
メンテナーはふだん 11 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信