Improve code readability by simplifying debug logging
See original GitHub issueIn the current code, there are a lot of such constructs:
#if DEBUG
if (debug)
Log._Debug("Whatever");
#endif
They are sometimes repeated very often, after each line (e.g. JunctionRestrictionsManager.cs
).
It’s almost impossible to read and to understand code like that.
Suggested improvements:
- The
Log._Debug
method already has the[Conditional("DEBUG")]
attribute, so no need in#if DEBUG / #endif
region at all - The
if (debug)
check can actually be transferred into theLog._Debug
method
After those improvements, the logging code becomes as simple as that:
Log._Debug("Whatever");
It will make the code much more readable and won’t affect performance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:23 (17 by maintainers)
Top Results From Across the Web
How to insert logging information without making the code ...
Counterintuitively, logging can lower readability. You've stumbled on a key issue here. Logging can inject orthogonal incentives for code ...
Read more >Code to logging ratio? [closed]
I have found that in all reality, many user applications don't need large amounts of logging, as really if issues come up you...
Read more >Here is one thing you can do to improve your project ...
Working on such types of projects, here's what I found. Replacing the comments with loggers is more effective. Not only can you read...
Read more >How do you test and debug your error handling ...
The fourth step is to use a debugger and a log analyzer to test and debug your error handling and logging code. A...
Read more >4 Tips for Improving Code Readability
4 Tips for Improving Code Readability · 1. Removing Boilerplate Code · 2. Formatting Indentation & Spacing · 3. Selecting Appropriate Names ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, by “never” I mean not literally “not a single time in your life time” but rather “you can really go without it, and if not, then you surely know what you are doing”.
20 bytes for x86 and 24 bytes for x64 are the struct sizes where the jitter decides to switch from simple and fast CPU instructions (cheap copying) to a loop (expensive copying). Cheap copying is almost as fast as accessing by-reference.
Rule of thumb: don’t use
in
. If you still want to use it, see rule of thumb. Please read this SO question and the two most upvoted answers.string.Format
is even slower than string concatenation. Better to avoid both whenever possible.