Remove includes in .cpp files for things the corresponding .h file already included #10574

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:redundant changing 37 files +0 −76
  1. practicalswift commented at 9:41 pm on June 11, 2017: contributor

    Remove includes in .cpp files for things the corresponding .h file already included.

    Example case:

    • addrdb.cpp includes addrdb.h and fs.h
    • addrdb.h includes fs.h

    Then remove the direct inclusion of fs.h in addrman.cpp and rely on the indirect inclusion of fs.h via the included addrdb.h.

    In line with the header include guideline (see #10575).

  2. fanquake added the label Refactoring on Jun 11, 2017
  3. practicalswift commented at 8:18 am on June 12, 2017: contributor

    Candidates for removal found by:

    0#!/bin/bash
    1
    2for H in $(git grep "" -- "*.h" | cut -f1 -d: | uniq); do
    3    CPP=${H/%\.h/.cpp}
    4    if [[ ! -e $CPP ]]; then
    5        continue
    6    fi
    7    cat "$H" "$CPP" | grep -E "^#include " | sort | uniq -c | \
    8      grep " 2 #include" && echo "$CPP" && echo
    9done
    
  4. practicalswift force-pushed on Jun 12, 2017
  5. practicalswift force-pushed on Jun 12, 2017
  6. practicalswift force-pushed on Jun 12, 2017
  7. practicalswift force-pushed on Jul 2, 2017
  8. practicalswift force-pushed on Jul 24, 2017
  9. practicalswift force-pushed on Jul 24, 2017
  10. practicalswift force-pushed on Aug 9, 2017
  11. practicalswift commented at 8:42 am on August 9, 2017: contributor
    Anyone willing to review? :-)
  12. razamobin commented at 10:08 pm on August 10, 2017: none
    Hi, I’m new to the bitcoin source code, but I looked for redundant includes and got the same changeset as you. Also I was able to run unit tests and they all passed (although I guess Travis did this already?). Either way, looks good to me.
  13. luke-jr commented at 4:03 am on September 2, 2017: member
    Soft NACK. IMO it’s better code quality to explicitly include everything needed in each source file using them.
  14. practicalswift force-pushed on Sep 10, 2017
  15. practicalswift commented at 7:08 pm on September 10, 2017: contributor
    Rebased! :-)
  16. danra commented at 7:50 pm on September 10, 2017: contributor
    I agree with luke-jr
  17. sipa commented at 7:53 pm on September 10, 2017: member

    @luke-jr @danra Then you should argue to change the guidelines in developer-notes.md:

    Every .cpp and .h file should #include every header file it directly uses classes, functions or other definitions from, even if those headers are already included indirectly through other headers. One exception is that a .cpp file does not need to re-include the includes already included in its corresponding .h file.

    I personally think that rule makes sense, as you can see the .cpp file as the continuation of the corresponding .h file.

  18. danra commented at 8:12 pm on September 10, 2017: contributor

    @sipa Yes, I’m for changing this rule as it creates an unnecessary dependency of the implementation (.cpp) on the interface (.h). If the interface no longer uses some other include directly, but the implementation still uses that include directly, removing the include from the interface would require adding it to the implementation.

    (Note I’m not for having the implementation re-include every include of the interface - only those which it uses directly)

  19. sipa commented at 10:39 pm on September 10, 2017: member
    @danra I understand that point of view, but I think it’s a non-issue. When the interface changes, almost certainly the implementation needs to change anyway.
  20. practicalswift force-pushed on Sep 29, 2017
  21. practicalswift commented at 12:51 pm on September 29, 2017: contributor
    Rebased! :-)
  22. Remove includes in .cpp files for things the corresponding .h file already included a720b928c8
  23. practicalswift force-pushed on Nov 16, 2017
  24. practicalswift commented at 9:28 pm on November 16, 2017: contributor
    Rebased! Getting this merged would get rid of 76 lines of redundant includes :-)
  25. laanwj merged this on Dec 12, 2017
  26. laanwj closed this on Dec 12, 2017

  27. laanwj referenced this in commit 5d132e8b97 on Dec 12, 2017
  28. laanwj commented at 2:01 pm on December 12, 2017: member
    utACK a720b928c80f18d340173f39f63e7ef9cfb367c1
  29. in src/qt/platformstyle.cpp:14 in a720b928c8
     7@@ -8,10 +8,8 @@
     8 
     9 #include <QApplication>
    10 #include <QColor>
    11-#include <QIcon>
    12 #include <QImage>
    13 #include <QPalette>
    14-#include <QPixmap>
    


    promag commented at 2:06 pm on December 12, 2017:
    This is in the header BUT I believe it’s not necessary there. IMO the first exercise should be to reduce to a minimal the includes in a header file.
  30. PastaPastaPasta referenced this in commit fd65b9589f on Mar 27, 2020
  31. PastaPastaPasta referenced this in commit 5a46d18116 on Mar 28, 2020
  32. PastaPastaPasta referenced this in commit 977a080fd9 on Mar 29, 2020
  33. PastaPastaPasta referenced this in commit b93fc710d5 on Mar 31, 2020
  34. UdjinM6 referenced this in commit f6e1b28661 on Mar 31, 2020
  35. PastaPastaPasta referenced this in commit fe8c18ca77 on Apr 1, 2020
  36. deadalnix referenced this in commit 019603ed8d on Jun 23, 2020
  37. ckti referenced this in commit bffacf8cc5 on Mar 28, 2021
  38. practicalswift deleted the branch on Apr 10, 2021
  39. furszy referenced this in commit 60d36292bc on Jul 26, 2021
  40. gades referenced this in commit eccb500a4d on Feb 21, 2022
  41. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-04 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me