-
Notifications
You must be signed in to change notification settings - Fork 66
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
Split mobiflight.cpp into multiple files #148
Comments
I absolutely subscribe to this idea. In the weekend I'll have a look, but I'm confident of your judgment. |
I would love this. It will reduce the chance of merge conflicts when people are working on different parts of the firmware at the same time. Instead of adding additional files can we move the methods to static methods on the associated classes? Then everything for analog would live in MFAnalog, everything for output would live in MFOutput, etc. (I don't know if this would actually work, just wondering if it is possible) |
@neilenns This was exactly the point where I was unsure and thought about a couple of days. In the end I came up to move it into separate files because I treated the classes as a kind of "library" and that I was unsure if this will work to have the existing functions in the files for the classes (in the mean time a saw it this way in another project). This weekend I could set it up e.g. for the analogIn in this way to see how it works / look like to evaluate if this makes more sense. |
If static methods work the advantage would be everything about each module type would live in one place. We'd never have to go "wait, is that method in output.cpp or MFOutput.cpp? 🤔" |
I agree with @neilenns , in fact, that's exactly one of the first thoughts that came through my mind as I went to browse the code. |
OK, I have had a look and I'm ready to give you my 2cent feedback. First of all, full thumbs up for the code split, but I think that was already settled. About the alternative to join all code pertaining to a device vs having two distinct files (i.e. " Although I initially agreed with @neilenns 's proposal, which is appealing since it would be great to have a single file (of reasonable size) for each device, on second thought I would rather dismiss that as logically incorrect (therefore misleading). While the "MFButton" file holds the code for the "button" object itself, the "button.cpp" part is purely client code, which should be decoupled from the device class; even more so, it has very little reason to be part of the class as static methods. Bottom line, I would definitely keep the two files separate, maybe slightly changing some naming if it helps (e.g. "button.cpp" in ".\inputs" rather that ".\MFinputs" etc). |
One way I've handled this in the past is to put Add-style methods into a static Unfortunately I'm not sure that really makes things much better, as it would just move the bulk of the length of mobiflight.cpp into another file that would also be quite long? |
@neilenns 101% agree. In order to keep things most manageable, one could have e.g. two classes as Beside that (and I did not want to go that far for fear of digressing), it would be a good step towards a full objectification of the code. |
@neilenns and @GioCC thanks for your comments! Just for my understanding (I am not soo familiar with the wording :( ), setting up two classes would mean e.g. for the inputs: Due to my less experience I am wondering, if
These are really serious questions from my side to get a better understanding due to my leck of experience. To have a file per device with the static functions and the classes included seems for me the best way for now in regard of flexibility, seperating the devices and getting a good overview (I set it up accordingly for the MFAnalog in my branch). |
I would do the managers as fully static classes so they don't require memory allocation and wouldn't have a constructor. I'll take a peek later today and mock up and example. I'm not at all sure it is a good approach 😂 |
Hoping to be on topic with what you ask, this would be my answers:
At the risk of being annoying, let me advocate again that my preference would definitely go towards keeping the actual device classes separated from the client "stub" functions; these latter can then be grouped in two "inputMgr"/"OutputMgr" files (quite regardless whether C or C++), but even individual files would be ok if that is deemed more convenient. |
Yup. And in my mind the only advantage to the static class is making it clear when those functions are called where they're coming from instead of just being random functions that magically somehow work. Of course that could also be accomplished with a namespace instead of a static class... |
Also true! |
@GioCC @neilenns thanks again for your comments. I will try to summarize the comments and to see, if I have understood everything correct.
That means at least to get a common proposel we have to decide if we stay with the existing C functions (don't they have already a namespace*?) or to move them to static libraries. It would be great if @MobiFlight-Admin could comment on this too. *) I am afraid that I do not have the same understanding (or knowledge) of the definition of a namespace. My understanding is that all functions shoud have the same syntax and it should be clear what the functions for which device does. For me this is fullfilled (except less minor naming differences) for the existing naming. |
That would be a defined scenario; I, personally, would be fully satisfied with that. |
OK, thanks for the big support from @GioCC! |
@elral Do you have a branch for it? Where? :D |
@neilenns yes, in my first post is the link. Once everything is "done" I will issue a pull request. |
@elral Did you push your latest changes? https://github.com/elral/MobiFlight-FirmwareSource/tree/multiple_files still has individual files like you originally had, I don't see namespaces for it. |
@neilenns I "just" did it for the input devices, outputs will be done when it goes into the correct direction |
Ah, I see it now. This wasn't quite what I was thinking. I was thinking there would just be a single As done now it really feels odd. There's no advantage to a single file with a bunch of namespaces in it, it just makes yet another big file which is what we're trying to get away from. And the namespaces being called |
@neilenns sorry this time I have to disagree (on one point). Whatever form they take, those methods have no business being attached as part of the MF_xxxx classes... I believe this is the one thing, if any, we have to stay away from. |
Yeah, I'm fine with that, I'm just saying the current namespace example isn't any better than what we have now. Maybe separate files + namespace is the answer? |
Why not? Albeit debatable, I still find it better (smaller files, but not as dispersed as all separate files). Right now, I'm fighting hard to keep myself from trying to undertake a more thorough (but sensible) refactoring... and I know that I will lose against myself. With that perspective, this solution (or an equivalent one) would be already a step in the right direction, but I admit that it's something that's only in my mind for now. |
It's still a large file and has multiple things in it that don't really have anything to do with each other. Something about a single source file with that many namespaces in it too just feels... wrong. If I want to go make a change to one of those methods I'm still opening a huge file and having to ctrl+F to find what I need. The thing I didn't like about single files was how the functions would just magically appear. Putting a namespace around the stuff in single files would solve that issue and give a matching structure to the existing |
Well, not that large a file, considering it's still a fraction of the one that we wanted to split in the first place... but I see your point. |
That would also my preferred solution. I like it more to have "multiple" flles instead of one big file, for me it's easier to know which file to open instead of searching in a big file. It gives also the possibility to use different inlude paths if a device should be included or excluded (instead of defines and encapsulating in the file, but (maybe?) more stuff in platformio.ini). |
Good then, looks like we finally have a solution! :D |
It's not pointless, it saves having to prefix all the function names with |
How is it different from prefixing them with |
Puuuh, changed everything from the inputs back to multiple files w/ namespace and added namespace for the outputs. There are no more dependecies directly between the devices. Some failures from merging the outputshifters (renaming) are also corrected. What I also saw: |
Hey cool! it is a lot better!!!! GREAT JOB. Idea: Can we not bundle the MFButton.cpp and Button.cpp together in one directory and get rid of the MFModules folder and use MF Analog, MFButton, etc, instead? This way we would have both cpp-files in one place. I would even put the h-file there, but i think it is a platformio thing that they have to reside in libs? I don't understand the specfic reason for splitting it up in MF_Inputs and MF_Outputs. |
For the folders there were only the reason that not all files should be on the same order and to group them. @DocMoebiuz I guess your proposal goes into the same direction I mentioned aboved.
This would mean for every device one folder with the required files (e.g. Analog.cpp, MFAnalog.cpp and their .h files). Within platformio.ini it will be defined which folder has to be used (which works also for the .h files, they must not be in |
I personally don't think is a good idea. One folder per device would mean an awful fragmentation, with the result that navigating the source would be even worse than the situation we started from in the first place. Also, conditional compilation by "hiding" folders wold not be a good idea either:
|
No, it can be definitely done - I usually find it much better that way, unless there are really lots of files (but even in that case, I split file groups keeping .c/cpp and .h/hpp together). |
I took a peek at the pull request and the general structure makes sense to me. It does look like the pull request incorporates a lot of other changes beyond this splitting into multiple files though. I see switches to using |
Oh sorry, maybe I did too much :( Just one question, which part do you mean with "setting the last button press time"? |
Ultimately it's up to @DocMoebiuz, but personally I prefer pull requests that are "single subject". It has several advantages:
|
* Split mobiflight.cpp into multiple files Fixes #148
@MobiFlight-Admin @neilenns @GioCC
During creating the last pull request it was some kind of "difficult" to keep the overview in mobiflight.cpp. A lot of scrolling through the file was required to find all related parts of the code.
PlatformIO has better capabilities to use multiple files than the Arduino IDE, and discussions in the past shows that all of us agree to split mobiflight.cpp into severall files.
@neilenns has done this already by setting up an additional file where all devices and other parts are set up in a class, I did it in the past not using classes but single files for each "functional group".
I will add an example of the file structure I have setup, but this should not mean that my proposal should be implementes. It is mean as a starting point to discuss how to split mobilflight.cpp and to habe an issue to keep track on this topic.
If one would like to have a deeper look into the file structure and the files itself, see my branch https://github.com/elral/MobiFlight-FirmwareSource/tree/multiple_files
The text was updated successfully, but these errors were encountered: