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

refactor: misc style changes #2177

Merged
merged 5 commits into from
Jun 19, 2021
Merged

Conversation

div72
Copy link
Member

@div72 div72 commented Jun 12, 2021

No description provided.

@div72 div72 self-assigned this Jun 12, 2021
@div72 div72 added the refactor This is for refactoring (if also an enhancement, use that label too). label Jun 12, 2021
@barton2526
Copy link
Member

Can this be done as well?
bitcoin/bitcoin#10645

@div72 div72 marked this pull request as draft June 12, 2021 20:43
@div72 div72 force-pushed the misc branch 2 times, most recently from fc86b30 to 4b9785d Compare June 12, 2021 22:14
@div72 div72 marked this pull request as ready for review June 12, 2021 22:18
@jamescowens jamescowens self-requested a review June 13, 2021 00:14
@jamescowens jamescowens added this to the Ingrid milestone Jun 13, 2021
div72 added 3 commits June 13, 2021 13:17
-BEGIN VERIFY SCRIPT-
sed -i -r -e 's/([^a-zA-Z0-9])\(\*(\w+)\)\./\1\2->/g' $(git ls-files -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
git diff -U0 | contrib/devtools/clang-format-diff.py -p1 -i -v
-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
sed -i -r -e 's/BOOST_FOREACH\([ ]?(.*+)[ ]?,[ ]?(.*+)[ ]?\)/for (\1 : \2)/g' $(git grep -l 'BOOST_FOREACH' -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
sed -i -r -e 's/foreach[ ]?\([ ]?(.*+)[ ]?,[ ]?(.*+)[ ]?\)/for (\1 : \2)/g' $(git grep -l 'foreach' -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
sed -i -r -e '/foreach/d' $(git grep -l 'foreach' -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
sed -i -r -e '/define PAIRTYPE/d' $(git grep -l 'PAIRTYPE' -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
sed -i -r -e 's/PAIRTYPE\([ ]?(.*+)[ ]?,[ ]?(.*+)[ ]?\)/std::pair<\1, \2>/g' $(git grep -l 'PAIRTYPE' -- 'src/*.h' 'src/*.cpp' ':!src/leveldb/**' ':!src/univalue/**' ':!src/qt/locale')
git diff -U0 | contrib/devtools/clang-format-diff.py -p1 -i -v
-END VERIFY SCRIPT-
@jamescowens
Copy link
Member

@cyrossignol You ok with merging a style change refactor this broad? To me, now is as good a time as any. It has no conficts at the moment.

@jamescowens jamescowens requested a review from cyrossignol June 13, 2021 18:31
Copy link
Member

@jamescowens jamescowens left a comment

Choose a reason for hiding this comment

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

Good job on this. These are always a PITA. In general for the class parameters after the colon, on the next line and using the standard indent is fine. I have made comments where braces need to go after the ifs or if ... elses and also for's. Note that the code is chock full of the indent single line ifs and if ... elses without braces, so I only commented on ones that were near the changes you already made. I don't think it is necessary to go through the code exhaustively to look for those. Just fix what is near the changes you already made.

Some of this code is merged from upstream (Bitcoin) as you know, and so some of the changes here will likely be lost for that unless they have been fixed in the source.

src/miner.cpp Outdated Show resolved Hide resolved
src/net.cpp Outdated Show resolved Hide resolved
src/primitives/transaction.h Outdated Show resolved Hide resolved
src/qt/addressbookpage.cpp Outdated Show resolved Hide resolved
src/qt/addresstablemodel.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.h Outdated Show resolved Hide resolved
src/wallet/wallet.h Outdated Show resolved Hide resolved
src/wallet/wallet.h Outdated Show resolved Hide resolved
@cyrossignol
Copy link
Member

@jamescowens As you might see, these are scripted changes using automation from upstream. I think I agree with all of your suggestions, but many of those will need to be adjusted by hand, and that seems like it may take much longer than @div72's original patch. In the spirit of this PR, it may be worth looking into whether scripted-diffs exist for the suggestions rather than switching to manual mode. Large-scale cosmetic trivia doesn't really seem worth the time without some kind of automation.

src/test/gridcoin/cpid_tests.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
@jamescowens
Copy link
Member

I agree with you @cyrossignol. That is the trouble with scripted changes. They aren't really intelligent. Most of the changes are actually fine, except the after the colon alignment, which I think makes things worse there. We don't have to straighten up the missing braces for the ifs and elses, although it would be nice to have a script to do that...

@jamescowens
Copy link
Member

I still think this is a worthwhile PR to merge... just to get rid of those antiquated and unsightly (*foo).fum's.

@div72
Copy link
Member Author

div72 commented Jun 16, 2021

Could we write the current preferred style of code somewhere(like docs/coding.txt) and enforce it? Then I can update the .clang-format file which should hopefully format better.

@jamescowens
Copy link
Member

jamescowens commented Jun 16, 2021 via email

@jamescowens
Copy link
Member

jamescowens commented Jun 16, 2021

Also, much of the older Bitcoin code does NOT meet their own (and our) styling standards. In general we have applied a pragmatic approach to cleanup of the older code. Unless the situation is gross, we have left older Bitcoin code undisturbed unless we are already modifying an area for other purposes. This limits PR conflicts.

As you will see in the newer code, we have been trying to adhere to the style guidelines much better.

@div72
Copy link
Member Author

div72 commented Jun 16, 2021

There should be one and only clear way to write something in my opinion. The { should either be on the same line or the next line in all newly written code.

Also, yes there is a style noted in docs/coding.txt but it is outdated and incomplete when compared with thr current gridcoin-specific code. New variables are named snake_case without type prefix where it notes PascalCase with type prefix, members variables are prefixed with m_, but it isn't noted etc.

You shouldn't have to say "This should be written like this...", the lint job should be configured and automatically fail if someone introduces a different style in a PR in my opinion at least.

@jamescowens
Copy link
Member

jamescowens commented Jun 17, 2021

I thought we had pulled over the Bitcoin code style document to replace the older one. Seems we didn't. That is what we are supposed to be following at this point. If you want to do a PR to bring that over, that would be wonderful.

I agree with your sentiment, but in many cases it is not realistic. Many PR's are not independent: instead they modify or extend code that has already been written. In many cases one has to use variables that have already been created, etc. These are often using legacy styles. In particular the legacy Qt side of the wallet is significantly different than the coding style of the core wallet. The core wallet has several styles depending on the era of the code. One has to make a choice, do you start refactoring to cause the older code that you are revising or extending to conform to the new style guide? The answer is sometimes yes, if the extension or modification you are trying to do (not including simply style revision) amounts to a complete overhaul of an area, but most of the time no, as excessive revision of older code for style issues only results in larger PR's involving more source files and is more likely to lead to conflicts with existing work that is underway.

Some of the reasons for the evolution in the C++ styling between the code image that was used when this wallet was amalgamated from Bitcoin/Peercoin/Blackoin and today is the changes in the tools used for coding. Hungarian notation or similar is not as relevant anymore because of the better, context aware development environments with significant parsing/checking capabilities, which render the need to indicate the type of variable in the variable name itself superfluous. The m_ prefix is a good idea to clearly distinguish member variables of a class, especially in a codebaselike ours which has quite a bit of global scope code that is not classed. Missing braces in situations where the combination of a missing brace and misleading indentation can lead to difficult to find bugs is more important than exact where the opening brace is placed IMHO.

I didn't mean to irritate you with this PR. I certainly think it improves things in many areas, and certainly doesn't do any harm. I am ok with merging it as is quite frankly. @cyrossignol?

@div72
Copy link
Member Author

div72 commented Jun 17, 2021

I apologize if I am a bit grumpy, been a bit busy and tired lately.

I kind of understand what you mean and which is why I think human assisted diff formatting is good.

Also sorry for the merge commit had to do it on mobile.

Copy link
Member

@jamescowens jamescowens left a comment

Choose a reason for hiding this comment

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

I think this is an improvement and is fine to merge now. @cyrossignol please do another pass on this too.

@jamescowens jamescowens requested a review from cyrossignol June 18, 2021 21:40
Copy link
Member

@cyrossignol cyrossignol left a comment

Choose a reason for hiding this comment

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

Thanks @div72... quite a PR here...

As an aside, these are the rough guidelines for managing legacy code style that seem standard in most teams that I've worked on:

  • Code in new modules should always follow the style guide
  • When modifying legacy code, be consistent with the style of the surrounding scope
    • Typically, a function boundary, but it could be a small file/class or a large nested block
    • Prefer to avoid mixing cosmetic changes with domain changes (batch-commit formatting as a whole separately)
    • New scopes can follow the style guide to ease expected transitions later
  • Do not modify the style of upstream code
  • Rely on tools for style enforcement rather than manual review
    • Use linters to flag style violations
    • Use formatters to apply style before submission
    • "Policy, not personal"

Of course, we need an up-to-date style guide for any of this to really matter. I think we do a decent job following these points so far (I surely haven't done so absolutely myself). I mention these because formalizing our position should save us time—I'd rather discuss and review style changes as little as possible. No convention or tool set is perfect, though. The goal is to minimize the distraction of code style from the review process—both for new reviews (PRs) and historical (git log/blame, change tracking, etc.)—so I propose these guidelines as a starting point.

@jamescowens
Copy link
Member

I agree @cyrossignol. Merging.

@jamescowens jamescowens merged commit 954ed72 into gridcoin-community:development Jun 19, 2021
jamescowens added a commit to jamescowens/Gridcoin-Research that referenced this pull request Aug 1, 2021
Added
 - util, rpc. gui: Changes for snapshotdownload and add feature sync from zero gridcoin-community#2093 (@iFoggz)
 - gui: Implement GUI version of consolidateunspent (coin control part) gridcoin-community#2111 (@jamescowens)
 - gui: Implement consolidateunspent wizard gridcoin-community#2125 (@jamescowens)
 - qt: Add antialiasing to traffic graph widget gridcoin-community#2150 (@barton2526)
 - util: Port of ArgsManager and a significant subset of src/util gridcoin-community#2146 (@jamescowens)
 - doc: add issue templates for bug reports and feature requests gridcoin-community#2147 (@Pythonix)
 - gui, rpc: Implement dynamic stakesplitting control, settings changes via rpc, and dynamic changes to sidestaking via rpc gridcoin-community#2164 (@jamescowens)
 - rpc: Implement getblocksbatch gridcoin-community#2205 (@jamescowens)
 - voting, rpc, gui: Implement demand loading of historical poll by poll id and AVW calculation gridcoin-community#2210 (@jamescowens)
 - gui: Show GUI error dialog if command line parsing fails gridcoin-community#2218 (@jamescowens)
 - gui: Implement close confirmation. gridcoin-community#2216 (@denravonska)
 - build: Use -fstack-reuse=none gridcoin-community#2232 (@barton2526)

Changed
 - doc: Update build doc gridcoin-community#2078 (@iFoggz)
 - gui: Normalize button and input control appearance gridcoin-community#2096 (@cyrossignol)
 - consensus: Implement GetMinimumRequiredConnectionsForStaking gridcoin-community#2097 (@jamescowens)
 - refactor: move CTransaction to primitives gridcoin-community#2006 (@div72)
 - consensus, refactor, test: Merkle gridcoin-community#2094 (@div72)
 - gui: Update diagnostics gridcoin-community#2095 (@jamescowens)
 - gui: Refresh UI styles and sidebar/statusbar design gridcoin-community#2102 (@cyrossignol)
 - gui: Set standard base Qt style on Windows and macOS gridcoin-community#2114 (@cyrossignol)
 - build, refactor: bump to C++17 gridcoin-community#2113 (@div72)
 - util, rpc, gui: Implement GetMaxInputsForConsolidationTxn() gridcoin-community#2119 (@jamescowens)
 - gui: Refresh overview page design gridcoin-community#2117 (@cyrossignol)
 - depends: change boost mirror gridcoin-community#2122 (@div72)
 - refactor: small cleanup gridcoin-community#2123 (@div72)
 - build: Update depends Qt recipe to version 5.12.10 gridcoin-community#2129 (@cyrossignol)
 - build: Bump Codespell to 2.0.0 gridcoin-community#2135 (@barton2526)
 - gui: Refresh "send coins" page design gridcoin-community#2126 (@cyrossignol)
 - gui: Optimize locks to improve responsiveness gridcoin-community#2137 (@cyrossignol)
 - gui: Refresh "receive payment" page design gridcoin-community#2138 (@cyrossignol)
 - gui: Add empty placeholder to recent transactions list gridcoin-community#2140 (@cyrossignol)
 - gui: Refresh transaction history page design gridcoin-community#2143 (@cyrossignol)
 - gui: Refresh address book page design gridcoin-community#2145 (@cyrossignol)
 - doc: Update http to https where possible gridcoin-community#2148 (@barton2526)
 - depends: Update dependencies gridcoin-community#2153 (@barton2526)
 - depends: Bump python to 3.6 gridcoin-community#2159 (@barton2526)
 - test: Update cppcheck linter to c++17 gridcoin-community#2157 (@barton2526)
 - test: Drop Travis specific workarounds, Mention commit id in error, Fix typos, Update spellcheck ignore words gridcoin-community#2158 (@barton2526)
 - gui: Overhaul the voting UI gridcoin-community#2151 (@cyrossignol)
 - wallet: simplify nTimeSmart calculation gridcoin-community#2144 (@div72)
 - gui: Refresh checkbox and radio button styles gridcoin-community#2170 (@cyrossignol)
 - build: Bump libevent to 2.1.11 gridcoin-community#2172 (@barton2526)
 - build: Update native_mac_alias, Remove big sur patch file in qt recipe gridcoin-community#2173 (@barton2526)
 - docs: Misc Grammar gridcoin-community#2176 (@barton2526)
 - build: miniupnpc 2.2.2 gridcoin-community#2179 (@barton2526)
 - rpc: Refresh rainbymagnitude gridcoin-community#2163 (@jamescowens)
 - util: optimize HexStr gridcoin-community#2185 (@div72)
 - refactor: misc style changes gridcoin-community#2177 (@div72)
 - rpc: consolidatemsunspent changes. gridcoin-community#2136 (@iFoggz)
 - refactor: Replace "GlobalStatus" state management gridcoin-community#2183 (@cyrossignol)
 - rpc, util: Remove use of ArgsManager::NETWORK_ONLY for now gridcoin-community#2190 (@jamescowens)
 - doc: Replace hidden service with onion service, Capitalize "Tor" gridcoin-community#2193 (@barton2526)
 - gui: Update Qt Linguist localization files gridcoin-community#2192 (@cyrossignol)
 - script: Shell script cleanups gridcoin-community#2195 (@barton2526)
 - build: set minimum required Boost to 1.58.0 gridcoin-community#2194 (@barton2526)
 - build, util: Prevent execution for Windows versions less than Windows 7 gridcoin-community#2203 (@jamescowens)
 - build: Tweak NSIS Windows installer gridcoin-community#2204 (@jamescowens)
 - build: Add bison in depends gridcoin-community#2206 (@iFoggz)
 - build: macOS toolchain bump gridcoin-community#2207 (@div72)
 - doc: Update build-unix.md gridcoin-community#2212 (@springfielddatarecovery)
 - build: Bump minimum python version to 3.6, Remove python2 references gridcoin-community#2219 (@barton2526)
 - depends: Change openSSL source path to Github gridcoin-community#2237 (@barton2526)
 - doc: Fix typo in bug report template gridcoin-community#2243 (@jamescowens)
 - ci: fold depends output gridcoin-community#2244 (@div72)

Removed
 - wallet: remove dead hardcoded addnodes gridcoin-community#2116 (@sweede-se)
 - rpc: Remove readconfig gridcoin-community#2248 (@jamescowens)
 - rpc: Remove obsolete comparesnapshotaccrual RPC function gridcoin-community#2100 (@jamescowens)
 - rpc: Remove memorypool RPC Command gridcoin-community#2214 (@RoboticMind)
 - rpc: Remove deprecated RPC commands gridcoin-community#2101 (@jamescowens)
 - Remove CCT from README, add Discord gridcoin-community#2134 (@barton2526)
 - refactor: Remove obsolete pubsub method definitions gridcoin-community#2191 (@barton2526)
 - refactor: Remove msMiningErrorsIncluded & msMiningErrorsExcluded gridcoin-community#2215 (@RoboticMind)
 - qt: Remove obsolete topLevelWidget(), Remove obsolete QRegExpValidator gridcoin-community#2198 (@barton2526)
 - net: Drop support of the insecure miniUPnPc versions gridcoin-community#2178 (@barton2526)
 - log: remove deprecated db log category gridcoin-community#2201 (@barton2526)
 - doc: Remove CCT from README and release process docs gridcoin-community#2175 (@barton2526)
 - build: Remove travis references gridcoin-community#2156 (@barton2526)

Fixed
 - gui: Fix macOS and designer font sizes gridcoin-community#2098 (@cyrossignol)
 - gui: Have the TrafficGraphWidget respect the selected stylesheet. gridcoin-community#2107 (@jamescowens)
 - gui: Fix macOS display inconsistencies gridcoin-community#2106 (@cyrossignol)
 - gui: Fix RPC console auto-complete background color gridcoin-community#2108 (@cyrossignol)
 - gui: Avoid reloading redundant stylesheets gridcoin-community#2109 (@cyrossignol)
 - gui: Fix "no active beacon" status gridcoin-community#2110 (@cyrossignol)
 - gui: Fix dark theme link text color visibility gridcoin-community#2115 (@cyrossignol)
 - scraper, util, qt: Fix several deprecations and warnings gridcoin-community#2131 (@jamescowens)
 - gui: Fix duplicate time in GUIUtil::dateTimeStr() gridcoin-community#2139 (@cyrossignol)
 - gui: Fix debug console traffic graph legend colors gridcoin-community#2142 (@cyrossignol)
 - gui: Fix nomenclature gridcoin-community#2104 (@jamescowens)
 - doc: Fix Typos gridcoin-community#2149 (@barton2526)
 - doc: Fix "master" branch build status badge in readme gridcoin-community#2167 (@cyrossignol)
 - gui: Fix Inter font rendering on Windows with FreeType gridcoin-community#2169 (@cyrossignol)
 - gui: Fix assert on non-existent data directory and GUI datadir chooser corner case issues gridcoin-community#2174 (@jamescowens)
 - gui: Fix display artifact in poll loading indicator gridcoin-community#2180 (@cyrossignol)
 - rpc, logging: Minor fixes for sidestake logging gridcoin-community#2187 (@jamescowens)
 - gui: Fix fractional scaling for dialog sizes gridcoin-community#2189 (@cyrossignol)
 - doc: Random fixes gridcoin-community#2197 (@barton2526)
 - doc: getbalance should say GRC not "btc" gridcoin-community#2199 (@barton2526)
 - net: Add missing verification of IPv6 address in CNetAddr::GetIn6Addr¦ gridcoin-community#2200 (@barton2526)
 - doc: remove duplicate line from .gitignore gridcoin-community#2202 (@Pythonix)
 - util: Tweak exception handling in MilliTimer class to eliminate compiler warnings gridcoin-community#2233 (@jamescowens)
 - depends: patch missing include in qt gridcoin-community#2234 (@div72)
 - wallet, rpc: Check each input for IsMine() in GetAddressGroupings gridcoin-community#2242 (@jamescowens)
 - util, qt: Fix snapshot download gridcoin-community#2246 (@jamescowens)
 - gui: Fix Column Widths in RPC Console. Elide long strings in their center. Indent user agent. gridcoin-community#2241 (@barton2526)
 - qt: Fix crash during download snapshot on macOS gridcoin-community#2250 (@jamescowens)
 - qt: Don't allow to open the debug window during splashscreen & verification state gridcoin-community#2245 (@barton2526)
 - gui: Fix address book selected model record when editing gridcoin-community#2253 (@cyrossignol)
 - researcher: Check wallet status before beacon renewal gridcoin-community#2254 (@cyrossignol)
 - qt: Prevent pasting (no label) as label in consolidation transaction gridcoin-community#2255 (@jamescowens)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor This is for refactoring (if also an enhancement, use that label too).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants