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,546
|
Comments: 51,163
Privacy Policy · Terms
filter by tags archive
time to read 2 min | 271 words

It seems like no one is ready to take my Linq Challange, so I decided to expand it a bit and meet my own standards. I decided to implement the challange in Active Record, since it is much faster to work with than NHibernate. Note that this is just the object model and the mapping, nothing more.

Overall, this is 800 lines of code and 20 lines of configuration, and I think that it took about three to four hours to build this demo.

Here is the object diagram:

OhMy.png

And the database model:

database.PNG

You can download the sample project here, I included a SQL Script to create the database in the file.

Just to note, this is not a toy sample, this is a complex model that is capable of expressing very annoying business requirements. I added a bit of recursive rules, just to make it a bit more realistic. The real project has a lot more stuff to make it easier to work with the model, but in essense, this is the way that I built the project.

Just to clarify, I am truly interested in seeing other solutions to this problem, preferably not ones in NHibernate / Active Record. Mainly because I think that this is complex enough to be a real world problem and not something that can be solved with demo code.

time to read 9 min | 1780 words

How would you write the following code so it would print "Bar" to the screen:

Foo foo = new Foo();

foo.DoWork("Foo");

foo.DoWork("Bar");

Can you make it work? You may not use any conditional operations.

Hint: Think Dynamically...

Update: To clarify, you should provide the rest of the code so those three lines will output "Bar" to the screen. You can implement Foo() anyway you want, and you can put more code between DoWork("Foo") and DoWork("Bar"), but you can't use conditinal operation (if, while, etc...).

Update II: Oren Ellenbogen suggested a solution like this:

static void Main (string[] args)

{

    using (Foo1 foo1 = new Foo1())

    {

        foo1.DoWork("Foo");

        foo1.DoWork("Bar");

    }

}

class Foo1 : IDisposable

{

    string last;

 

    public void DoWork(string arg)

    {

        this.last = arg;

    }

 

    public void Dispose()

    {

        Console.WriteLine(last);

    }

}

This answers the conditions of the the original challange, but it wasn't what I had in mind. So now you need to profuce "Bar", "Fubar" from this code, without using conditinals or loops.

Foo foo = new Foo();

foo.DoWork("Foo");

foo.DoWork("Bar");

foo.DoWork("Fubar");

Thinking about it, I realize that there are actually several other ways to do it than the one I thought of, most of them are not obvious, so I'll let the challange stand for now.

Another hint: I'm looking for another "What the F%$@ was he thinking..."

FUTURE POSTS

  1. Partial writes, IO_Uring and safety - one day from now
  2. Configuration values & Escape hatches - 4 days from now
  3. What happens when a sparse file allocation fails? - 6 days from now
  4. NTFS has an emergency stash of disk space - 8 days from now
  5. Challenge: Giving file system developer ulcer - 11 days from now

And 4 more posts are pending...

There are posts all the way to Feb 17, 2025

RECENT SERIES

  1. Challenge (77):
    20 Jan 2025 - What does this code do?
  2. Answer (13):
    22 Jan 2025 - What does this code do?
  3. Production post-mortem (2):
    17 Jan 2025 - Inspecting ourselves to death
  4. Performance discovery (2):
    10 Jan 2025 - IOPS vs. IOPS
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats
}