Tidy up, modernise code and VS cleanup#1920
Conversation
|
Can we lose the dropping of the space before |
|
@VisualMelon I know there are a lot of files changed due to that, my bad. But I can't really easilly revert that back on my side. Maybe the easiest is to Hide whitespace in the 'Files changed' tab. This should help a lot, let me know what you think |
Thanks ;) feels like I'm having to relearn how to use github at the moment. Could we change it to the opposite? (i.e. add the spaces before Tagging @HavenDV who has suggested we sort out some XAML standards, and who might know better what is the Zeitgeist on XML whitespace. |
|
Don't know why azure is failing at the moment; I doubt it's anything wrong with this PR. |
|
Slowly getting through these; all looks sane so far. @BobLd just to check, are these otherwise all the automatic changes from the old PR? |
There was a problem hiding this comment.
There are a few changes here I wouldn't personally make, but nothing too objectionable. is patterning, ?. on events, and readonly properties are nice. Everything else seems reasonable enough.
Couple suggestions below among examples of things that don't fill me with joy.
|
|
||
| double nextInterval = goodIntervals.FirstOrDefault(i => i > interval); | ||
| if (nextInterval == default(double)) | ||
| if (nextInterval == default) |
There was a problem hiding this comment.
Not sure I like this, but if it's automatic, so be it.
| protected void BindCore(OxyInputGesture gesture, IViewCommand command) | ||
| { | ||
| var current = this.InputCommandBindings.FirstOrDefault(icb => icb.Gesture.Equals(gesture)); | ||
| var current = this.InputCommandBindings.Find(icb => icb.Gesture.Equals(gesture)); |
There was a problem hiding this comment.
Prefer FirstOrDefault, but again, if this is an automatic change it's OK.
| else | ||
| { | ||
| c = c >> 1; | ||
| c >>= 1; |
There was a problem hiding this comment.
Not wild about this, but again, if it's automatic I'm not bothered.
| if (dh > 0.5) | ||
| { | ||
| dh -= 1.0; | ||
| dh--; |
There was a problem hiding this comment.
Again, prefer version which makes it clear this is a float, but not going to fight VS over it.
There was a problem hiding this comment.
you're making a good point, happy to revert back and disable the warning. @VisualMelon what do you think?
There was a problem hiding this comment.
Yep, if it's easy to disable this whole class of warning that'd be great.
| List<double> binBreaks = new List<double>(binCount + 1); | ||
|
|
||
| binBreaks.Add(start); | ||
| List<double> binBreaks = new List<double>(binCount + 1) |
There was a problem hiding this comment.
Don't like this much either, but again, if it's automatic, I'll live.
|
I would prefer this PR to be broken down into separate PRs that change one type of style at a time. For example, a PR that changes strings to nameof and so on. This makes it much easier to check. |
|
@HavenDV thanks. Looks like |
|
Separate commits would be nice, but I don't think it's too big a problem if it's difficult or time-consuming. |
|
I will wait for progress on this PR before continuing with nullable enable PRs |
|
@VisualMelon @HavenDV I've implemented your feedback.
Once I have your go, I will squash the commits to make it clean |
|
@BobLd I'll probably not have time to look at this properly for a quite a few days, but nothing jumps out to me as a problem. Re. azure, looks like it has never worked for the .NET Core versions of the tests, but at some point it started failing noisily rather than silently. I tried a few things to make it happy (see the open PRs), but failed and ran out of time. Not a problem for this (or any other) PR so long as we check it's the .NET Core tests failing and not something unexpected. Don't worry about squashing: can do that within the github interface now. |
VisualMelon
left a comment
There was a problem hiding this comment.
If it is possible to turn off the automatic contraction for x = x (whater) y to x (whatever)= y that would be good. None of the instance here improve readability, and I think a number of then make it worse.
I also really don't like all the checks of the form x?.y > z: this is producing a bool from an int? > int comparison and that's just wrong. bool? == bool is acceptable, but very happy for that to be disabled as well if they're all under one rule.
I'd also much prefer if it didn't remove all the empty lines within methods.
| double y_portion = delta_y / _y; | ||
| lineend_x = y_portion * _x; | ||
| lineend_y = y_portion * _y; | ||
| result = new ScreenPoint((y_portion * _x) + midPoint.X, (y_portion * _y) + midPoint.Y); |
There was a problem hiding this comment.
Maybe change this to use lineend_* instead; probably clearer.
| // </copyright> | ||
| // <summary> | ||
| // Provides information about an <see cref="OxyImage" />. | ||
| // Provides information about an <see cref="OxyImage />. |
There was a problem hiding this comment.
Something looks fishy here.
| byte[] streamBytes = null; | ||
|
|
||
| if (this.contents != null && this.contents.Length > 0) | ||
| if (this.contents?.Length > 0) |
There was a problem hiding this comment.
I was a bit unsure about this last time, now I'm sure I don't like it... Don't want to lose the event refits etc. but these nullable comparisons are not nice. There are some instances of blah?.blah() == true also, but if they're not nearly as bad.
Don't know what others opinions are on this, but this sort of lifting makes me very uncomfortable.
| this.IsPanEnabled = (this.XAxis?.IsPanEnabled == true) | ||
| || (this.YAxis?.IsPanEnabled == true); | ||
|
|
||
| this.IsZoomEnabled = (this.XAxis != null && this.XAxis.IsZoomEnabled) | ||
| || (this.YAxis != null && this.YAxis.IsZoomEnabled); | ||
| this.IsZoomEnabled = (this.XAxis?.IsZoomEnabled == true) | ||
| || (this.YAxis?.IsZoomEnabled == true); |
There was a problem hiding this comment.
Per the above comment about lifting with comparisons, these are OK, but also not going to complain if they are lost if it means we can keep the rules simple.
| if (dh > 0.5) | ||
| { | ||
| dh -= 1.0; | ||
| dh--; |
There was a problem hiding this comment.
Yep, if it's easy to disable this whole class of warning that'd be great.
| this.StrokeColor = OxyColors.Black; | ||
| this.StrokeThickness = 0; | ||
| this.TrackerFormatString = XYAxisSeries.DefaultTrackerFormatString; | ||
| this.TrackerFormatString = DefaultTrackerFormatString; |
There was a problem hiding this comment.
These are OK, but again, if there's a way to turn them off, I think these are clearer as they were.
This could lead to inconsistency, however. What are others' opinions?
| { | ||
| this.MinY = Math.Min(this.ActualItems.Min(r => 0), this.ActualItems.Min(r => r.Height)); | ||
| this.MaxY = Math.Max(this.ActualItems.Max(r => 0), this.ActualItems.Max(r => r.Height)); | ||
| this.MinY = Math.Min(0, this.ActualItems.Min(r => r.Height)); |
There was a problem hiding this comment.
(Note: this is OK: checks that the collection isn't empty above)
|
@BobLd thanks for your changes. If we can change a few of the rules per the above, that's great. I don't know much about how this is all configured (must be editor config or something?), but obviously if we can use the VS defaults where possible and only disable those rules that we've agreed are problematic that'd be great. I didn't see a config file in the PR: does it just need adding or have I missed something? (e.g. my VS doesn't light up all of these same things). |
Jonarw
left a comment
There was a problem hiding this comment.
Thanks for tackling this task! I think I can get behind pretty much all of the changes. I'd just have two additional comments:
- (As already mentioned by @VisualMelon) Would it be possible to include a VS configuration file, so others would get the same automatic suggestions and refactorings regarding code style? I think this should be possible with an EditorConfig file.
- Could we define (and enforce) a consistent code style regarding
varusage? I think this is still a bit all over the place in different sections of code. My personal style is to always usevarwherever possible, but I would also be happy with other conventions, as long as it is consistent.
|
@BobLd CI should be happy after a rebase |
|
@BobLd if you can include a VS configuration file I'll take another look at this |
|
Following the discussion in #2012, I will close this for now and revisit once we have fewer open PRs. If you have a VS config file that you could share you are welcome to do so, if not no worries :) |
|
Thanks for that @VisualMelon, I'll try to do something along the lines but focusing on other projects at the moment |

Checklist
Changes proposed in this pull request:
@oxyplot/admins