Ayende @ Rahien

Hi!
My name is Ayende Rahien
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

@

Posts: 5,947 | Comments: 44,541

filter by tags archive

Comments

Paul Stovell

One subject in basic pure math that I wish all developers would take is factorization - taking an equation, recognising and removing the duplicates and simplifying.

I still can't fathom how a developer can see the same thing over and over again - like 6 lines of code repeated every single time an exception needs to be logged - and not recognize that they can factor it out.

Paul

Grimace of Despair

"Using a naming convention where the company name is prefixed to all local variables"

I've witnessed a Database that was prefixed with the DEVELOPERS initials, as were all tables in it...

I still shiver while writing this.

Markus Zywitza
  
try
  
{
  
	ActiveRecordMediator.Save(foo);
  
}
  
catch (Exception ex)
  
{
  
	Logger.WarnFormat(ex, "Error saving Foo {0}", foo.Name);
  
	while (ex.InnerException != null)
  
	{
  
		ex = ex.InnerException;
  
		Logger.Info("Inner Exception", ex);
  
	}
  
}
  

If you count the brace lines, it's 6 lines for the exception, too. But absolute necessary unless

Castle.ActiveRecord.Framework.ActiveRecordException: Could not perform Save for Foo at ... in ...

is enough for you to see the error's cause, which isn't the case for me.

Ayende Rahien

Markus, is there a reason that you are doing it this way?

ex.ToString() gives you the inner exception as well, after all

Markus Zywitza

Hmm, it seems that the fact that I always use Logging now avenges. Perhaps I should have just used

Console.WriteLine(exception)

:-(

Markus Zywitza

What is Logging?

No special product, I simply wrote it with a capital letter because I'm accustomed to that practice. German language capitalizes all nouns, hence "Logging" instead of logging.

Ayende Rahien

Well, most of the logging frameworks that I am aware of will handle this correctly.

Markus Zywitza

Windsor's LoggingFacility with loggingApi="console" obviously doesn't.

Paul Stovell

@Markus:

class LogHelper

{

public static void Warn(Exception ex, string format, params object[] args) 

{

Logger.WarnFormat(ex, format, args);

while (ex.InnerException != null)

{

ex = ex.InnerException;

Logger.Info("Inner Exception", ex);

}

}

}

Now in the many places you use that code, you can have:

try

{

ActiveRecordMediator.Save(foo);

}

catch (Exception ex)

{

LogHelper.Log("Error saving Foo {0}", foo.Name, ex);

}

}

There are thousands of libraries which require multiple lines to do something. There's no reason you should write those multiple lines twice.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  2. The RavenDB Comic Strip (2):
    20 May 2015 - Part II – a team in trouble!
  3. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  4. Interview question (2):
    30 Mar 2015 - fix the index
  5. Excerpts from the RavenDB Performance team report (20):
    20 Feb 2015 - Optimizing Compare – The circle of life (a post-mortem)
View all series

RECENT COMMENTS

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats