<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Designfrage: Setter -&amp;gt; return *this?]]></title><description><![CDATA[<p>Was meint ihr?</p>
<p>Sollte man bei jedem Setter das Objekt als Referenz wieder zurückgeben?</p>
<pre><code class="language-cpp">class myClass {
    std::string title;
public:
    myClass&amp; setTitle(const std::string&amp;);
};
</code></pre>
<p>Schlechter Stil? Perfomanceverlust? Andere Gründe?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/268185/designfrage-setter-gt-return-this</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 00:14:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/268185.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 05 Jun 2010 15:42:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:42:54 GMT]]></title><description><![CDATA[<p>Was meint ihr?</p>
<p>Sollte man bei jedem Setter das Objekt als Referenz wieder zurückgeben?</p>
<pre><code class="language-cpp">class myClass {
    std::string title;
public:
    myClass&amp; setTitle(const std::string&amp;);
};
</code></pre>
<p>Schlechter Stil? Perfomanceverlust? Andere Gründe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907347</guid><dc:creator><![CDATA[Luzius]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:42:54 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:46:39 GMT]]></title><description><![CDATA[<p>Geschmackssache.</p>
<p>Ich persönlich würde das ablehnen, denn es verleihtet sehr zu unübersichtlichen Konstrukten wie:<br />
obj.setTitle(&quot;Foo&quot;).setDescription(&quot;Bar&quot;).setAge(15);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907349</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907349</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:46:39 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:46:43 GMT]]></title><description><![CDATA[<p>nein, sollte man nicht.<br />
sollte aber keine (performance-)nachteile haben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907350</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:47:33 GMT]]></title><description><![CDATA[<p>wofür sollte das denn gut sein?</p>
<pre><code class="language-cpp">m.setTitle(&quot;hallo&quot;).setTitle(&quot;hallo welt&quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907351</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:47:33 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:48:20 GMT]]></title><description><![CDATA[<p>warum sollte man das tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907352</guid><dc:creator><![CDATA[dizzzy]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 15:59:10 GMT]]></title><description><![CDATA[<p>Das nennt man Function Chaining. Das hat den Vorteil, dass man nicht schreiben muss:</p>
<pre><code class="language-cpp">myClass.setBla();
myClass.setBlub();
myClass.setFoo();
</code></pre>
<p>Sondern:</p>
<pre><code class="language-cpp">myClass.setBla().setBlub().setFoo();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907358</guid><dc:creator><![CDATA[......]]></dc:creator><pubDate>Sat, 05 Jun 2010 15:59:10 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 16:02:22 GMT]]></title><description><![CDATA[<p>...... schrieb:</p>
<blockquote>
<p>Das nennt man Function Chaining. Das hat den Vorteil, dass man nicht schreiben muss:</p>
</blockquote>
<p>Ob man dies als Vorteil sehen kann?<br />
Ich persönlich bevorzuge einen Funktionsaufruf pro Zeile. Aber ist sicherlich auch Geschmacksache.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907360</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 05 Jun 2010 16:02:22 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 16:07:21 GMT]]></title><description><![CDATA[<p>Dravere schrieb:</p>
<blockquote>
<p>...... schrieb:</p>
<blockquote>
<p>Das nennt man Function Chaining. Das hat den Vorteil, dass man nicht schreiben muss:</p>
</blockquote>
<p>Ob man dies als Vorteil sehen kann?<br />
Ich persönlich bevorzuge einen Funktionsaufruf pro Zeile. Aber ist sicherlich auch Geschmacksache.</p>
<p>Grüssli</p>
</blockquote>
<p>Wie immer, gibt es immer Vor- und Nachteile. Es gibt Situationen, da machen solche Konstrukte Sinn.</p>
<pre><code class="language-cpp">myList.Add(&quot;Bla&quot;)
      .Add(&quot;Blub&quot;)
      .Add(&quot;Foo&quot;);
</code></pre>
<p>Andererseits gibts natürlich auch massive Nachteile. Beispielsweise ist das Debugging solcher Ketten nicht sonderlich schön.<br />
Auch kann die Lesbarkeit stark abnehmen, wenn man es übertreibt. Letzendlich ist aber auch std::cout eine Kette von Befehlen und daher nichts anderes. Das Konzept ist das gleiche - wo es Sinn macht, kann man darüber nachdenken.</p>
<p>Man muss natürlich garantieren können, dass immer ein gültiges Objekt zurückgegeben wird. Ansonsten crasht natürlich alles.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907364</guid><dc:creator><![CDATA[......]]></dc:creator><pubDate>Sat, 05 Jun 2010 16:07:21 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 16:09:59 GMT]]></title><description><![CDATA[<p>Das von Janjan gebrachte Beispiel, was als Beispiel für unleserlichen Code gedacht war, empfinde ich übrigens als sehr leserlich und auf den ersten Blick verstädnlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907368</guid><dc:creator><![CDATA[......]]></dc:creator><pubDate>Sat, 05 Jun 2010 16:09:59 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 16:40:06 GMT]]></title><description><![CDATA[<p>Mir fällt da immer wieder SQL als Beispiel ein:</p>
<pre><code class="language-cpp">sql_ressource sql(&quot;www.my_sql_server.com&quot;);
std::vector&lt;std::string&gt; result = sql.select(&quot;*&quot;).from(&quot;users&quot;).where(&quot;client_id&quot;).equals(45).asc();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907384</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Sat, 05 Jun 2010 16:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 16:41:12 GMT]]></title><description><![CDATA[<p>...... schrieb:</p>
<blockquote>
<p>Wie immer, gibt es immer Vor- und Nachteile. Es gibt Situationen, da machen solche Konstrukte Sinn.</p>
<pre><code class="language-cpp">myList.Add(&quot;Bla&quot;)
      .Add(&quot;Blub&quot;)
      .Add(&quot;Foo&quot;);
</code></pre>
</blockquote>
<p>Ad aCTa schrieb:</p>
<blockquote>
<p>Mir fällt da immer wieder SQL als Beispiel ein:</p>
<pre><code class="language-cpp">sql_ressource sql(&quot;www.my_sql_server.com&quot;);
std::vector&lt;std::string&gt; result = sql.select(&quot;*&quot;).from(&quot;users&quot;).where(&quot;client_id&quot;).equals(45).asc();
</code></pre>
</blockquote>
<p>Und beide Beispiele sind nicht treffend, da es hier eindeutig um Setter geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907386</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Sat, 05 Jun 2010 16:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:05:07 GMT]]></title><description><![CDATA[<p>Ad aCTa schrieb:</p>
<blockquote>
<p>Mir fällt da immer wieder SQL als Beispiel ein:</p>
<pre><code class="language-cpp">sql_ressource sql(&quot;www.my_sql_server.com&quot;);
std::vector&lt;std::string&gt; result = sql.select(&quot;*&quot;).from(&quot;users&quot;).where(&quot;client_id&quot;).equals(45).asc();
</code></pre>
</blockquote>
<p>Hi,<br />
darf ich fragen aus welchem wrapper oder gar library/framework der Ausschnitt stammt.<br />
Sieht nämlich ganz interessant aus.<br />
Gruß Gate.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907392</guid><dc:creator><![CDATA[Gate]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:05:07 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:10:12 GMT]]></title><description><![CDATA[<p>Gate schrieb:</p>
<blockquote>
<p>Ad aCTa schrieb:</p>
<blockquote>
<p>Mir fällt da immer wieder SQL als Beispiel ein:</p>
<pre><code class="language-cpp">sql_ressource sql(&quot;www.my_sql_server.com&quot;);
std::vector&lt;std::string&gt; result = sql.select(&quot;*&quot;).from(&quot;users&quot;).where(&quot;client_id&quot;).equals(45).asc();
</code></pre>
</blockquote>
<p>Hi,<br />
darf ich fragen aus welchem wrapper oder gar library/framework der Ausschnitt stammt.<br />
Sieht nämlich ganz interessant aus.<br />
Gruß Gate.</p>
</blockquote>
<p>Ja, vor allem wenn man sich die Alternative anschaut, so einen SQL-String selber tippen zu müssen. Ich habs eben Testhalber für obige Abfrage mal gemacht und war überrascht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907395</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:10:12 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:32:58 GMT]]></title><description><![CDATA[<p>Wie sieht dann sowas aus?</p>
<pre><code>select name from employee where employeeID not in (select employeeID from assignment)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907408</guid><dc:creator><![CDATA[hhhhmmmm]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:32:58 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:44:08 GMT]]></title><description><![CDATA[<p>hhhhmmmm schrieb:</p>
<blockquote>
<p>Wie sieht dann sowas aus?</p>
<pre><code>select name from employee where employeeID not in (select employeeID from assignment)
</code></pre>
</blockquote>
<p>Vielleicht</p>
<pre><code class="language-cpp">select(&quot;name&quot;).from(&quot;employee&quot;).where(&quot;employeeID&quot;).notIN(sql.select(&quot;employeeED&quot;).from(&quot;assignment&quot;));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907410</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:44:08 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:38:31 GMT]]></title><description><![CDATA[<p>Es könnte so aussehen.</p>
<pre><code class="language-cpp">sql.select(&quot;name&quot;)
   .from(&quot;employee&quot;)
   .where(&quot;employeeID&quot;).notin()
      .select(&quot;employeeID&quot;)
      .from(&quot;assignment&quot;)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1907411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907411</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:47:17 GMT]]></title><description><![CDATA[<p>Verhinder der Compiler dann sowas?</p>
<pre><code class="language-cpp">sql.where(&quot;dfs&quot;).select(&quot;*&quot;).equal(&quot;dsfsfs&quot;).from(&quot;f&quot;);
</code></pre>
<p>Oder wird das sogar noch &quot;richtig&quot; ausgeführt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907418</guid><dc:creator><![CDATA[hhhhmmmm]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:47:17 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:49:58 GMT]]></title><description><![CDATA[<p>hhhhmmmm schrieb:</p>
<blockquote>
<p>Verhinder der Compiler dann sowas?</p>
<pre><code class="language-cpp">sql.where(&quot;dfs&quot;).select(&quot;*&quot;).equal(&quot;dsfsfs&quot;).from(&quot;f&quot;);
</code></pre>
<p>Oder wird das sogar noch &quot;richtig&quot; ausgeführt?</p>
</blockquote>
<p>Wie soll der Compiler es verhindern? Es sind nur Strings. Wenn es falsch Information kommt es dann zur ein Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907419</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:49:58 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 17:50:58 GMT]]></title><description><![CDATA[<p>hhhhmmmm schrieb:</p>
<blockquote>
<p>Verhinder der Compiler dann sowas?</p>
<pre><code class="language-cpp">sql.where(&quot;dfs&quot;).select(&quot;*&quot;).equal(&quot;dsfsfs&quot;).from(&quot;f&quot;);
</code></pre>
<p>Oder wird das sogar noch &quot;richtig&quot; ausgeführt?</p>
</blockquote>
<p>Der Biblitheksschreiber kann es verhindern, muß es aber nicht verhindern.<br />
Normalerweise wird er es verhindern mit den selben Mitteln mit denen er zum Beispiel vergessene From-Clauses verhindert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907420</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907420</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 05 Jun 2010 17:50:58 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 18:13:41 GMT]]></title><description><![CDATA[<p>Naja, wenn es einen Compileerror geben würde, wäre es natürlich schon praktisch, aber dann müsste select() nicht sql_ressource sondern was anderes zurück geben und das könnte sehr aufwendig werden für den Biblitheksschreiber. Man kann natürlich auch zur Laufzeit eine Exception werfen, aber dann kann ich das Statement auch so hinschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907437</guid><dc:creator><![CDATA[hhhhmmmm]]></dc:creator><pubDate>Sat, 05 Jun 2010 18:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 21:01:21 GMT]]></title><description><![CDATA[<p>Mit genügend Aufwand, kann man das durchaus schaffen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907487</guid><dc:creator><![CDATA[_)_)_)_)]]></dc:creator><pubDate>Sat, 05 Jun 2010 21:01:21 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sat, 05 Jun 2010 21:20:33 GMT]]></title><description><![CDATA[<p>So viel Aufwand wäre das vielleicht gar nicht. Man müsste sich einige Zwischenklassen ausdenken, welche Funktionen mit passendem Rückgabetyp bereitstellen. Ich meine, falls man den Fehler zur Laufzeit abfangen will, muss man auch nicht gerade wenig Code schreiben. Möglicherweise ist der sogar komplizierter.</p>
<p>Aber kann auch sein, dass ich das völlig falsch einschätze, es ist mehr eine spontane Vermutung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907496</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 05 Jun 2010 21:20:33 GMT</pubDate></item><item><title><![CDATA[Reply to Designfrage: Setter -&amp;gt; return *this? on Sun, 06 Jun 2010 08:26:27 GMT]]></title><description><![CDATA[<p>Schwierig könnte es werden, wenn bestimmte Sachen nur in nem größeren Kontext erlaubt sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1907598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1907598</guid><dc:creator><![CDATA[hhhhmmmm]]></dc:creator><pubDate>Sun, 06 Jun 2010 08:26:27 GMT</pubDate></item></channel></rss>