-
-
Notifications
You must be signed in to change notification settings - Fork 733
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
Inconsistent config settings range usage #1116
Comments
Alrighty; so the intended behaviour is
The macros are generally not a large concern given that they change infrequently and are mostly there as a collection point for magic numbers than for edit-ability. It is expected their values are tested after any changes. The |
Thanks for your attention to this issue \o/ Using 'min <= value < max' suggests a review of the configuration settings may be warranted to be sure they have the intended range. Adusting all 'max' settings by +1, or alternatively adding some macro function that does and use it throughout initializing 'settingsConstant' seems like a better solution to me.
Rule that I recite to everyone at some point when doing code inspections: "You can get away with coding almost anything, other than knowingly writing bad code, if you just comment your intentions! Sometimes you need to code stuff oddly, but others looking at your code are not going to know your reasons. Even a comment like this is useful:
Also, you are likely to forget the reasons yourself after a few months!" |
You are more than welcome to do one if you have time 😀
now we are into personal opinion territory.
Now that said; by asking around this, makes me suspect that its not overly clear that the comparisons are written in grammatical order, so a comment might help here.
I wish I could 🙃 |
I would, but unfortunately I don't own all the supported irons, nor do I claim intimate knowledge of every setting, and the consequences of them. The reason I originally posted this bug was because I changed how the temperature controls worked, and that patch no longer worked on the latest codebase. When I adapted my patch, it was obvious I had unintentionally broken other things. That's when I realized there were different ranges in use. Then I ran into solderingTemp not being adjusted through the same methods, with its own range checking hardcoded with constants in gui_solderingTempAdjust() [that also failed if the 'min' is set to 0 because then the comparison 'newTemp < MIN_TEMP_C' becomes 'newTemp < 0' which is always false for unsigned numbers], which made me consider the possibility that other things I'm unfamiliar with might also have their own special handling. After having cooked a thermistor in a 3D printer because of a failed PID, I decided I didn't want to cook my TS100, and thought I'd let the expert(s) confirm or deny what I thought I might have discovered.
Actually, I really appreciated your original explanation, and thought "Gee, that's clever!" I stared at the code in question a long time, thinking it was just multiplied by -1 so the exact same thing, and then doubted myself thinking I must be missing something, making a silly math mistake (I actually looked-up solving inequalites to confirm) because why would somebody purposely do that? I really wish you'd added your comment of:
I would have just gone, "Gee, that's clever", and moved on.
A co-worker recently strongly disagreed with my rule recital, insisting that he'd forget the reasons by the end of the week rather than in a few months. Another chimed in that he be lucky to make it to the end of day. Memory aside, the previous point remains that most developers lack the ability to read minds, hence sharing the wisdom in comments.
True. I apologize if I may have overstepped or offended. The intention was to be helpful, not insulting. After thinking things over some more, I agree with you that it is better to use 'min <= value < max' everywhere for simplicity. Most developers wouldn't expect 'min <= value <= max' which makes it a bad choice. However, I just don't see having say a max temperature define of say 451F when that results in an actual max temperature of 450F. That could also require adjusting many values in the configuration files, which could have be sourced from other developers. Hence adding +1 when used in 'settingConstants', changing a much smaller amount of code. BUT that could lead to forgetting to add +1, hence the idea of using an ugly macro like say
would make it stand out like a sore thumb when used, making it impossible to overlook:
I'm not claiming it is the best solution, just one that is hard to go unnoticed. Note that in that example I also removed the hardcoded constants, and changed the increment to 0 as it really doesn't apply to solderingTemp. As I've already admitted above, I know I'm not always right, but I am always open to learn new tricks, like coding "within one increment". |
So I've been thinking on this too; and I also see the gain of So my original thinking was as I stated above, with keeping to match other conventions; and this works really well for things where its iterating over options, since for three options you can use 0,1,5 to map to [0,1,2,3,4]; since that feels nicer to me. But I can also see good intentions in Since you raise the point around the temperature, its the main cause of the "within 1 increment of" as well, since it often doesnt land nicely on a more simple bounds check. Thus, I'm not not certain which is the nicer range setup to use. 🤷🏼
Dont ever let this stop you really; anyone is qualified to give this code a skim over and raise issues :)
Ahh, I would love to hear about what/how you changed things :)
The settings change was a non-trivial change, but was also long overdue. Apologies it was a mess for you :(
There is a hardware sanity mask to stop you cooking the tip beyound around 430C or so so, even if your temp settings go wildly wrong.
Aye; I do agree to this, will definitely add one 🤗
Naah not all; possibly didnt come across but I meant that more in a " this could easily be one of those things that everyone differs on". Definitely not offended :)
As i mentioned earlier, now I'm conflicted on this.
Yeah they are sorta there as placeholders, so there is at least something non-zero there
I do wonder how much that is less of a trick and a stylistic choice I've picked up somewhere and long forgotten the source. |
SummaryWhen quickly adjusting temperature with a long-press, going through say 271, 276, 281, 286, 291 is visually a lot for my shotglass brain to follow, especially when the numbers are changing quickly. Maybe not for others, but for me it is hard to follow. It is much easier for me to follow going rapidly from 271 to 275, 280, 285, 290 then fine-tuning to 291 with a short-press. I admit to being in awe of market vendors that can add a mixed basket of item prices in their heads before I have even reached for my wallet. However, I did set grade school records for speed-reciting any multiplication table of any length. Configuration changes
I was able to get the current codebase to do this by using custom increment functions, though I did note a lack of a way to replace the decrement function, but didn't need to as these values only increment. I suspect solderingTemp is the only setting that decrements (maybe voltage calibration uses it?), but it is currently the only setting that doesn't use the standard increment / decrement functions in any manner. Temperature adjustment changes
I'd really prefer to have done this using the standard setting adjustment routines, and that is on my "To Do" list. This is just a small excerpt sample from my personal patch:
Unrelated change
I also noticed that the EN translation file (and perhaps others) has been DOS edited so CRLF. Not yet implemented
|
Address settings bounds checks #1116 Pull in fix for PD PPS
In regards to the rounding values to the increment, this makes a fair bit of sense to me.
Happy for this edit to be put in a PR; maybe just change languages you know to keep it easy :) |
Good afternoon @aemileski, If this solves your issue, please do not forget to close this. 😊 thanks in advance |
I've been away from the code long enough (too long) to remember what triggered my 'spidey-sense' with ranges. Looking over the current code ... and nothing. No tingling at all. I guess that's good. Will stare at it some more, fiddle with my iron some more, and rework my customization patch. Looks like you went with min<=value<=max after all, if that's indeed the case, the max is unreachable in this function (easy to overlook, given it is only used in voltage calibration) unless:
|
May be better like this (opposite of nextSettingValue):
|
Ah yep good spot. |
When the UI was overhauled, and configuration settings changed to be handled more generically, an inconsistency in the usage of settings ranges became more obvious, and problematic.
The entire issue seems to stem from config settings having a range 'min <= value < max' which is programmatically sensible, instead of 'min <= value <= max' which is configuration sensible, yet both ranges are used interchangably throughout the code.
There is arguably reason to use either method, though I personally would support changing all ranges to 'min <= value <= max', as one shouldn't need to understand the subtleties of the code to tweak configuration values!
However, the following description assumes that 'min <= value < max' was the intended range for all config settings.
Reference: source/Core/Src/Settings.cpp
Config settings range 'min <= value < max' in these routines:
Config settings range from 'min <= value <= max' in these routines: INCONSISTENT
Reference: source/Core/BSP/*/configuration.h
All the values defined in */configuration.h are used to populate 'settingsConstants' as-is.
Weirdness: nextSettingValue()
There are two different conditions to determine if 'max - 1' was exceeded, when it would be logical to use the same condition (the first one would be my preference):
The text was updated successfully, but these errors were encountered: