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

Numerous minor changes for correctness. #648

Merged
merged 11 commits into from
Nov 9, 2024

Conversation

robertlipe
Copy link
Contributor

@robertlipe robertlipe commented Aug 21, 2024

  • Zillions of tiny edits to remove a warning or improve correctness.
  • Prep for push
  • Fix typo in a symbol that should be deleted...

Description

Contributing requirements

  • I read the contribution guidelines in CONTRIBUTING.md.
  • I understand the BlinkenPerBit metric, and maximized it in this PR.
  • I selected main as the target branch.
  • All code herein is subjected to the license terms in COPYING.txt.

I know this project isn't fond of these, but the screeching of
loading this project into Clion or Neovim or any other modern
tooling is too much. PRs like this are eating veggies. They may
not be tasty like features, but they're good for long-term health.

I won't break line-by-line here, so I'll just get big picture.

globals.h was basically including the world when it doesn't need to.
I reduced the amount of tokens exposed to each compilation unit by
simplifying globals.h and pushing more of an include-what-you-use
style. Not everything is totally hermetic, but some files that I
preprocessed are now seeing 20-40,000 lines fewer of headers each.

I tried to preserve the CP/M line endings in files that are
blessed with those. (Dare me to fix that in a future PR, please....)

For both English and C++, almost every change was from "you know what
I mean" to "what the reader actually read it as".
* Some typos are fixed.
* Some "bool foo = 1" became "boo foo = true".
* Ctors with a single argument became explicit. (Accidentally pass
  an integer that gets promoted to a pointer and then used as such
  for a good time.)
* Operator = was changed to handle the self setting case when needed.
* The second argument to strtoul and friends is a pointer, not an
  integer. nullptr > NULL for these.
* Default ctors and dtors, overrides, etc. are now spelled post C++11
  ways.
* When I was pretty sure that code was really dead, I removed it. LOTS
  remain.
* Prefer foo.empty() over foo.size == 0. Think testing the zflag instead
  of a cmp #0. The container might have to work hard to know the actual
  size, but know quickly that it has something.
* When header blocks were ugly enough to ooze, I sorted them. The
  rest probably need that on some rainy day.
* Sometimes when implicit container iteration spoke to me, I listened.
  May we never again have to figure out of a matrix dimesion is signed
  or unsigned. (LOL - we still do....)
* Consts and statics are labeled more aggressively.
* When loops were making read-only temp copies, I worked to look at
  the callers refs instead.
* Things that were scary (like improv) I touched only very lightly.
  I don't care about remotecontrol because I have a replacement pending.
  screen.cpp doesn't bother me because I've not ported to my S3-BOX.
  Fields that seem unused in places that may appear in a packet stayed.
  Since I don't edit those files, the warnings in them don't
  bother me. :-)
* When I disagree with the compiler, it loses. I LIKE 'if (3 == foo)'.
   and [[nodiscard]] is dumb. I'm not a total sellout.
* I didn't tackle big picture mismatches like "is time a double or a
  long". Those just spill over and downcast all over.

Probably way more, but most everything SHOULD be reviewable by just
paging through, nodding your head, tagging a few things to come back
to in the future if not in this PR (build times are just awful...) but
everything should be pretty mechanical and self-evident.

If you want to take it "except for ...", please feel free to just
edit the PR. I can probably explain anything individually, but I'm
probably not so emotionaolly attached to saving one copy on a loop
that I'll let the whole thing die - or force either of us to spend
the time for multiple builds. Those are getting crushing.

