Fix some shadowing by using more distinct variable names#228
Open
0Xellos wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixing some
-Wshadow warnings, mostly renaming, one redundant argument removed. Reasoning copied from blogpattern, there's a members(line 733) that's shadowed by a c.arg. (line 1531). However, the constructor doesn't just use copystopattern::s, it also parses it into a more structured form that the new instance stores (note thatsis passed by mutable value). Then,sis only used at one point - the functionpattern::srcreturns it. Therefore, let's rename it tosource, making the code self-documenting that it's the pattern's source string.FileInputStreamReader::getc(line 1777) takes aFILE*as an argument, which shadows its memberfile(line 1763). This function is private and only used within that class a few times with the memberfilepassed as that argument everytime. We might as well remove that argumentfile, it's unnecessary and confusing.FileInputStreamReader, there's a membername(line 1764) shadowed in a constructor (line 1809). The same happens inBufferedFileInputStreamReader(lines 1882, 1923). I'm not sure what those variables are supposed to be for and it highlights why it's good to deal with shadowing - when a constructor takes afileand aname, is it supposed to be the name of the file? Or a more general name given to the stream, which would probably include the filename but isn't limited to it? There are only few usages that don't shed much light on the situation, so I'm going to err on the side of generality and rename the c.arg. tostreamNamein both cases to indicate that it's not forced to be just the filename.InStreamhas a membermode(line 2018) that's shadowed by a c.arg. repeatedly again (lines ~2030, ~3310). What mode? Mode in testlib can be file opening mode, strict/non-strict, input/output/answer, it's quite a confusing word... and the way it's named would suggest some file mode or stream mode, but it's actually input/output/answer (as the type shows, but digging through types shouldn't be action number 1). That has nothing to do with the stream or the file. I want to rename each c.arg. tocontentModeand am opening an issue that all these modes should be named clearer.setAppesModeEncoding(line 4645) is setting the global variableappesModeEncoding(line 2382) from a shadow argument. Putting aside that global variables are evil and should at least be put in a global state struct within a namespace, I tend to prefix such arguments withnew, sonewAppesModeEncoding. Sometimes the current value matters and it's better to distinguish between current (not yet old, the change can fail!) and new value by name.Still remaining: stream readers' member
file, members ofValidatorBoundsHitshadowed in constructors are named clearly enough, see #229.