Opened 4 years ago
Closed 4 years ago
#20167 closed enhancement (fixed)
[patch] Improve code readability by replacing indexed loops with foreach
Reported by: | gaben | Owned by: | team |
---|---|---|---|
Priority: | minor | Milestone: | 20.12 |
Component: | Core | Version: | |
Keywords: | Cc: |
Description ¶
There is no code logic change, just readability improvements.
Not all indexed loops replaced, just where it makes the code more compact and readable.
Also found a file with inconsistent formatting (UrlValidatorTest.java), this also got fixed.
You may want to rename the loop variables in a few places if the ones I provided not good enough :)
Change History (18)
by , 4 years ago
Attachment: | enhanced_for_loops.patch added |
---|
comment:1 by , 4 years ago
by , 4 years ago
Attachment: | enhanced_for_loops_v2.patch added |
---|
three more readability improvements not related to loops
follow-up: 4 comment:3 by , 4 years ago
@GerdP Thanks, much better :)
If anyone commits this, merge my last and GerdP's patch. I could merge it by myself, but don't know what the patch etiquette is, so left it as is.
comment:4 by , 4 years ago
Replying to gaben:
@GerdP Thanks, much better :)
If anyone commits this, merge my last and GerdP's patch. I could merge it by myself, but don't know what the patch etiquette is, so left it as is.
Apply it with a note "patch by xxx" or "modified patch by xxx" depending on the fact if you changed something or not. NOTE: Do not use full email addresses in a comment (if only e-mail known the e.g. use only the name part of the mail).
follow-up: 7 comment:6 by , 4 years ago
@stoecker Thanks, I think wiki:DevelopersGuide/PatchGuide needs an update ;)
@GerdP Don't forget committing your improvements of the NTV2GridShiftFile
.
comment:7 by , 4 years ago
Replying to gaben:
@GerdP Don't forget committing your improvements of the
NTV2GridShiftFile
.
sonar lint doesn't like them and suggests to merge the loops. I have no idea what this structure contains so I didn't want to replace one issue with another one.
comment:8 by , 4 years ago
Oh, I see. And how does Sonar felt about my patch? I tried checking, but the browser just stalled. Maybe I need a local instance.
Btw JOSM's Sonar instance is 1 year old, the latest version is 8.5.1, but 8.0 deployed.
comment:9 by , 4 years ago
Your patch introduced a checkstyle issue in class UrlValidatorTest (linelength > 145)
Did not see that before committing and I am not sure what to do with that long line
"http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org"));
If the number of dots is relevant it might be better to compute this test string using the number.
comment:10 by , 4 years ago
I guess you can also disable that test for that line similar to https://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java#L51
comment:14 by , 4 years ago
Milestone: | → 20.12 |
---|
comment:15 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
OK for most, but I think
NTV2GridShiftFile
andConnectivityRelations
are not really improved.