Repository navigation
Polymorphic ruler version 3 - #3257
Paul-Licameli wants to merge 17 commits into
Conversation
There was a problem hiding this comment.
All uses of SetUseZoomInfo are gone in this commit, replaced with this better, more general thing. Good! But then, don't leave behind a code comment referring to a nonexistent function. Say it in the commit comment.
There was a problem hiding this comment.
Make a separate commit just for this one line.
There was a problem hiding this comment.
Here and below, *mRuler is the simpler equivalent expression. I'm reviewing the first commit, but I think you fixed this in a later one. Good, but then do it in the first commit.
There was a problem hiding this comment.
Your own name!
Or as I often leave it, when splitting up legacy code into smaller files:
Dominic Mazzoni
Michael Papadopoulos split from Updater.h
There was a problem hiding this comment.
Do you want to rename the class (and file) as RulerUpdater?
There was a problem hiding this comment.
I will change it to RulerUpdater and I'll update the credits when I do. No rush to change it.
There was a problem hiding this comment.
I like that you added const wherever possible for member functions of Updater and its nested types.
Can you use even more const ? ...
There was a problem hiding this comment.
You ignore the argument z and always pass NULL (which should be nullptr to observe more modern C++ style).
Is that a mistake, or is z really not needed? If the latter, then omit it from the argument list.
There was a problem hiding this comment.
How can we avoid the friend declarations, and mention of higher level things?
There was a problem hiding this comment.
We had a long talk about just that, didn't we... I need to see the later commits
There was a problem hiding this comment.
I see two overloads of SetUpdater. Can they be collapsed into one, by use of a default argument for leftOffset?
Yes: you might pass int* not int and default the argument to nullptr
But better than that -- avoiding funny looking function declarations that might leave the reviewer with doubts about lifetime questions -- you can make the intent even clearer by passing std::optional<int> around, by-value.
There was a problem hiding this comment.
I have never heard of std::optional<>. I will look into it.
There was a problem hiding this comment.
I see that the second commit corrects several things I found doubtful in the first commit.
Good to correct them: but better not to introduce them though at any point in the history.
Maybe the first two commits should be squashed (after rebbasing on a separate small commit for AudacityHeaders.h)
But then, make the separate, and prior, commit to define RulerStruct with all necessary changes in Ruler.cpp. And then, rebase all onto that.
This will present a more reviewable sequence of changes. Ruler.cpp will make a lot of necessary, "noisy" changes in a prior commit that is mostly just the noise.
Then the later commit separates the "noise" from the more interesting structural change.
There was a problem hiding this comment.
The second commit introduces RulerStruct and this constructor.
This constructor has many assignments in it.
It's better C++ style (since 1998) to prefer member initialization where possible over assignments in the constructor body, for instance:
RulerStruct::RulerStruct()
: mMin(0.0)
{
But since C++11, it's even better to prefer the "uniform initialization" syntax (curly braces) where possible:
RulerStruct::RulerStruct()
: mMin{ 0.0 }
{
-- among other things, this disallows implicit narrowing convertions (as from float to integer).
But, also in C++11, and better still where it applies: use in-class initialization. That is, in Updater.h, declare the member as:
double mMin = 0.0;
or better
double mMin{ 0.0 };
or, even:
double mMin{};
Because 0 is the default value for all kinds of number types.
Any of those is better than
double mMin;
which implies no initialization.
When I review a class to understand it better, I want to start with the header file. If I see in-class initializers, I don't have to read the constructor definitions to have confidence that members are never left uninitialized by mistake. Rather I know that they default reasonably. And then when I do read the constructor, it's a shorter constructor.
Only when there is no reasonable, argument-independent default for a member -- then, leave it without an initializer. But then, I know that I must read the constructor body to understand fully what the member is for.
There was a problem hiding this comment.
I confirm that at the second commit, you do not introduce dependency cycles among sourc code files. 👍
There was a problem hiding this comment.
The third commit corrects the omission of the virtual destructor. Good: but, logically this should be squashed with the same commit that introduces
std::unique_ptr<Updater> mpUpdater;
in Ruler.h, so the known mistake of missing default constructors is never even introduced into the commit history.
Besides that, I recommend:
- Define all of the destructors in this commit as non-inline, not only the one for Updater
- You can use the C++11 alternative syntax:
Updater::~Updater() = default - Also, now that I think of this too: when you introduce the subclasses of
Updater, make themfinalif possible, e.g.struct LinearUpdater final : public Updater { ...this means: you do not intend further subclassing of those classes.
What are my reasons for these practices?
- A linker has to put the virtual function table for each class in some unique place, and often implemented to follow this rule: the .cpp file definining the first non-inline virtual function generates the object file in which the table will live. But, if there is no non-inline virtual function, then the compiler has to fall back on generating multiple copies of the virtual function table that the linker just eliminates later. Moral: be nice to your linker, and avoid in-line virtuals.
- in-line optimization is inherently incompatible with virtual function dispatch anyway, so why declare the functions inline anyway ? ...
- ... except: when a class is
final, and the declared object is of the leaf-class type, then the compiler can know that it really can to do the inline optimization, avoiding virtual function dispatch. Better to usefinaland let a smart compiler find the inlining opportunities.
There was a problem hiding this comment.
The fourth commit splits RulerPanel from Ruler.
Observe that including Ruler.h in RulerPanel.h is unavoidable, because there is a nested Ruler object.
Ok then -- but that means the transitive inclusion of Ruler.h happens whever RulerPanel.h is included.
There are four such inclusions, including that in RulerPanel.cpp. I suggest then you simplify the lists of #inlude directives in each place.
There was a problem hiding this comment.
The fifth commit moves this function.
I'd rather just squash that into the commit that introduces class Updater. It's not recommended to have the non-inline definitions of a class's member functions in more than one file: so, avoid putting things into this state to begin with.
There was a problem hiding this comment.
The last commit, too, might as well be squashed onto the commit that introduces Updater.
Rework update so that it is polymorphic. Break it into multiple files and allow the ruler's creator to set the updater with a unique pointer creator.
be122e6 to
d5d0b36
Compare
There was a problem hiding this comment.
typo: "correct"
There was a problem hiding this comment.
Reviewing the first again, I see the Ruler::mUseZoomInfo becomes unused at the first commit. Reassigned in Ruler::SetUpdater but not used elsewhere for anything. So eliminate it.
There was a problem hiding this comment.
Reviewing the commit "Remove circular dependencies..." which moves fields into the new type RulerStruct -- I see that the member mLeftOffset is never initialized.
A later commit removes the constructor in favor of in-class initializers, which is all right, but still does not correct this.
The remaining fields without in-class initializers are all right to remain so, because they are not primitive types. So their default constructors are implicitly invoked. You could write {} to initialize each but it isn't needed and makes no difference in compiled code. I omit such initializers myself in such cases.
There was a problem hiding this comment.
The comment is incorrect about the purpose of the inclusion
There was a problem hiding this comment.
The commit that separates RulerPanel.cpp can also remove this #include which becomes unnecessary.
There was a problem hiding this comment.
This changed line should be preceded by an i18n-hint comment explaining that "amp" abbreviates "amplitude".
Those comments matter because xgettext extracts them to locale/audacity.pot when we update that file, at least once in each development cycle. Then the comments are copied to the several locale/*.po files, and serve as clues for the volunteer translators who update the string catalogs for other languages.
There was a problem hiding this comment.
See scripts/update_po_files.sh if you are curious about that process.
Create the virtual destructor for updater Remove circular dependencies of Updater and Ruler Streamline the dependencies of Updater and Ruler. Extract all necessary data for Updater functions down to Updater, and rework ruler calls to use this format. This allows Updater to be independent of Ruler.
Separates Ruler from RulerPanel to reduce unnecessary importing.
To be squashed into a past commit
Properly implements Custom functions and uses the LinearDb ruler as a space to test it.
98ce83b to
e9fc442
Compare
Imports an old change for GSoC to separate the units of a label from its text so different fonts can be used for each.
A basic start on making dB ruler functional for all settings. Will proceed more when design is discussed.
Resolves: (direct link to the issue)
(short description of the changes and the motivation to make the changes)
Recommended: