<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Coffeehouse - Unconventional use of indexers</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Coffeehouse - Unconventional use of indexers</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Wed, 22 May 2013 18:09:58 GMT</pubDate>
	<lastBuildDate>Wed, 22 May 2013 18:09:58 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>5</c9:totalResults>
	<c9:pageCount>-5</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Coffeehouse - Unconventional use of indexers</title>
		<description><![CDATA[<p>I'm playing around with trying to make array math in C# as easy and concise as in Matlab, and (besides array operators) the biggest language &quot;mismatch&quot; is in indexers, ranges, etc. In Matlab, I can easily get a subarray of A, such as A[0:5:255]<br>
<br>
As a user of a fluent interface DSL in C#, would you ever put up with unconventional use of indexers? Like:<br>
<br>
<pre class="brush: csharp">A[Get.Range[0,5,255]]</pre>
<br>
<br>
...where Range is actually a static readonly field holding an instance of class Range<br>
<br>
<pre class="brush: csharp">    public class Get
    {
        public static readonly Range Range = new Range();
        public static readonly Size Size = new Size();
    }

    public class Range
    {
        public Range this[int from, int to] { get { return new Range(from, 1, to); } }
        public Range this[int from, int every, int to] { get { return new Range(from, every, to); } }

        private Range(int start, int every, int stop) { Start = start; Every = every;  Stop = stop; }
        private Range(int start, int stop) : this(start, 1, stop) { }
        internal Range() { } // for indexer use

        public int Start { get; private set; }
        public int Stop { get; private set; }
        public int Every { get; private set; }
        public int Count() { return (Stop - Start) / Every &#43; 1; }
    }

    public class Size
    {
        public Size this[int d0] { get { return new Size(new int[] { d0 }); } }
        public Size this[int d0, int d1] { get { return new Size(new int[] { d0, d1 }); } }
        public Size this[int d0, int d1, int d2] { get { return new Size(new int[] { d0, d1, d2 }); } }
        public Size this[int d0, int d1, int d2, int d3] { get { return new Size(new int[] { d0, d1, d2, d3 }); } }

        private Size(int[] dimensions) { Dimensions = dimensions.ToArray(); }
        internal Size() { } // for indexer use

        public int[] Dimensions { get; private set; }
    }
</pre>
<br>
<br>
Obviously the following would be more C-sharpy:<br>
<br>
<pre class="brush: csharp">A[new Range(0,5,255)]</pre>
<br>
<br>
But, isn't it OK to stray a bit as long as there's a consistent convention in the DSL?<br>
<br></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/426985#426985</link>
		<pubDate>Thu, 11 Sep 2008 06:53:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/426985#426985</guid>
		<dc:creator>dcuccia</dc:creator>
		<slash:comments>5</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/dcuccia/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Unconventional use of indexers</title>
		<description><![CDATA[<p>you may also want to make&nbsp; the constructor of the Range class internal, to force the user to use it via Get class (if you use first approach), I would suggest to use the second one, but the first one looks cooler...<br></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/dd2bbd937605461d864c9dea00fd6d51#dd2bbd937605461d864c9dea00fd6d51</link>
		<pubDate>Thu, 11 Sep 2008 09:05:11 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/dd2bbd937605461d864c9dea00fd6d51#dd2bbd937605461d864c9dea00fd6d51</guid>
		<dc:creator>Ion Todirel</dc:creator>
		<slash:comments>5</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Ion Todirel/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Unconventional use of indexers</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Ion Todirel said:</div><div class="quoteText">you may also want to make&nbsp; the constructor of the Range class internal, to force the user to use it via Get class (if you use first approach), I would suggest to use the second one, but the first one looks cooler...<br>
</div></blockquote>I'd be honest and say I don't think it adds anything or makes it really different, to me it just serves as a barrier for people to realize whats actually going on here..</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/1b1a4bbdda804421891a9dea00fd6d7f#1b1a4bbdda804421891a9dea00fd6d7f</link>
		<pubDate>Thu, 11 Sep 2008 10:36:09 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/1b1a4bbdda804421891a9dea00fd6d7f#1b1a4bbdda804421891a9dea00fd6d7f</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>5</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Unconventional use of indexers</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">stevo_ said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Ion Todirel said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
I'd be honest and say I don't think it adds anything or makes it really different, to me it just serves as a barrier for people to realize whats actually going on here..</div></blockquote>Thanks for the thoughts Ion and stevo_.
<br>
<br>
Is the &quot;Get&quot; class a barrier too? If you had factory methods, which would you prefer (assuming &quot;Get&quot; is used for many purposes in the DSL)?<br>
<br>
<pre class="brush: csharp">A[Get.Range(0,5,255)]</pre>
<br>
<br>
or a classic <br>
<br>
<pre class="brush: csharp"> A[Range.GetRange(0,5,255)]</pre>
<br></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/29ae48ed6a314313a2669dea00fd6dad#29ae48ed6a314313a2669dea00fd6dad</link>
		<pubDate>Fri, 12 Sep 2008 20:13:26 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/29ae48ed6a314313a2669dea00fd6dad#29ae48ed6a314313a2669dea00fd6dad</guid>
		<dc:creator>dcuccia</dc:creator>
		<slash:comments>5</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/dcuccia/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Unconventional use of indexers</title>
		<description><![CDATA[<p>I would prefer A.Range(from, to) and A.Range(from, to, every) rather than the indexer, but that's just my opinion.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/9602604e4ca34c66a11f9dea00fd6dd7#9602604e4ca34c66a11f9dea00fd6dd7</link>
		<pubDate>Fri, 12 Sep 2008 21:07:58 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/426985-Unconventional-use-of-indexers/9602604e4ca34c66a11f9dea00fd6dd7#9602604e4ca34c66a11f9dea00fd6dd7</guid>
		<dc:creator>JChung2006</dc:creator>
		<slash:comments>5</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JChung2006/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>