<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: How to Design Function Parameters That Make Interfaces Easier to Use (2/3)	</title>
	<atom:link href="https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Mon, 07 Oct 2019 03:26:43 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1514</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sat, 01 Dec 2018 20:30:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1514</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1507&quot;&gt;Arash Kashani&lt;/a&gt;.

Great question. For a class method that it not const, I think we can consider the object to be an in-out parameter. And for const methods, an in-parameter. With this convention, the initial code, t.sort(&quot;1stCol&quot;), becomes the most explicit and simple.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1507">Arash Kashani</a>.</p>
<p>Great question. For a class method that it not const, I think we can consider the object to be an in-out parameter. And for const methods, an in-parameter. With this convention, the initial code, t.sort(&#8220;1stCol&#8221;), becomes the most explicit and simple.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Arash Kashani		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1507</link>

		<dc:creator><![CDATA[Arash Kashani]]></dc:creator>
		<pubDate>Thu, 29 Nov 2018 21:47:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1507</guid>

					<description><![CDATA[If the outputs are supposed to be the return value of functions preferably, then would you suggest that class methods should be restricted to change the state of a class object merely and do not be used to create new objects?

Let&#039;s say we create a table class with rows and columns populated with items.

Table t(100,100);
t.sort(&quot;1stCol&quot;);

What&#039;s the sort method doing? is it modifying the object t inplace or is it returning a new sorted table?

If the intent is to create a new sorted table, isn&#039;t more explicit to define a standalone function to sort and return a new Table?

Table sort( Table t, char* col) { ...}

or perhaps a method that does both using an extra kewword?

Class Table() {

Table* sort (char* col, bool inplace) {

// Sort ...


If (inplace) return this;
else return nestable;


}

};

Which solution better shows the intent? Which one is more explicit?]]></description>
			<content:encoded><![CDATA[<p>If the outputs are supposed to be the return value of functions preferably, then would you suggest that class methods should be restricted to change the state of a class object merely and do not be used to create new objects?</p>
<p>Let&#8217;s say we create a table class with rows and columns populated with items.</p>
<p>Table t(100,100);<br />
t.sort(&#8220;1stCol&#8221;);</p>
<p>What&#8217;s the sort method doing? is it modifying the object t inplace or is it returning a new sorted table?</p>
<p>If the intent is to create a new sorted table, isn&#8217;t more explicit to define a standalone function to sort and return a new Table?</p>
<p>Table sort( Table t, char* col) { &#8230;}</p>
<p>or perhaps a method that does both using an extra kewword?</p>
<p>Class Table() {</p>
<p>Table* sort (char* col, bool inplace) {</p>
<p>// Sort &#8230;</p>
<p>If (inplace) return this;<br />
else return nestable;</p>
<p>}</p>
<p>};</p>
<p>Which solution better shows the intent? Which one is more explicit?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1504</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Wed, 28 Nov 2018 10:42:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1504</guid>

					<description><![CDATA[If you look at the MS headers, you&#039;ll see that they use _In_, _Inout, _Out_ and a variety of variations. Eg

&lt;pre&gt;&lt;code&gt;
WINUSERAPI
int
WINAPI
wvsprintfW(
    _Out_ LPWSTR,
    _In_ _Printf_format_string_ LPCWSTR,
    _In_ va_list arglist);

&lt;/code&gt;&lt;/pre&gt;

Which is part of MS markers for documenting the semantics of API&#039;s - The Microsoft Source Code Annotation Language (SAL). For more details see sal.h.]]></description>
			<content:encoded><![CDATA[<p>If you look at the MS headers, you&#8217;ll see that they use _In_, _Inout, _Out_ and a variety of variations. Eg</p>
<pre><code>
WINUSERAPI
int
WINAPI
wvsprintfW(
    _Out_ LPWSTR,
    _In_ _Printf_format_string_ LPCWSTR,
    _In_ va_list arglist);

</code></pre>
<p>Which is part of MS markers for documenting the semantics of API&#8217;s &#8211; The Microsoft Source Code Annotation Language (SAL). For more details see sal.h.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1503</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Wed, 28 Nov 2018 07:33:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1503</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1498&quot;&gt;Miguel Raggi&lt;/a&gt;.

Yes you&#039;re right, this is what I meant, this is now fixed. Thanks Miguel!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1498">Miguel Raggi</a>.</p>
<p>Yes you&#8217;re right, this is what I meant, this is now fixed. Thanks Miguel!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Piotr Nycz		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1501</link>

		<dc:creator><![CDATA[Piotr Nycz]]></dc:creator>
		<pubDate>Tue, 27 Nov 2018 19:58:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1501</guid>

					<description><![CDATA[This `IN` / `INOUT` / `OUT` is not so stupid idea. If only it was done this way `template  using IN = T const&#038;;` - same for OUT/INOUT - and use like this:  ` void copy(IN&#060;vector&#062; from, OUT&#060;vector&#062; to);`]]></description>
			<content:encoded><![CDATA[<p>This `IN` / `INOUT` / `OUT` is not so stupid idea. If only it was done this way `template  using IN = T const&amp;;` &#8211; same for OUT/INOUT &#8211; and use like this:  ` void copy(IN&lt;vector&gt; from, OUT&lt;vector&gt; to);`</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rud Merriam		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1500</link>

		<dc:creator><![CDATA[Rud Merriam]]></dc:creator>
		<pubDate>Tue, 27 Nov 2018 16:45:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1500</guid>

					<description><![CDATA[First, the original presentation ignores the later rule about putting the more important parameter first. The reference item should be the first parameter:

   double getRatio(Item const&#038;  containingItem, Item const&#038; item);

Second, this should be a member function of Item which eliminates the question about parameter ordering:

   double getRatio(Item const&#038; item) const { ... }

Third, even if you want it as a standalone function it costs nothing to create specializations:

   inline
   double getRatio(const Bag&#038; bag, const Book&#038; book) {
       return getRatio(bag, book);
       }

The entire purpose of strong typing is to prevent these kind of  problem.]]></description>
			<content:encoded><![CDATA[<p>First, the original presentation ignores the later rule about putting the more important parameter first. The reference item should be the first parameter:</p>
<p>   double getRatio(Item const&amp;  containingItem, Item const&amp; item);</p>
<p>Second, this should be a member function of Item which eliminates the question about parameter ordering:</p>
<p>   double getRatio(Item const&amp; item) const { &#8230; }</p>
<p>Third, even if you want it as a standalone function it costs nothing to create specializations:</p>
<p>   inline<br />
   double getRatio(const Bag&amp; bag, const Book&amp; book) {<br />
       return getRatio(bag, book);<br />
       }</p>
<p>The entire purpose of strong typing is to prevent these kind of  problem.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sebastian Büttner		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1499</link>

		<dc:creator><![CDATA[Sebastian Büttner]]></dc:creator>
		<pubDate>Tue, 27 Nov 2018 16:43:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1499</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1498&quot;&gt;Miguel Raggi&lt;/a&gt;.

You are right imo, was about to comment this as well.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1498">Miguel Raggi</a>.</p>
<p>You are right imo, was about to comment this as well.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/11/27/design-function-parameters-make-interfaces-easy-use-23/#comment-1498</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Tue, 27 Nov 2018 16:41:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1981#comment-1498</guid>

					<description><![CDATA[In that last example (the one with macros), I&#039;m not sure what you mean. Shouldn&#039;t INOUT parameters be simply passed as references (and not const references)? Maybe it makes more sense in the callsite.]]></description>
			<content:encoded><![CDATA[<p>In that last example (the one with macros), I&#8217;m not sure what you mean. Shouldn&#8217;t INOUT parameters be simply passed as references (and not const references)? Maybe it makes more sense in the callsite.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
