<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A few things from C++ that i miss in C#</title>
	<atom:link href="http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/</link>
	<description>If we don't have the solution you have the wrong problem</description>
	<lastBuildDate>Wed, 28 Dec 2011 10:48:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: eti</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3692</link>
		<dc:creator>eti</dc:creator>
		<pubDate>Sun, 31 Jan 2010 07:42:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3692</guid>
		<description>@Allon, thanks for your opinion on this. I have since than entered the world of NHibernate witch i can&#039;t say i fully know, but witch has proven to be pretty complex and feature-full ORM. I&#039;ve read about EF 4 and i&#039;m eager to play hoping that will be a log more than v3 was.</description>
		<content:encoded><![CDATA[<p>@Allon, thanks for your opinion on this. I have since than entered the world of NHibernate witch i can&#8217;t say i fully know, but witch has proven to be pretty complex and feature-full ORM. I&#8217;ve read about EF 4 and i&#8217;m eager to play hoping that will be a log more than v3 was.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allon Guralnek</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3690</link>
		<dc:creator>Allon Guralnek</dc:creator>
		<pubDate>Sat, 30 Jan 2010 17:15:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3690</guid>
		<description>@eti, you should not use a long-living DataContext, ever! You might have a long-living IDbConnection, but beware that a DataContext can leak memory like crazy. A simple test would be to try and insert a million rows. You&#039;ll hit a OutOfMemoryException pretty fast, since the DataContext tried to track all the objects. The DataContext should be used on a per-operation basis, it&#039;s a lightweight object - create it and dispose of it at the end of a logical operation. Use the constructor that accepts a IDbConnection object to avoid connecting and disconnecting from the database with each operations.

In general, LINQ to SQL is a pretty basic and O/R Mapper, providing a very low level of abstraction. I suggest having a look at Entity Framework v4 which is included with .NET 4.0/VS2010 (EFv3, included with .NET3.5 SP1, what a bit... meh).</description>
		<content:encoded><![CDATA[<p>@eti, you should not use a long-living DataContext, ever! You might have a long-living IDbConnection, but beware that a DataContext can leak memory like crazy. A simple test would be to try and insert a million rows. You&#8217;ll hit a OutOfMemoryException pretty fast, since the DataContext tried to track all the objects. The DataContext should be used on a per-operation basis, it&#8217;s a lightweight object &#8211; create it and dispose of it at the end of a logical operation. Use the constructor that accepts a IDbConnection object to avoid connecting and disconnecting from the database with each operations.</p>
<p>In general, LINQ to SQL is a pretty basic and O/R Mapper, providing a very low level of abstraction. I suggest having a look at Entity Framework v4 which is included with .NET 4.0/VS2010 (EFv3, included with .NET3.5 SP1, what a bit&#8230; meh).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eti</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3651</link>
		<dc:creator>eti</dc:creator>
		<pubDate>Tue, 20 Oct 2009 09:06:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3651</guid>
		<description>Hi all,
Funny thing that after this discussions i had an interesting debate at work. We are working with a DAL implemented using LINQ to SQL. Basically we have an MVC app that has Controllers witch use Services witch use Repositories witch use a LINQ DataContext. 

Now the DataContext generated by LINQ implements IDisposable, and when i see a class that implements IDisposable i want to play nice and dispose any instance created. The problem is that all the repositories share - for a request - the same DataContext instance and also the results of some linq queries are stored in cache so i can&#039;t really dispose of the DataContext at the end of the request since objects created by it might still exist in the cache and they hold a reference to the DataContext. 

Going deeper in the DataContext story I&#039;ve found out that you don&#039;t really have to dispose it since it will not keep the db connection open only the while executing the query and retrieving the results. So in the end the conclusion was that it&#039;s better, simpler to just leave it to the GC.

Still it feels strange to rely on the internal details of the DataContext ... but i guess it&#039;s one of the prices i have to pay for all the nice things that LINQ to SQL brings. 

@Ben: Man, i hear you on the non nullable types.</description>
		<content:encoded><![CDATA[<p>Hi all,<br />
Funny thing that after this discussions i had an interesting debate at work. We are working with a DAL implemented using LINQ to SQL. Basically we have an MVC app that has Controllers witch use Services witch use Repositories witch use a LINQ DataContext. </p>
<p>Now the DataContext generated by LINQ implements IDisposable, and when i see a class that implements IDisposable i want to play nice and dispose any instance created. The problem is that all the repositories share &#8211; for a request &#8211; the same DataContext instance and also the results of some linq queries are stored in cache so i can&#8217;t really dispose of the DataContext at the end of the request since objects created by it might still exist in the cache and they hold a reference to the DataContext. </p>
<p>Going deeper in the DataContext story I&#8217;ve found out that you don&#8217;t really have to dispose it since it will not keep the db connection open only the while executing the query and retrieving the results. So in the end the conclusion was that it&#8217;s better, simpler to just leave it to the GC.</p>
<p>Still it feels strange to rely on the internal details of the DataContext &#8230; but i guess it&#8217;s one of the prices i have to pay for all the nice things that LINQ to SQL brings. </p>
<p>@Ben: Man, i hear you on the non nullable types.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eti</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3648</link>
		<dc:creator>eti</dc:creator>
		<pubDate>Tue, 13 Oct 2009 07:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3648</guid>
		<description>@Daniel: Thanks for the links, very informative on the subject.</description>
		<content:encoded><![CDATA[<p>@Daniel: Thanks for the links, very informative on the subject.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3647</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sun, 11 Oct 2009 02:29:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3647</guid>
		<description>ref counting GCs were tried but performance penalty is heavy ( it also requires recompilation).. Cyclical references have been shown to always happen and are nasty bugs to find or test for.

However you can manage your own memory by using a factory and pointers ( allocate a byte block) in an unsafe block and manage your own heap. This is very useful for cases when you want no GC collections  eg if you were writing a 3D app and want to manage your vertex buffers etc. I

Templates i can understand but few people actually understand some templates and Java passes with very poor generics. 

My biggest gripes
-Non nullable types (Sing# has these) 
-Immutable object support via an interface</description>
		<content:encoded><![CDATA[<p>ref counting GCs were tried but performance penalty is heavy ( it also requires recompilation).. Cyclical references have been shown to always happen and are nasty bugs to find or test for.</p>
<p>However you can manage your own memory by using a factory and pointers ( allocate a byte block) in an unsafe block and manage your own heap. This is very useful for cases when you want no GC collections  eg if you were writing a 3D app and want to manage your vertex buffers etc. I</p>
<p>Templates i can understand but few people actually understand some templates and Java passes with very poor generics. </p>
<p>My biggest gripes<br />
-Non nullable types (Sing# has these)<br />
-Immutable object support via an interface</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Earwicker</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3646</link>
		<dc:creator>Daniel Earwicker</dc:creator>
		<pubDate>Thu, 08 Oct 2009 09:34:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3646</guid>
		<description>Lior, your suggest about reference counting is way off.

VB 6 worked like that, and so obviously Microsoft considered very carefully if there was a way to bring it into .NET, and all that debate was played out nearly a decade ago. Here&#039;s the conclusion that was posted to the original .NET mailing list back in 2000:

http://blogs.msdn.com/brada/articles/371015.aspx

One important point is that reference counting is NOT deterministic destruction.

The whole point of deterministic destruction is to be able to say with certainty that by the time control reaches a certain point in the code, a certain resource has been freed. But if somewhere else in the program is able to stop that from happening, then it is invalidated.

If you want deterministic destruction, you don&#039;t want reference counting. You want C++ destructors (no reference counting) or IDisposable (no reference counting) or the Lisp/Schema &quot;with&quot; idiom (no reference counting).

Reference counting is typically a wrong-headed attempt to simulate a GC where a proper automatic GC is not available. The irony is that GC is usually missing from the environment due to &quot;performance concerns&quot;, and yet the alternative chosen usually runs slower than automatic GC. This is certainly true with reference counting.

Here&#039;s a paper about an attempt to provide &quot;deterministic&quot; destruction via reference counting (which is a contradiction-in-terms):

http://bit.ly/1OHefw

They were surprised to find that C# programs ran an awful lot slower when using reference counting instead of GC. But if you understand just how amazingly fast the CLR&#039;s GC is, this will not be a surprise.</description>
		<content:encoded><![CDATA[<p>Lior, your suggest about reference counting is way off.</p>
<p>VB 6 worked like that, and so obviously Microsoft considered very carefully if there was a way to bring it into .NET, and all that debate was played out nearly a decade ago. Here&#8217;s the conclusion that was posted to the original .NET mailing list back in 2000:</p>
<p><a href="http://blogs.msdn.com/brada/articles/371015.aspx" rel="nofollow">http://blogs.msdn.com/brada/articles/371015.aspx</a></p>
<p>One important point is that reference counting is NOT deterministic destruction.</p>
<p>The whole point of deterministic destruction is to be able to say with certainty that by the time control reaches a certain point in the code, a certain resource has been freed. But if somewhere else in the program is able to stop that from happening, then it is invalidated.</p>
<p>If you want deterministic destruction, you don&#8217;t want reference counting. You want C++ destructors (no reference counting) or IDisposable (no reference counting) or the Lisp/Schema &#8220;with&#8221; idiom (no reference counting).</p>
<p>Reference counting is typically a wrong-headed attempt to simulate a GC where a proper automatic GC is not available. The irony is that GC is usually missing from the environment due to &#8220;performance concerns&#8221;, and yet the alternative chosen usually runs slower than automatic GC. This is certainly true with reference counting.</p>
<p>Here&#8217;s a paper about an attempt to provide &#8220;deterministic&#8221; destruction via reference counting (which is a contradiction-in-terms):</p>
<p><a href="http://bit.ly/1OHefw" rel="nofollow">http://bit.ly/1OHefw</a></p>
<p>They were surprised to find that C# programs ran an awful lot slower when using reference counting instead of GC. But if you understand just how amazingly fast the CLR&#8217;s GC is, this will not be a surprise.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allon Guralnek</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3645</link>
		<dc:creator>Allon Guralnek</dc:creator>
		<pubDate>Sat, 03 Oct 2009 23:46:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3645</guid>
		<description>I like a little poppy seed sprinkled on my bread roll, but I thoroughly dislike poppy seed cake. Too much of a good thing (functional programming) can be, well, too much. Nevertheless, I&#039;d try F# if it weren&#039;t for the real world. You see, the job requirement is to write in C# and to target the .NET Framework 2.0. Thankfully, that means I can use all of C# 3.0&#039;s features, including LINQ to Objects (with the aid of LINQBridge: http://code.google.com/p/linqbridge/). Since having a using prefix to local variable declarations is pure syntactic sugar, it would still work with .NET 2.0, just like the rest of C# 3.0&#039;s features. Well maybe it will appear in C# 5.0 (by then I&#039;m sure I&#039;ll be using .NET 3.5 in production environment, still a little shy from the required .NET 4.0 for official F# support).</description>
		<content:encoded><![CDATA[<p>I like a little poppy seed sprinkled on my bread roll, but I thoroughly dislike poppy seed cake. Too much of a good thing (functional programming) can be, well, too much. Nevertheless, I&#8217;d try F# if it weren&#8217;t for the real world. You see, the job requirement is to write in C# and to target the .NET Framework 2.0. Thankfully, that means I can use all of C# 3.0&#8242;s features, including LINQ to Objects (with the aid of LINQBridge: <a href="http://code.google.com/p/linqbridge/" rel="nofollow">http://code.google.com/p/linqbridge/</a>). Since having a using prefix to local variable declarations is pure syntactic sugar, it would still work with .NET 2.0, just like the rest of C# 3.0&#8242;s features. Well maybe it will appear in C# 5.0 (by then I&#8217;m sure I&#8217;ll be using .NET 3.5 in production environment, still a little shy from the required .NET 4.0 for official F# support).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3644</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Sat, 03 Oct 2009 18:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3644</guid>
		<description>@Allon

In fact, F#, the new language being developed by Microsoft Research (origins in OCaml) has exactly the prefix syntax you want.  Below is an example of the function you gave in F#&#039;s syntax:

let CompressServerLog() =
    use file = new FileStream(@”C:\archive.zip”)
    use zip = new ZipFileStream(file)
    zip.Addfile @”C:\ServerActivity.log”

The filestream and zipfilestream&#039;s are disposed when the function ends and the two &#039;use&#039; bindings go out of lexical scope.  Lexical scope is created by indentation or optional syntax a la:
use file = new FileStream(...) in  where the binding is scoped to the expression after the in keyword.

You can read more about F# at fsharp.net
http://msdn.microsoft.com/en-us/library/dd233240(VS.100).aspx has information on the &#039;use&#039; binding and &#039;using&#039; function.

I&#039;ve been using F# now for a year and am quite pleased with it.  If you enjoy using LINQ, then you&#039;ll love F#.</description>
		<content:encoded><![CDATA[<p>@Allon</p>
<p>In fact, F#, the new language being developed by Microsoft Research (origins in OCaml) has exactly the prefix syntax you want.  Below is an example of the function you gave in F#&#8217;s syntax:</p>
<p>let CompressServerLog() =<br />
    use file = new FileStream(@”C:\archive.zip”)<br />
    use zip = new ZipFileStream(file)<br />
    zip.Addfile @”C:\ServerActivity.log”</p>
<p>The filestream and zipfilestream&#8217;s are disposed when the function ends and the two &#8216;use&#8217; bindings go out of lexical scope.  Lexical scope is created by indentation or optional syntax a la:<br />
use file = new FileStream(&#8230;) in  where the binding is scoped to the expression after the in keyword.</p>
<p>You can read more about F# at fsharp.net<br />
<a href="http://msdn.microsoft.com/en-us/library/dd233240(VS.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd233240(VS.100).aspx</a> has information on the &#8216;use&#8217; binding and &#8216;using&#8217; function.</p>
<p>I&#8217;ve been using F# now for a year and am quite pleased with it.  If you enjoy using LINQ, then you&#8217;ll love F#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allon Guralnek</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3643</link>
		<dc:creator>Allon Guralnek</dc:creator>
		<pubDate>Sat, 03 Oct 2009 17:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3643</guid>
		<description>Eti, I think the disposing of object when out of scope is a good idea. Today I would have to write:

private void CompressServerLog()
{
    using (FileStream file = new FileStream(@&quot;C:\archive.zip&quot;))
    {
        using (ZipFileStream zip = new ZipFileStream(file))
        {
            zip.AddFile(@&quot;C:\ServerActivity.log&quot;);
        }
    }
}

Instead, I would like to write:

private void CompressServerLog ()
{
    using FileStream file = new FileStream(@&quot;C:\archive.zip&quot;);
    using ZipFileStream zip = new ZipFileStream(file);
    zip.AddFile(@&quot;C:\ServerActivity.log&quot;);
}

And have it translated to the first example by the compiler. Allowing the &#039;using&#039; statement to be an optional prefix for local variable declarations which would tell the compiler to dispose when out of scope would be quite a nice feature in my opinion. That would actually make using the curly brackets to create an inner scope actually useful for a change.</description>
		<content:encoded><![CDATA[<p>Eti, I think the disposing of object when out of scope is a good idea. Today I would have to write:</p>
<p>private void CompressServerLog()<br />
{<br />
    using (FileStream file = new FileStream(@&#8221;C:\archive.zip&#8221;))<br />
    {<br />
        using (ZipFileStream zip = new ZipFileStream(file))<br />
        {<br />
            zip.AddFile(@&#8221;C:\ServerActivity.log&#8221;);<br />
        }<br />
    }<br />
}</p>
<p>Instead, I would like to write:</p>
<p>private void CompressServerLog ()<br />
{<br />
    using FileStream file = new FileStream(@&#8221;C:\archive.zip&#8221;);<br />
    using ZipFileStream zip = new ZipFileStream(file);<br />
    zip.AddFile(@&#8221;C:\ServerActivity.log&#8221;);<br />
}</p>
<p>And have it translated to the first example by the compiler. Allowing the &#8216;using&#8217; statement to be an optional prefix for local variable declarations which would tell the compiler to dispose when out of scope would be quite a nice feature in my opinion. That would actually make using the curly brackets to create an inner scope actually useful for a change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lior</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/comment-page-1/#comment-3641</link>
		<dc:creator>Lior</dc:creator>
		<pubDate>Sat, 03 Oct 2009 08:00:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/?p=90#comment-3641</guid>
		<description>Your comment re &quot;standard&quot; managed objects controlling the lifecycle of [AutoDisposed] objects is correct. I believe that in order for my idea to work, a proper implementation will have to implicitly propagate the reference counting to any class that has a reference-count member (clearly, there may be exceptions). In fact, this is what we have to write explicitly these days- any class that contains an IDisposable member should (for reasons of proper encapsulation) implement IDisposable itself, even if all its Dispose method does is calling its IDisposable members&#039; Dispose methods. My idea will automate this process and exempt programmers from the burden of writing and managing the explicit calls to all these Dispose methods.</description>
		<content:encoded><![CDATA[<p>Your comment re &#8220;standard&#8221; managed objects controlling the lifecycle of [AutoDisposed] objects is correct. I believe that in order for my idea to work, a proper implementation will have to implicitly propagate the reference counting to any class that has a reference-count member (clearly, there may be exceptions). In fact, this is what we have to write explicitly these days- any class that contains an IDisposable member should (for reasons of proper encapsulation) implement IDisposable itself, even if all its Dispose method does is calling its IDisposable members&#8217; Dispose methods. My idea will automate this process and exempt programmers from the burden of writing and managing the explicit calls to all these Dispose methods.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

