question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve code readability by simplifying debug logging

See original GitHub issue

In 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 the Log._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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:23 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
dymanoidcommented, Jul 19, 2019

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.

2reactions
dymanoidcommented, Jul 18, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found