﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Jeff Brown commented on Dense code</title><description>Doh!  I missed a "return" statement in there.
  
  
return reportSnapshotMemoizer.Memoize(() =&gt; ....);
</description><link>http://ayende.com/4001/dense-code#comment21</link><guid>http://ayende.com/4001/dense-code#comment21</guid><pubDate>Mon, 11 May 2009 20:24:34 GMT</pubDate></item><item><title>Jeff Brown commented on Dense code</title><description>This looks like memoization.  Here's my variation on this:
  
  
private Memoizer
&lt;ireportsnapshot reportSnapshotMemoizer = new Memoizer
&lt;ireportsnapshot();
  
  
public IReportSnapshot GetReportSnapshot()
  
{
  
    reportSnapshotMemoizer.Memoize(() =&gt;
  
    {
  
        // obtain snapshot
  
        return reportSnapshot;
  
    });
  
}
  
  
Another variation I use in Gallio is a KeyedMemoizer
&lt;tkey,&gt;
 which is basically a simple dictionary-based lazily populated cache.
&gt;</description><link>http://ayende.com/4001/dense-code#comment20</link><guid>http://ayende.com/4001/dense-code#comment20</guid><pubDate>Mon, 11 May 2009 20:23:33 GMT</pubDate></item><item><title>Kelly Stuard commented on Dense code</title><description>You're probably going through a fair amount of work to make cached.Read() work without any passed in information. I would see you more as the type of person who would use aspect oriented programming to do:
  
  
[Cached]
  
public IEnumerable
&lt;iqueryaggregationshapshot GetReportSnampshot()
  
  
and have it do the
  
  
cached.Read followed by the wonderfully compact write.
&gt;</description><link>http://ayende.com/4001/dense-code#comment19</link><guid>http://ayende.com/4001/dense-code#comment19</guid><pubDate>Mon, 11 May 2009 14:33:14 GMT</pubDate></item><item><title>Ian Chamberlain commented on Dense code</title><description>Pity the poor person who has maintain it years from now.
  
Dense code is bad for testing, bad for understanding and bad for maintenance.
  
For me this is the opposite of elegance.
</description><link>http://ayende.com/4001/dense-code#comment18</link><guid>http://ayende.com/4001/dense-code#comment18</guid><pubDate>Mon, 11 May 2009 09:38:45 GMT</pubDate></item><item><title>Martin commented on Dense code</title><description>Couldn't caching be achieved without the GetReportSnapshot method itself care about the cashing?
</description><link>http://ayende.com/4001/dense-code#comment17</link><guid>http://ayende.com/4001/dense-code#comment17</guid><pubDate>Mon, 11 May 2009 08:31:13 GMT</pubDate></item><item><title>PandaWood commented on Dense code</title><description>I think it's just right
</description><link>http://ayende.com/4001/dense-code#comment16</link><guid>http://ayende.com/4001/dense-code#comment16</guid><pubDate>Sun, 10 May 2009 07:04:29 GMT</pubDate></item><item><title>Jacob commented on Dense code</title><description>I like it. To me it's not about density or beauty, it's about readability. Your example has that (largely due to your formatting and whitespace). Nice.
</description><link>http://ayende.com/4001/dense-code#comment15</link><guid>http://ayende.com/4001/dense-code#comment15</guid><pubDate>Sat, 09 May 2009 20:33:14 GMT</pubDate></item><item><title>nightshade427 commented on Dense code</title><description>Very nice code! I noticed that ever since I started using ruby, my code is starting to look more and more succinct like this in C#. Couldn't the projection be made simpler without the assignments?
</description><link>http://ayende.com/4001/dense-code#comment14</link><guid>http://ayende.com/4001/dense-code#comment14</guid><pubDate>Sat, 09 May 2009 18:07:22 GMT</pubDate></item><item><title>Ayende Rahien commented on Dense code</title><description>Omer,
  
If I wouldn't do that, I would cache the query itself, not the query results
</description><link>http://ayende.com/4001/dense-code#comment13</link><guid>http://ayende.com/4001/dense-code#comment13</guid><pubDate>Sat, 09 May 2009 17:26:35 GMT</pubDate></item><item><title>Ayende Rahien commented on Dense code</title><description>Frank,
  
The unused value is the previous value for the item, which allow you to make modifications. It is not used here.
  
The reason for this is that I want to create an immutable snapshot
</description><link>http://ayende.com/4001/dense-code#comment12</link><guid>http://ayende.com/4001/dense-code#comment12</guid><pubDate>Sat, 09 May 2009 17:25:59 GMT</pubDate></item><item><title>Jeremy Gray commented on Dense code</title><description>@Omer - Yes, in order to force evaluation and convert the results into a form that can be safely cached and reused.
</description><link>http://ayende.com/4001/dense-code#comment11</link><guid>http://ayende.com/4001/dense-code#comment11</guid><pubDate>Sat, 09 May 2009 16:40:26 GMT</pubDate></item><item><title>Omer Mor commented on Dense code</title><description>Do you really need to  turn the result into an array ( .ToArray() )  at the end? 
</description><link>http://ayende.com/4001/dense-code#comment10</link><guid>http://ayende.com/4001/dense-code#comment10</guid><pubDate>Sat, 09 May 2009 16:20:18 GMT</pubDate></item><item><title>Frank Quednau commented on Dense code</title><description>What's with the unused "snapshots" variable? You could write 
  
_ =&gt; ... 
  
  
Should look even more dense ;)
  
And why is the type of "agg" so similar to the QueryAgg..Snapshot type?
  
  
Anyway, I like it. 
</description><link>http://ayende.com/4001/dense-code#comment9</link><guid>http://ayende.com/4001/dense-code#comment9</guid><pubDate>Sat, 09 May 2009 15:46:16 GMT</pubDate></item><item><title>Colin Jack commented on Dense code</title><description>Too dense for me.
</description><link>http://ayende.com/4001/dense-code#comment8</link><guid>http://ayende.com/4001/dense-code#comment8</guid><pubDate>Sat, 09 May 2009 15:01:15 GMT</pubDate></item><item><title>noone commented on Dense code</title><description>Frankly, I see nothing bug ugly.
</description><link>http://ayende.com/4001/dense-code#comment7</link><guid>http://ayende.com/4001/dense-code#comment7</guid><pubDate>Sat, 09 May 2009 13:14:23 GMT</pubDate></item><item><title>Dave commented on Dense code</title><description>@Sasha. Outside the function itself it shouldn't matter if the result cam from cache or was freshly created.
  
  
I don't know how you write your tests, but I hope you don't started testing cached in the GetReportSnapshot tests. As GetReportSnapshot depends on cached, it's safe to assume cached would work properly as that part is covered elsewhere. 
  
  
Why would you give the GC a lot of work only so you can when you have a problem set a breakpoint? If you ever would encounter a problem in the GetReportSnapshot method, just add the intermediate (result) variable just for debugging. When you're done debugging, don't forget to remove the variable. With all the tears and layers I have enough overhead performance penalties. I don't need extra penalties.
  
</description><link>http://ayende.com/4001/dense-code#comment6</link><guid>http://ayende.com/4001/dense-code#comment6</guid><pubDate>Sat, 09 May 2009 11:04:43 GMT</pubDate></item><item><title>Thomas Eyde commented on Dense code</title><description>Too dense for my taste. Too many things happens at once, so I have a hard time figuring out what is going on.
</description><link>http://ayende.com/4001/dense-code#comment5</link><guid>http://ayende.com/4001/dense-code#comment5</guid><pubDate>Sat, 09 May 2009 10:43:22 GMT</pubDate></item><item><title>Chris Martin commented on Dense code</title><description>Lame...even gay; if you ask me. ;)
</description><link>http://ayende.com/4001/dense-code#comment4</link><guid>http://ayende.com/4001/dense-code#comment4</guid><pubDate>Sat, 09 May 2009 10:08:00 GMT</pubDate></item><item><title>Sasha Goldshtein commented on Dense code</title><description>What I don't like is that it's a little difficult to debug.  For example, if I wanted to know the value returned by Read() or by Write(), I would have to work quite hard.
  
  
When writing a public method such as this one, I often would assign the return values to variables and test the variables explicitly to facilitate debugging.
</description><link>http://ayende.com/4001/dense-code#comment3</link><guid>http://ayende.com/4001/dense-code#comment3</guid><pubDate>Sat, 09 May 2009 09:44:19 GMT</pubDate></item><item><title>JeroenH commented on Dense code</title><description>Personally, I don't really like linq syntactic sugar.
  
  
To me, this is just as clear, if not clearer:
  
  
queriesLookup.Values
  
   .Select(agg =&gt; new QueryAggregationSnapshot
  
      {
  
          ...
  
      }
  
  .Cast
&lt;iqueryaggregationsnapshot  
  .ToArray()
&gt;</description><link>http://ayende.com/4001/dense-code#comment2</link><guid>http://ayende.com/4001/dense-code#comment2</guid><pubDate>Sat, 09 May 2009 09:41:51 GMT</pubDate></item><item><title>Michael Morton commented on Dense code</title><description>I agree, very elegant.  Never quite occurred to me to do caching in this way, but it does make sense.  Definitely something I will have to consider in the future.
</description><link>http://ayende.com/4001/dense-code#comment1</link><guid>http://ayende.com/4001/dense-code#comment1</guid><pubDate>Sat, 09 May 2009 08:47:19 GMT</pubDate></item></channel></rss>