Code clean-up and simplification - #21
Conversation
…bool instead of int.
…rameter type and declaration ordering.
… compiler warnings.
|
@jbowler your comments on these proposed changes would be most welcome, especially as there are conflicts. |
|
@nayuki thanks for unearthing these. They look like useful changes to move this elderly codebase to a more maintainable format. It would be simpler to handle them as individual PRs, especially as some have already been done. |
|
@svgeesus most likely the @nayuki: you should verify using the changes with the CFLAGS (in particular CERRORS) that I added to Makefile.unx. I believe those should work for both the GCC and LLVM. In general: a quick review for the changes as described (i.e. without looking at the source code) suggests those changes are all good. They cover many of the things I was thinking of doing but haven't done. There are a couple of caveats below but the only major issue I see is the introduction of There is a policy issue here: I never use There is a second policy issue surrounding indentation. This is purely stylistic and since I've contributed to a few FOSS projects and worked (many years ago) in different corporate environments I just try to copy the style. I hope most software developers do that, however the style has to be documented, clearly and, preferably, supported by editor settings. Those should apply cross-organisation. Cosmin added .editorconfig which will work in this case but probably requires a major re-indent. That should be done in one step when there is no active development. What I suggest @svgeesus is that you give @nayuki the privileges to at least create a branch in pnggroup/pngcheck and make this the development branch. The constraint here is that because I'll separate detailed comments out. |
|
@jbowler Thanks for your thoughts. A partial reply:
In the worst case, I could restart with the HEAD/tip of development that you would specify, and painstakingly re-apply each of my changesets individually and deal with any problems that materialize (merge conflicts, semantic errors, additional changes on code that was not present when I made the original changes).
I agree that this technique is fishy. If you look at my changeset, you can see that I'm casting the value I don't think there is a clean way to deal with this situation - whether modifying existing code, adding new code, or ignoring the signed-unsigned compiler warnings. It's a matter of trade-offs and which type of ugliness you prefer.
I understand. I am extremely strict on indentation in my own projects, but I am way more lenient on other people's projects. If you look at the changeset, I changed just 14 lines in the 5200-line file. The code had inconsistent indentation to begin with. I was fixing the tiny amount of inconsistency in favor of the overwhelming majority style (2 spaces per indent) already present in the file.
As I don't expect to do ongoing development on pngcheck, I'm okay if you don't give me commit privileges in your repository. Thank goodness this is not the CVS or SVN days. I'm totally okay with you plucking changes from my copy of the repo. |
Detailed comments.I'm assuming, @nayuki, that your comments accurately summarise all the actual changes. I'm not sure I see any need to do line-by-line review and not doing it avoids getting lost in purely stylistic issues; what I call code correctness. In addition the code as it stands is at times very difficult to understand (see my comments in #23) and that makes it difficult to review line-by-line. Build failures:missing-prototypes: I get errors for "-Werror=missing-prototypes" (you must either declare a prototype with type-limits: -Wtype-limits: comparing discarded-qualifiers: assigning string literals to Individual changes:
Conclusions:Mostly harmless so far as I can see. It is worth noting that changes which alter the UI need a bump to a major version. That could be "3.1" or it could be "4.0". So far as I can see these changes don't require that but the exit code change I suggested in #23 would. |
|
@jbowler Thanks for the more detailed review and context (e.g. the
I wasn't aware of this issue back then, so it wasn't part of my original changesets. I'm happy to deal with this issue in the rewrite.
Well, I don't see that policy in force even in the current version of the code. Also, I have to voice my complaint that 3 spaces is a highly unusual policy (usually 2, 4, or tab) that I've never seen any project use, and is also aesthetically unpleasing IMO. I'm not going to stop you from doing it, though.
I don't see any use of
I should note that the code already had one C99 comment before I started, so I didn't make things worse: Line 3879 in 194a7fd
I wasn't interested in pngsplit.c because I haven't used it, so I'm not even aware of what the program does. So I didn't make any changes there; only made changes in pngcheck.c. |
|
Some clarifications:
Expect to see much more use of explicit
I guess from my point of view the bottom line @svgeesus is that this is desirable code cleanup some of which has already been done in the main branch and some of which raises policy issues ( |
I apologize for the complexity of processing this set of commits.
Back on 2021-09-12, after emailing Greg Roelofs, I imported the publicly available source code of pngcheck at version 3.0.3 (released on 2021-04-25). Evidently, other people have imported that code and ended up with the exact same working tree but with different commit metadata: a9cf3731 by Nayuki, cab5ffb1 by svgeesus, 67d38027 by Chris Lilley. You can confirm the matches by performing
git diff <CommitHash0> <CommitHash1>and seeing zero output.From that initial state, I made 21 changes, and I'll let the commit messages speak for themselves (oldest to newest):
The result of my original batch of work is at https://github.com/nayuki/pngcheck/tree/ea8192e360e6b13b6699908b2f5198395a24ca21 . The changes amount to improvements for human readability and semantic clarity, but don't introduce any new functionality. I confirm that the code compiles with no errors in GCC and LLVM.
I just discovered this project repository ( https://github.com/pnggroup/pngcheck ) today and it looks official enough that it could host the work that I did. To that end, I rebased my commits so that the starting point is not a9cf373 but instead cab5ffb (which as I said before, has the exact same working tree). The new tip of my development branch is e2cfeeb0 (patch-0), and is what I am proposing in this pull request.
I understand that this has merge conflicts with the current main commit and probably doesn't have a simple resolution. I understand that while each of my commits is simple and self-contained, the cumulative result of all of them is not easy for you to handle.
Let me know if this work is acceptable, and whether I can do anything to help get it integrated. Thank you for your consideration.