Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Balancing Logging and Code Readability

by kwaping (Priest)
on Sep 14, 2009 at 23:59 UTC ( #795246=note: print w/replies, xml ) Need Help??

in reply to Balancing Logging and Code Readability

I think you've hit upon a very basic dilemma that most, if not all, good programmers have. I know that issue is something I struggle with as well.

My solution to the problem has been two-fold:
  1. I make sure that the first thing on the line is the "important" code.
  2. I sometimes line-break then indent my logging code, to further emphasize its subordinate status.

Here's an example:
# bad log("This code is broken!") unless $obj->method_call(arg1 => 'abc', ar +g2 => 123); # good $obj->method_call(arg1 => 'abc', arg2 => 123) or log("This code is broken!");
I'm not saying my way is the One True Way, but that's what I do and it works for me.

It's all fine and dandy until someone has to look at the code.

Replies are listed 'Best First'.
Re^2: Balancing Logging and Code Readability
by ack (Deacon) on Sep 17, 2009 at 02:22 UTC

    I have been thinking about a similar approach. I think mine is a bit more drastic (probalby unnecessarily so). I had thought about moving all of my logging invocations over to the right side of the code margins so that they are drastically dislocated from the code. I was thinking that it would give a more visual continuity to the code distinctly separate and different from the logging.

    I haven't tried it yet. I thought I'd take one of my more lengthy scripts and try it out just to see how it looks visually.

    Your reflection upon your strategy gives me additional motivation to look into trying this strategy, too.

    As I think about the dilema, I am feeling a strong sense that putting most all of these suggestions together as an overall strategy could be an excellent solution to my challenge. everyone!

    ack Albuquerque, NM
      I'm interested to see what your final strategy is. Please keep us updated!

      It's all fine and dandy until someone has to look at the code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://795246]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2023-03-31 02:30 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (74 votes). Check out past polls.