-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Improve readability of main.cpp. #75548
base: master
Are you sure you want to change the base?
Conversation
1) Be consistent with spacing in if, else if, else blocks. Removed empty lines at the beginning and end. Previously, some blocks had no extra empty lines, while other blocks had one at the beginning, end, or both. 2) Add underscores to variable names like hasicon and iconpath. Other files used icon_path, so now main.cpp does the same. 3) Reduce the number of times OS::get_singleton() appears. Some functions like print_help() look less visually noisy. This helps the reader while skimming the source code. Added OS *os = OS::get_singleton(); to the eight functions that use the OS singleton. These functions were modified: print_help(const char *) test_setup() test_cleanup() setup(const char *, int, char * [], bool) setup2(Thread::ID) start() iteration() cleanup(bool)
} | ||
#endif | ||
|
||
String iconpath = GLOBAL_GET("application/config/icon"); | ||
if ((!iconpath.is_empty()) && (!hasicon)) { | ||
String icon_path = GLOBAL_GET("application/config/icon"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an underscore to some variables to be more consistent with the rest of the code base, which uses _ to separate words.
Nowhere else do we grab the singleton like this as far as I know (for other ones there are cases, like |
Thanks for opening a PR. This file is slated for a rewrite, because it is indeed very messy. I'm not convinced these changes help in the meantime. Some are arbitrary (like splitting a get singleton oneliner into two lines), and some make things less readable for such huge spaghetti methods (like removing a bunch of empty lines). |
E.g. in // 10 occurences:
RenderingServer *rs = RenderingServer::get_singleton();
// 9 occurences:
RenderingServer::get_singleton()->...
// 8 occurences:
RS::get_singleton()->... godot/servers/rendering_server.h Lines 1693 to 1694 in 21d080e
I mean it seems it's not well settled what's preferred (even within the same author). 🙃 Personally I don't mind |
My bad I didn't know the situation in |
@YuriSizov No problem. I view PRs as a way to start a conversation. I am happy to take on the rewrite of I am new to Godot engine, so I am reading the source code. I noticed that The singleton getter appears 243 times in this file, and replacing it with We are not really consistent with whether we save the singleton to a local variable. For example, in
Anyways, we can continue the conversation in this thread, but I can slowly improve main.cpp, piece by piece. Is that OK with you all? The first PR I could submit would be to rename some of the variables. I find Later on, we can extract some functions and reorganize the file. This would require lots of testing, since main.cpp has lots of branches, flags, and |
That's not how we approach things :) You can work on it, eventually, but it needs to be discussed first. Here, I can agree that the print command can be made a bit clearer. But then you also do this in a few places where the singleton is only accessed once. We don't normally split such lines, and if there is no consistent style, as kleonc points out, these changes are pretty arbitrary and are not really warranted by anything but personal taste. If it was done as a part of the general reorganization of the file, then great, that's not a big deal. But as a standalone PR it makes it low value. As for the refactoring itself, it needs a comprehensive proposal. Something that aggregates all the entrypoints, use cases, permutations that the file presents. There is quite a bit, so I'm not sure if you'd be well equipped to make such a proposal if you're only starting with the engine codebase. But of course, try by all means, we can polish it in the process. Don't want to discourage you, just want to point out that this is a pretty big undertaking. |
No problem. I am not easily discouraged. Thanks @Calinou for linking the other PRs. As we can see, many developers start with main.cpp and notice that it has some readability issues. This means that their first impression of Godot engine is not ideal. I feel like a huge refactor of main.cpp is risky and also is unlikely to be merged due to many stakeholders chiming in with competing opinions. Here is my suggestion:
Would starting with those two PRs help? I think it is much more likely that main.cpp improves slowly, like replacing pieces of the Ship of Theseus. A full refactor in one PR would probably not be merged without intense discussion and agreement across all the main stakeholders. |
Be consistent with spacing in
if
,else if
,else
blocks.Removed empty lines at the beginning and end.
Previously, some blocks had no extra empty lines, while other blocks
had one at the beginning, end, or both.
Add underscores to variable names like
hasicon
andiconpath
.Other files used
icon_path
, so now main.cpp does the same.Reduce the number of times OS::get_singleton() appears.
Some functions like print_help() look less visually noisy. This helps
the reader while skimming the source code.
Added
OS *os = OS::get_singleton();
to the eight functions that use theOS singleton. These functions were modified: