-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
C++ Namespace layout #6086
Comments
Each time this was proposed in the past, I've been an opponent. I've always felt that it proposes inflation to the code for what I would consider a small chance of necessity and a 0% chance of re-usability. I believed it should be on the 3rd-party libraries to namespace, since LMMS isn't reused in other projects or used as a library elsewhere, I'd felt (historically) it was unwarranted and should become an upstream bug when this occurs, not ours.
This above, all over the codebase (or even worse, the That said, its our developer time that suffers when these crashes occur and I don't actively maintain the C++ portions of the code, nor do I actively maintain any medium or large C++ projects in general, so my opinion is simply that and the pros and cons explained by the OP should we weighed greater by those writing the code. 🍻 That said, this has been requested a lot. Related: LMMS/zynaddsubfx#16, quoting Dom:
|
Agreed. namespacing is the task of library vendors, but unfortunately not all libraries do it, so implementing it clientside can act as a mitigation for current name clashes and as a precaution for dependencies we might add in the future. Regarding granularity as in the |
Adding namespaces to avoid collisions seems like a good idea to me, but the suggested structure feels a bit too complex. Do we really need separate namespaces for audio, midi and lv2? And is there any benefit to nesting it like I would personally go just with |
Yes. If you want to use the Mixer in GUI code, in one case, you use This also means that e.g. Lv2 types can reference other Lv2 types without naming their namespace, which means the code itself will get shorter (all "Lv2" prefixes will wanish). Though... if you read Lv2 code referencing |
This is something I believe LMMS could benefit from working towards. |
Nested namespaces aren't really efficient in C++ from my experience. |
I think the main thing to keep in mind there is that C++ namespaces are not packages like in Java or C#; there is no such thing as "namespace visibility" and you can't export or import namespaces. They only exist to avoid name collisions, and thus should be used to achieve this goal without burdening client code too much. namespace lmms{
// Everything lives here
namespace gui{
// The only nested namespace. GUI elements live here.
}
} That way, all LMMS symbols can just refer to each other without the |
I like this variant better than my original suggestion; it gets the job done, it's shorter, gets out of the way most of the time, and still achieves the core / GUI separation. Thumbs up. |
At least, it makes it harder to use |
What should we do for plugins? Some options:
Long namespace names aren't as much of a concern here since most plugins aren't referenced elsewhere in the code. Also, plugins have core and GUI components too. Should these go in separate namespaces? |
Another question that needs to be cleared up: For UI widgets following MVC patterns, there's multiple classes involved; |
Regarding this question, I would generally advise against nesting namespaces too much, so I'd argue for the |
I thought we agreed on using only a minimal amount of namespaces, |
In theory, there could be a different GUI accessing the same models (in practice, very unlikely?). If we introduce Minimizing complication sounds best to me, too, whatever the solution is. |
@irrenhaus3 Is anything blocking you with this? It's a useful PR and is theoretically on the re-org list (though we agreed we can skip it). |
I'm available to solve the merge conflicts if that's the only thing needed to get this PR through... |
Btw, this is just the issue. The real PR is actually here: #6174 . |
About the whole discussion of I think this is really easily done with a simple shell/python script. Pseudo code:
Also, I don't see issues like with "using" here, if you do it like above. Let's say you have What do others think? Do you see any risks in this approach? |
Just a reminder: |
What's the deal with namespacing
The only reason I see for a // core.h
class Model {}; // This class got introduced in core some time after the plugin was written
// old_plugin.h
#import <core>
class Model {}; // Error: redefinition of Model Plugins shouldn't include symbols from other plugins, so there should be no need for things like |
This could be a good motivation for Although I'm not sure how well all plugins are separated into core/gui right now. It could be quite tedious to do this separation. |
After thinking about it I don't see a point for The purpose of the |
hasn't the pr been merged? |
It doesn't mean that the issue is done though. |
What is left to do with this issue ? |
I've the same question as @luzpaz, this is the last thing in "Reorg", might as well finish it. |
The current namespacing seems sufficient to me - there's an overall |
Part of the big LMMS refactor is to set up C++ namespaces for LMMS' symbols, to avoid potential name clashes with its dependencies (which has already happened with ZynAddSubFX). My first quick proposal for a namespace layout guided by LMMS' current directory structure went as follows:
with some symbol name changes such as
MixerWorkerThread -> lmms::mixer::WorkerThread
.This is only a draft and open for discussion; the main points to consider here are:
std::vector
vs.std::chrono::steady_clock
) and leads to an increase inusing
-declarations (orusing namespace
, which can be easily mis-used).Also, this is not a very important remark right now, but at some point in the future, C++20's Modules feature might be desirable; and since namespaces and Modules are orthogonal to each other, mixing the two can complicate the codebase. Kind of a reiteration of the first point here: If namespaces are set up to effectively group logical modules together, a potential future refactor into C++20 Modules becomes a great deal easier.
Discussion, GO!
The text was updated successfully, but these errors were encountered: