Oren Eini

aka Ayende Rahien

Oren Eini

CEO of RavenDB

a NoSQL Open Source Document Database

Get in touch with me:

oren@ravendb.net +972 52-548-6969

Posts: 7,575
|
Comments: 51,188

Copyright ©️ Ayende Rahien 2004 — 2025

Privacy Policy · Terms
filter by tags archive
stack view grid view
  • architecture (606) rss
  • bugs (450) rss
  • challanges (123) rss
  • community (377) rss
  • databases (481) rss
  • design (893) rss
  • development (640) rss
  • hibernating-practices (71) rss
  • miscellaneous (592) rss
  • performance (397) rss
  • programming (1085) rss
  • raven (1442) rss
  • ravendb.net (526) rss
  • reviews (184) rss
  • 2025
    • May (7)
    • April (10)
    • March (10)
    • February (7)
    • January (12)
  • 2024
    • December (3)
    • November (2)
    • October (1)
    • September (3)
    • August (5)
    • July (10)
    • June (4)
    • May (6)
    • April (2)
    • March (8)
    • February (2)
    • January (14)
  • 2023
    • December (4)
    • October (4)
    • September (6)
    • August (12)
    • July (5)
    • June (15)
    • May (3)
    • April (11)
    • March (5)
    • February (5)
    • January (8)
  • 2022
    • December (5)
    • November (7)
    • October (7)
    • September (9)
    • August (10)
    • July (15)
    • June (12)
    • May (9)
    • April (14)
    • March (15)
    • February (13)
    • January (16)
  • 2021
    • December (23)
    • November (20)
    • October (16)
    • September (6)
    • August (16)
    • July (11)
    • June (16)
    • May (4)
    • April (10)
    • March (11)
    • February (15)
    • January (14)
  • 2020
    • December (10)
    • November (13)
    • October (15)
    • September (6)
    • August (9)
    • July (9)
    • June (17)
    • May (15)
    • April (14)
    • March (21)
    • February (16)
    • January (13)
  • 2019
    • December (17)
    • November (14)
    • October (16)
    • September (10)
    • August (8)
    • July (16)
    • June (11)
    • May (13)
    • April (18)
    • March (12)
    • February (19)
    • January (23)
  • 2018
    • December (15)
    • November (14)
    • October (19)
    • September (18)
    • August (23)
    • July (20)
    • June (20)
    • May (23)
    • April (15)
    • March (23)
    • February (19)
    • January (23)
  • 2017
    • December (21)
    • November (24)
    • October (22)
    • September (21)
    • August (23)
    • July (21)
    • June (24)
    • May (21)
    • April (21)
    • March (23)
    • February (20)
    • January (23)
  • 2016
    • December (17)
    • November (18)
    • October (22)
    • September (18)
    • August (23)
    • July (22)
    • June (17)
    • May (24)
    • April (16)
    • March (16)
    • February (21)
    • January (21)
  • 2015
    • December (5)
    • November (10)
    • October (9)
    • September (17)
    • August (20)
    • July (17)
    • June (4)
    • May (12)
    • April (9)
    • March (8)
    • February (25)
    • January (17)
  • 2014
    • December (22)
    • November (19)
    • October (21)
    • September (37)
    • August (24)
    • July (23)
    • June (13)
    • May (19)
    • April (24)
    • March (23)
    • February (21)
    • January (24)
  • 2013
    • December (23)
    • November (29)
    • October (27)
    • September (26)
    • August (24)
    • July (24)
    • June (23)
    • May (25)
    • April (26)
    • March (24)
    • February (24)
    • January (21)
  • 2012
    • December (19)
    • November (22)
    • October (27)
    • September (24)
    • August (30)
    • July (23)
    • June (25)
    • May (23)
    • April (25)
    • March (25)
    • February (28)
    • January (24)
  • 2011
    • December (17)
    • November (14)
    • October (24)
    • September (28)
    • August (27)
    • July (30)
    • June (19)
    • May (16)
    • April (30)
    • March (23)
    • February (11)
    • January (26)
  • 2010
    • December (29)
    • November (28)
    • October (35)
    • September (33)
    • August (44)
    • July (17)
    • June (20)
    • May (53)
    • April (29)
    • March (35)
    • February (33)
    • January (36)
  • 2009
    • December (37)
    • November (35)
    • October (53)
    • September (60)
    • August (66)
    • July (29)
    • June (24)
    • May (52)
    • April (63)
    • March (35)
    • February (53)
    • January (50)
  • 2008
    • December (58)
    • November (65)
    • October (46)
    • September (48)
    • August (96)
    • July (87)
    • June (45)
    • May (51)
    • April (52)
    • March (70)
    • February (43)
    • January (49)
  • 2007
    • December (100)
    • November (52)
    • October (109)
    • September (68)
    • August (80)
    • July (56)
    • June (150)
    • May (115)
    • April (73)
    • March (124)
    • February (102)
    • January (68)
  • 2006
    • December (95)
    • November (53)
    • October (120)
    • September (57)
    • August (88)
    • July (54)
    • June (103)
    • May (89)
    • April (84)
    • March (143)
    • February (78)
    • January (64)
  • 2005
    • December (70)
    • November (97)
    • October (91)
    • September (61)
    • August (74)
    • July (92)
    • June (100)
    • May (53)
    • April (42)
    • March (41)
    • February (84)
    • January (31)
  • 2004
    • December (49)
    • November (26)
    • October (26)
    • September (6)
    • April (10)
Deep Dive into RavenDB webinars
  previous post next post  
Apr 13 2009

There are so many things wrong with this code…

time to read 1 min | 26 words

I just want to cry:

image

Tweet Share Share 57 comments
Tags:
  • WTF?!

  previous post next post  

Comments

justin
13 Apr 2009
21:03 PM
justin

lol that's hilarious

Peter
13 Apr 2009
21:07 PM
Peter

Lol thats too funny, or to put it into terms the original author would recognize.

try

{

  LearnFromArticle();

}

catch (AuthorIsAnIdiotException ex)

{

 throw new  SackableOffenceException(ex);

}

lol

Laurion Burchall
13 Apr 2009
21:53 PM
Laurion Burchall

At least the exception is being rethrown! ;-)

Brian
13 Apr 2009
21:53 PM
Brian

Beautiful!

Jimmy Zimmerman
13 Apr 2009
21:53 PM
Jimmy Zimmerman

Is it wrong that I started laughing out loud when I read this?

OH WAIT. NO. This person's an idiot.

meisinger
13 Apr 2009
21:55 PM
meisinger

first off... i am surprised that this isn't a generic function (just think of the potential boxing and unboxing performance issues)

as far as i am concerned... you can't get any deeper than this type of "deep copy"

at least the author is using the Single Responsibility principle by calling this method from the Assemble and Disassemble methods

Ayende Rahien
13 Apr 2009
21:59 PM
Ayende Rahien

No, the exception is NOT being REthrown.

It is being _thrown_.

Seeing that is a BIG WTF sign in most cases.

Pop Catalin
13 Apr 2009
22:05 PM
Pop Catalin

Oh my %$%@ god, I can't believe I saw what I saw on that article!!! And the author even has a screenshot with a unhandled application exception O_O.

Microsoft should make FxCop and StyleCop mandatory and include it in every VS version including Express, they would do a great favor to humanity, by eliminating whole classes of "stupid" coding mistakes. Not that will be enough ... but ... still ...

This is enough to make a grown man cry ...

Dmitry
13 Apr 2009
22:08 PM
Dmitry

Wow! Everything is wrong with this code starting from the name and ending with exception handling.

Ayende Rahien
13 Apr 2009
22:09 PM
Ayende Rahien

Pop,

The exception dialog make sense, he is showing that the concurrency strategy works.

Vince
13 Apr 2009
22:13 PM
Vince

haha, the proper "rethrow" should be:

catch(Exception ex){

throw;

}

João P. Bragança
13 Apr 2009
22:14 PM
João P. Bragança

This is reassuring! If this is the quality of the code base coming out of East Asia I think we're gonna have job security for quite some time.

Dmitry
13 Apr 2009
22:15 PM
Dmitry

@Vince,

I would not call you example proper as well. A proper re-throw could be:

catch (SqlException)

{ throw; }

catch (Exception ex)

{

// handle ex

}

Rethrowing a general System.Exception is pointless.

Dmitry
13 Apr 2009
22:16 PM
Dmitry

Something like this would be valid as well:

catch (Exception ex)

{

// handle ex

throw;

}

zihotki
13 Apr 2009
22:21 PM
zihotki

Really great article!!! Every time when I'll be in a sad mood I'll read it!

Pop Catalin
13 Apr 2009
22:25 PM
Pop Catalin

Pop, The exception dialog make sense, he is showing that the concurrency strategy works.

Yes, but what I was finding funny in this, is that he has catch blocks all over, without doing anything (except eating stacktrace info), and the only place where he should have cough a expected exception, (the point of the article) he didn't.

Rory Primrose
13 Apr 2009
22:39 PM
Rory Primrose

LOL, that is fantastic. I haven't laughed at code that quickly in ages (it's normally crying).

So I guess it's a deep copy of a memory pointer. Maybe that's what the author intended.... :P

Igor Ostrovsky
13 Apr 2009
23:09 PM
Igor Ostrovsky

@Ayende, Vince, Dmitry:

Thrown or rethrown... does it even matter? It is dead code anyways, as "return value" cannot possibly throw an exception.

Or am I missing something?

Dmitry
13 Apr 2009
23:13 PM
Dmitry

@Igor,

Click the article link. He uses try/catch blocks like this in every method.

Justin Etheredge
13 Apr 2009
23:31 PM
Justin Etheredge

This looks like an entry in a contest to see who can write the highest density of bad code.

Seshan
13 Apr 2009
23:38 PM
Seshan

First, it seems to me as if it is Not a Copy at all - Neither a shallow Copy nor a deep copy. The method just returns the same object, as objects are passed by ref. There is no use of returning an object when it is passed by reference. There would be a warning that "Not all Code paths return value". No need of Try catch around a return. No need to enclose an Exception object in catch construct when the exception is rethrown.

Walter Poch
14 Apr 2009
01:51 AM
Walter Poch

At least he could made it static LOL :)

U are not your code
14 Apr 2009
01:55 AM
U are not your code

Shameful public flogging. Aren't you big men!

pcm
14 Apr 2009
05:30 AM
pcm

I can't believe it! There are people who actually vote 5 on this article!

Peter Morris
14 Apr 2009
09:24 AM
Peter Morris

I'm sure we all write crap code sometimes. At least the guy could accept the criticism of the comment telling him why his exception "handling" is wrong rather than replying

"It was just a DEMO. I didn't intent to show HOW TO USE "TRY ... CATCH" in C#."

I'd fix it out of shame, not defend it!

Sindri
14 Apr 2009
09:52 AM
Sindri

Good programmers can make mistakes, even as bad as this one. Then there are bad programmers that will always do something like this.

You can tell who's who by their response when you point it out.

Benny Thomas
14 Apr 2009
09:56 AM
Benny Thomas

Things like this I've seen at lots of project I have been working with. And always the coder of the ugly code defends himself like the auther does here too.

Sometimes is good to cry.

defaultuser
14 Apr 2009
10:18 AM
defaultuser

PERFECT :)

Chris
14 Apr 2009
11:08 AM
Chris

BRILLANT

Grunties
14 Apr 2009
11:37 AM
Grunties

There's some things wrong with this code, yes, and it was clearly written by someone with little understanding of what's going on 'under the bonnet/hood'. But, here, there's a lot of Dunning-Kruger effect. There are some good reasons to be doing what this code is attempting, and yet no one here wants to mention any of it. Shameful and misguided elitism, IMHO.

jay vaughan
14 Apr 2009
11:54 AM
jay vaughan

// tl;dr

duh, everyone knows that this is just a hook for an out-of-VM exception handler.

John Chapman
14 Apr 2009
12:13 PM
John Chapman

Why did you leave out the Disassemble method? It really ties the whole thing together. I actually feel kind of bad for him, but worse for the people reading this as an expert example.

public object DeepCopy(object value)

    {

        try

        {

            return value;

        }

        catch (Exception ex)

        {

            throw ex;

        }

    }

    public object Disassemble(object value)

    {

        try

        {

            return DeepCopy(value);

        }

        catch (Exception ex)

        {

            throw ex;

        }

    }
Pop Catalin
14 Apr 2009
12:19 PM
Pop Catalin

@Grunties, I don' claim to be a smart fellow or an enlightened .Net developer, but what are the reasons you are talking about?

This is not about elitism, this is about spreading bad coding practices, in a community where thousands of developers passionate about their framework and language invest huge amounts of time and dedication to write blog posts, articles and books about good coding practices as a community effort to raise the quality bar of the code .Net developers write in general.

We are all better of when bad coding isn't spread around in articles like this one.

Aslam Khan
14 Apr 2009
13:22 PM
Aslam Khan

Yes, this is just bad code. Ayende has rightfully surfaced it as such. But I really don't see the value of hosing the author as a useless developer. Have you asked yourself "Why am I laughing at this - publicly, and loudly?".

I watched the tail-end of Romy and Michelle's High School Reunion on TV last night. The laugh comments here reminds me of Christine and her girlfriends ridiculing Romy and Michele at the reunion.

I think we are all capable of being better people than this.

Matt H
14 Apr 2009
13:36 PM
Matt H

maybe the code was poorly ported from C++ where the object was returned by value and the exception was caught in case the copy constructor failed

Min
14 Apr 2009
14:09 PM
Min

Wow...

I do not know what disturbs me more, the fact that this article was accepted by CodeProject or the fact that someone out there will use this article in production code.

I've googled some of the code in my company's codebase and have found some CodeProject articles come up.

Fabio Maulo
14 Apr 2009
14:58 PM
Fabio Maulo

Probably you don't have realized that the NH's users generation are changing; this is not a minor problem and sure it is a problem.

James E. Ervin
14 Apr 2009
15:49 PM
James E. Ervin

There is nothing wrong with the code, that is just it, there is nothing. It makes me feel almost zen like... There is nothing wrong... There is no spoon... There is no special ingredient... There is just nothing....

Scott R
14 Apr 2009
16:02 PM
Scott R

i haven't laughed so hard in ages. thank you for brightening my day.

Stinking Machines
14 Apr 2009
16:28 PM
Stinking Machines

It looks like a stub. Move along...

Tim
14 Apr 2009
17:42 PM
Tim

Shame on CodeProject.com.

I'll be extra skeptical next time I see a CodeProject article from an unknown author.

Peter Morris
14 Apr 2009
21:38 PM
Peter Morris

@Grunties : What good reasons are those?

@Aslam : If you are going to compare with something, try something that people have heard of :-)

Seriously though, I thought this post was a bit pathetic until I saw the author's apparent inability to accept his mistakes and fix the code in the article. Then I thought the article was worth mocking.

It's counts not only how good you are when things go right, but also how good you are when things go wrong!

If my code is shit I will be glad for the criticism as I learn from changing it.

Krylen
14 Apr 2009
23:37 PM
Krylen

Wow, that's something else right there. The creator of that code should give this new fangled learning technique called "reading books" a try.

Alex
15 Apr 2009
03:26 AM
Alex

I call fizzbuzz.

Leo
15 Apr 2009
11:44 AM
Leo

guys.,

I am one of those junior developers who can't see what is so wrong with the code. How would it be different if one would do

Catch(Exception ex)

{ throw; }

In the case of the author he is still throwing eventually. I miss the point.

Also I am not sure what are the inherent problems with accepting a parameter as an object and then returning it? Let me go further and say I don't even understand how does that mean deep copy? Just accepting an object by reference and returning the reference back.

I would be glad for any pointers.

Ayende Rahien
15 Apr 2009
11:49 AM
Ayende Rahien

throw; // keep the stack trace

throw ex; // lose the stack trace

Losing the stack trace is _bad_.

Putting a try catch block without doing any error handling is wrong.

DeepCopy should perform a DEEP copy, not a ref copy.

What this method does is return the same reference, so it lies about its impl.

Leo
15 Apr 2009
11:59 AM
Leo

Thanks Ayende. That was quick. I am glad you restored my sanity.

Dmitry
15 Apr 2009
13:53 PM
Dmitry

The method actually returns a copy of the reference. .NET uses a copy of the original reference inside a method unless the "ref" keyword is used in the parameter declaration. This is why setting the reference to null inside the method will not change the outside reference.

Dave G
15 Apr 2009
20:22 PM
Dave G

Well it seems that your criticism of the author has now caused the article to be removed..

Moran
16 Apr 2009
13:32 PM
Moran

I've seen much worse:

try { ... }

catch(Exception ex)

{

Response.Write(ex.Message + "

" + ex.StackTrace);

}

Green WIlliams
16 Apr 2009
18:58 PM
Green WIlliams

I have an idea. Let me throw up lousy code, lay back and watch herds of women-deprived geeks laugh about it and throw up more code. Oh, no need to. It has already been done here.

Jeff Hadfield
16 Apr 2009
23:14 PM
Jeff Hadfield

It's already been voted into oblivion by the community. Hooray. Thanks for reading The Code Project, though. Hope you voted it down!

Pop Catalin
17 Apr 2009
14:49 PM
Pop Catalin

Well it seems that your criticism of the author has now caused the article to be removed..

It's a shame, that the criticism didn't make the author rewrite it ...

Ayende Rahien
21 Apr 2009
07:34 AM
Ayende Rahien

Aslam,

Several reasons:

a) bad code need to be made public, to make sure that people _recognize it as bad code

b) this is actually fairly high on the search for a few important nhibernate concurrency searches

Sung Meister
27 Apr 2009
03:12 AM
Sung Meister

It has now been deleted... I can't get myself into context any more.

Brian Henderson
02 May 2009
06:28 AM
Brian Henderson

How to make this code throw an exception? Would like to see an unit test that demonstrates. Thx.

Ayende Rahien
02 May 2009
06:30 AM
Ayende Rahien

Brian,

Sort of my point

Comment preview

Comments have been closed on this topic.

Markdown formatting

ESC to close

Markdown turns plain text formatting into fancy HTML formatting.

Phrase Emphasis

*italic*   **bold**
_italic_   __bold__

Links

Inline:

An [example](http://url.com/ "Title")

Reference-style labels (titles are optional):

An [example][id]. Then, anywhere
else in the doc, define the link:
  [id]: http://example.com/  "Title"

Images

Inline (titles are optional):

![alt text](/path/img.jpg "Title")

Reference-style:

![alt text][id]
[id]: /url/to/img.jpg "Title"

Headers

Setext-style:

Header 1
========
Header 2
--------

atx-style (closing #'s are optional):

# Header 1 #
## Header 2 ##
###### Header 6

Lists

Ordered, without paragraphs:

1.  Foo
2.  Bar

Unordered, with paragraphs:

*   A list item.
    With multiple paragraphs.
*   Bar

You can nest them:

*   Abacus
    * answer
*   Bubbles
    1.  bunk
    2.  bupkis
        * BELITTLER
    3. burper
*   Cunning

Blockquotes

> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
> 
> * You can quote a list.
> * Etc.

Horizontal Rules

Three or more dashes or asterisks:

---
* * *
- - - - 

Manual Line Breaks

End a line with two or more spaces:

Roses are red,   
Violets are blue.

Fenced Code Blocks

Code blocks delimited by 3 or more backticks or tildas:

```
This is a preformatted
code block
```

Header IDs

Set the id of headings with {#<id>} at end of heading line:

## My Heading {#myheading}

Tables

Fruit    |Color
---------|----------
Apples   |Red
Pears	 |Green
Bananas  |Yellow

Definition Lists

Term 1
: Definition 1
Term 2
: Definition 2

Footnotes

Body text with a footnote [^1]
[^1]: Footnote text here

Abbreviations

MDD <- will have title
*[MDD]: MarkdownDeep

 

FUTURE POSTS

  1. NOT Sharding RavenDB Vector Search - 2 hours from now
  2. Optimizing the cost of clearing a set - 3 days from now
  3. Scaling HNSW in RavenDB: Optimizing for inadequate hardware - 5 days from now

There are posts all the way to May 14, 2025

RECENT SERIES

  1. RavenDB News (2):
    02 May 2025 - May 2025
  2. Recording (15):
    30 Apr 2025 - Practical AI Integration with RavenDB
  3. Production Postmortem (52):
    07 Apr 2025 - The race condition in the interlock
  4. RavenDB (13):
    02 Apr 2025 - .NET Aspire integration
  5. RavenDB 7.1 (6):
    18 Mar 2025 - One IO Ring to rule them all
View all series

RECENT COMMENTS

  • But in case you have nullability checks enabled (i.e. `<Nullable>enable</Nullable>`), then you'll have a compiler warning on ...
    By Samyon Ristov on The null check that didn't check for nulls
  • Grok wasn't *wrong*. It only said that `_items` can't be null for the condition to evaluate to `true`, but didn't say anythi...
    By Johannes Egger on The null check that didn't check for nulls
  • When I started enabling NRT, I remember I was initially confused when all variables (for reference types) declared with `var`...
    By riccardo on The null check that didn't check for nulls
  • That is surprising - I think of var as a shorthand that does not affect the final result of the compilation. I wouldn't expec...
    By Chris B on The null check that didn't check for nulls
  • "It is also about as friendly as a monkey with a sore tooth and an alcohol addiction." And I have to clean my monitor.
    By Tim on When racing the Heisenbug, code quality goes out the Windows

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats
}