This whole PR was cherry-picked from my trees that have been running
mesmerizer, demo, a superset of hex, and a superset of radial circle,
and spectrum. They all seem fine, but I can't promise to have inspected
every pixel on every build. (I'm skeptical anyone can.)

Successful build:

===================== [SUCCESS] Took 117.20 seconds =====================

Environment               Status    Duration
------------------------  --------  ------------
demo                      SUCCESS   00:00:12.596
m5demo                    SUCCESS   00:00:45.958
m5plusdemo                SUCCESS   00:00:45.343
m5stackdemo               SUCCESS   00:00:49.577
heltecdemo                SUCCESS   00:01:08.584
heltecv2demo              SUCCESS   00:00:46.029
heltecv3demo              SUCCESS   00:00:48.808
lilygo-tdisplay-s3-demo   SUCCESS   00:00:32.880
ledstrip_amoled           SUCCESS   00:00:49.330
ledstrip                  SUCCESS   00:00:49.323
ledstrip_feather          SUCCESS   00:00:34.618
ledstrip_feather_hexagon  SUCCESS   00:00:34.183
ledstrip_feather_wrover   SUCCESS   00:00:31.670
ledstriplite              SUCCESS   00:00:33.466
ledstrip_pico             SUCCESS   00:00:32.423
spectrum                  SUCCESS   00:00:42.362
spectrum2                 SUCCESS   00:00:42.649
helmet                    SUCCESS   00:00:42.585
spectrum_elecrow          SUCCESS   00:00:56.125
spectrumstack             SUCCESS   00:00:42.633
spectrumlite              SUCCESS   00:00:45.230
spectrum_wrover_kit       SUCCESS   00:00:34.408
mesmerizer                SUCCESS   00:00:35.640
mesmerizer_lolin          SUCCESS   00:00:54.078
laserline                 SUCCESS   00:00:37.684
lantern                   SUCCESS   00:00:41.808
pdpgrid                   SUCCESS   00:01:57.374
chieftain                 SUCCESS   00:01:31.571
umbrella                  SUCCESS   00:01:28.386
generic                   SUCCESS   00:01:34.298
panlee                    SUCCESS   00:01:45.128
ttgo                      SUCCESS   00:01:30.101
xmastrees                 SUCCESS   00:01:47.136
insulators                SUCCESS   00:01:39.503
magicmirror               SUCCESS   00:01:46.613
atomlight                 SUCCESS   00:01:26.652
spirallamp                SUCCESS   00:01:46.936
fanset                    SUCCESS   00:01:58.392
cube                      SUCCESS   00:01:57.196
====================== 39 succeeded in 00:40:19.275 ======================
@rbergen
Copy link
Collaborator

rbergen commented Aug 25, 2024

Hi @robertlipe, I was wondering how/to what extent you've tested these changes?

@robertlipe
Copy link
Contributor Author

robertlipe commented Aug 25, 2024 via email

@rbergen
Copy link
Collaborator

rbergen commented Aug 25, 2024

For me the main thing is that I hate breaking functionally working code to implement improvements that may not even be contested in themselves, but are "only" improvements on a non-functional level. At a 99.5% chance of over-explaining, the reason is that in my mind the only real reason for code to be there is to do the stuff it does. There are almost always multiple ways to do stuff and some are better than others, but if the code that's there works and the best-case scenario from a functional perspective is that it does exactly what it does now, then I tend to stick to "if it ain't (functionally) broken, don't try to fix it."

In a "binary world" that would put me on the track of "thanks, I'll take the comment changes, but let's just leave the code alone until we have another reason to change it". However, I do understand the value of maintainability, consistency, testability (yes, I read ahead), etc. so I'm not going to make that the conclusion just like that.

It does mean that I think we should indeed know we've tested all code paths we're touching at least once, and can't really have any known blind spots there. As responsible guardians of our users' functionality, if you will. And I know, most if not all of these changes should "just work", but you and I have both been doing this long enough to have collected a beautiful batch of campfire stories where it should have just worked... and didn't.

So, if testing blind spots do exist (like the colorserver example you mention), then let's cover those before we proceed. And colorserver is a great example, because I also don't use that - which is why I don't think I've ever touched its code in my three years on this project. If we can "casually" make the way we cover them automated and repeatable then one could successfully argue with me that we actually have a reason to touch the code.

Concerning the contestability of the changes in this PR at a non-functional level: in my view many of them are clearly improvements because the English language dictates that words are spelled in a certain way, because .empty() is less error-prone than .size() == 0, adding const more clearly documents in code what is (not) supposed to happen in a function or with a variable/parameter, etc. In some other cases I think it's more of a coding style/standard thing. Is a raw string literal really clearer than two escaped double quotes, when that literal is still part of a string concatenation? I think one could argue either way (and in all honesty: I think not, but that's also just an opinion).

Which kind of brings me to the question about what makes changes like these more digestible for me, in decreasing order of importance:

1., 2. and 3. Make sure you've tested the new version of the old working code and have seen it working
4. Make it "obvious" that the change is an improvement, not the likely subject of a conversation that boils down to "but I really think blue is better than red!" (I know there is a bit of aptness in US politics with that statement, and it's actually a case in point in a way: I do have a strong opinion on the matter, but as I have no vote and therefore no influence, I think it's best for me to keep my mouth shut about that topic...)

Also, non-functional changes that are part of another "objective" improvement are always easier for me to be comfortable with, if only because that tends to cover the first criterion.

I don't know if I've covered all points you asked my input on with this; feel free to point out any that I missed.

Cheers,
Rutger

@rbergen rbergen mentioned this pull request Oct 10, 2024
4 tasks
@robertlipe robertlipe closed this Nov 7, 2024
@rbergen
Copy link
Collaborator

rbergen commented Nov 7, 2024

@robertlipe May I suggest we reopen this? I really would like to incorporate these changes to the extent we (that includes me personally) can test them, and I that's actually the majority of them.

robertlipe and others added 6 commits November 8, 2024 08:57
I know this project isn't fond of these, but the screeching of
loading this project into Clion or Neovim or any other modern
tooling is too much. PRs like this are eating veggies. They may
not be tasty like features, but they're good for long-term health.

I won't break line-by-line here, so I'll just get big picture.

globals.h was basically including the world when it doesn't need to.
I reduced the amount of tokens exposed to each compilation unit by
simplifying globals.h and pushing more of an include-what-you-use
style. Not everything is totally hermetic, but some files that I
preprocessed are now seeing 20-40,000 lines fewer of headers each.

I tried to preserve the CP/M line endings in files that are
blessed with those. (Dare me to fix that in a future PR, please....)

For both English and C++, almost every change was from "you know what
I mean" to "what the reader actually read it as".
* Some typos are fixed.
* Some "bool foo = 1" became "boo foo = true".
* Ctors with a single argument became explicit. (Accidentally pass
  an integer that gets promoted to a pointer and then used as such
  for a good time.)
* Operator = was changed to handle the self setting case when needed.
* The second argument to strtoul and friends is a pointer, not an
  integer. nullptr > NULL for these.
* Default ctors and dtors, overrides, etc. are now spelled post C++11
  ways.
* When I was pretty sure that code was really dead, I removed it. LOTS
  remain.
* Prefer foo.empty() over foo.size == 0. Think testing the zflag instead
  of a cmp #0. The container might have to work hard to know the actual
  size, but know quickly that it has something.
* When header blocks were ugly enough to ooze, I sorted them. The
  rest probably need that on some rainy day.
* Sometimes when implicit container iteration spoke to me, I listened.
  May we never again have to figure out of a matrix dimesion is signed
  or unsigned. (LOL - we still do....)
* Consts and statics are labeled more aggressively.
* When loops were making read-only temp copies, I worked to look at
  the callers refs instead.
* Things that were scary (like improv) I touched only very lightly.
  I don't care about remotecontrol because I have a replacement pending.
  screen.cpp doesn't bother me because I've not ported to my S3-BOX.
  Fields that seem unused in places that may appear in a packet stayed.
  Since I don't edit those files, the warnings in them don't
  bother me. :-)
* When I disagree with the compiler, it loses. I LIKE 'if (3 == foo)'.
   and [[nodiscard]] is dumb. I'm not a total sellout.
* I didn't tackle big picture mismatches like "is time a double or a
  long". Those just spill over and downcast all over.

Probably way more, but most everything SHOULD be reviewable by just
paging through, nodding your head, tagging a few things to come back
to in the future if not in this PR (build times are just awful...) but
everything should be pretty mechanical and self-evident.

If you want to take it "except for ...", please feel free to just
edit the PR. I can probably explain anything individually, but I'm
probably not so emotionaolly attached to saving one copy on a loop
that I'll let the whole thing die - or force either of us to spend
the time for multiple builds. Those are getting crushing.

This whole PR was cherry-picked from my trees that have been running
mesmerizer, demo, a superset of hex, and a superset of radial circle,
and spectrum. They all seem fine, but I can't promise to have inspected
every pixel on every build. (I'm skeptical anyone can.)

Successful build:

===================== [SUCCESS] Took 117.20 seconds =====================

Environment               Status    Duration
------------------------  --------  ------------
demo                      SUCCESS   00:00:12.596
m5demo                    SUCCESS   00:00:45.958
m5plusdemo                SUCCESS   00:00:45.343
m5stackdemo               SUCCESS   00:00:49.577
heltecdemo                SUCCESS   00:01:08.584
heltecv2demo              SUCCESS   00:00:46.029
heltecv3demo              SUCCESS   00:00:48.808
lilygo-tdisplay-s3-demo   SUCCESS   00:00:32.880
ledstrip_amoled           SUCCESS   00:00:49.330
ledstrip                  SUCCESS   00:00:49.323
ledstrip_feather          SUCCESS   00:00:34.618
ledstrip_feather_hexagon  SUCCESS   00:00:34.183
ledstrip_feather_wrover   SUCCESS   00:00:31.670
ledstriplite              SUCCESS   00:00:33.466
ledstrip_pico             SUCCESS   00:00:32.423
spectrum                  SUCCESS   00:00:42.362
spectrum2                 SUCCESS   00:00:42.649
helmet                    SUCCESS   00:00:42.585
spectrum_elecrow          SUCCESS   00:00:56.125
spectrumstack             SUCCESS   00:00:42.633
spectrumlite              SUCCESS   00:00:45.230
spectrum_wrover_kit       SUCCESS   00:00:34.408
mesmerizer                SUCCESS   00:00:35.640
mesmerizer_lolin          SUCCESS   00:00:54.078
laserline                 SUCCESS   00:00:37.684
lantern                   SUCCESS   00:00:41.808
pdpgrid                   SUCCESS   00:01:57.374
chieftain                 SUCCESS   00:01:31.571
umbrella                  SUCCESS   00:01:28.386
generic                   SUCCESS   00:01:34.298
panlee                    SUCCESS   00:01:45.128
ttgo                      SUCCESS   00:01:30.101
xmastrees                 SUCCESS   00:01:47.136
insulators                SUCCESS   00:01:39.503
magicmirror               SUCCESS   00:01:46.613
atomlight                 SUCCESS   00:01:26.652
spirallamp                SUCCESS   00:01:46.936
fanset                    SUCCESS   00:01:58.392
cube                      SUCCESS   00:01:57.196
====================== 39 succeeded in 00:40:19.275 ======================
@rbergen
Copy link
Collaborator

rbergen commented Nov 8, 2024

I'm reopening this myself - I noticed the PR was created from a branch in my own fork, so I feel I'm not out of line by doing so.

Compared to the original submission by @robertlipe:

  • The changes to socketserver.h have been reverted, as I can't properly test them.
  • I've reverted a couple of changes I felt didn't constitute an improvement to the codebase.
  • I've synced the PR's head branch with main, and projected some original changes on the diff.
  • I've included an update to platformio.ini, to fix builds for M5 devices - they started breaking because the M5Unified library now depends on M5GFX, which wasn't pulled in when M5Unified was pulled in from GitHub instead of as a PlatformIO package.

All other changes included in the original PR have been tested by myself using the Mesmerizer and Spectrum (for M5StickC Plus) configurations.

@rbergen rbergen reopened this Nov 8, 2024
@rbergen
Copy link
Collaborator

rbergen commented Nov 9, 2024

As I prepare to merge this, I'm hereby documenting for posterity that I'll restore the originally proposed changes to socketserver.h in this PR's head branch after this PR has been merged.

That way they can still be applied after someone has been able to confirm on actual hardware that the changes don't break anything.

@rbergen rbergen merged commit 15221f2 into PlummersSoftwareLLC:main Nov 9, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants