Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,954 | Comments: 44,412

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

  1. What is new in RavenDB 3.5–Intro - 18 hours from now

There are posts all the way to Jul 08, 2015

RECENT SERIES

  1. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
  2. Special Offer (2):
    27 May 2015 - 29% discount for all our products
  3. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  4. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  5. Interview question (2):
    30 Mar 2015 - fix the index
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats