<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>kera.name Articles</title>
	<atom:link href="http://kera.name/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://kera.name/articles</link>
	<description>tomalak's occasional commentary on Internet, PHP, TV and Life</description>
	<pubDate>Tue, 07 Sep 2010 04:41:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Tomalak&#039;s Tuesday Tip #8: Outsmarting Static Initialization</title>
		<link>http://kera.name/articles/2010/09/tomalaks-tuesday-tip-8-outsmarting-static-initialization/</link>
		<comments>http://kera.name/articles/2010/09/tomalaks-tuesday-tip-8-outsmarting-static-initialization/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 04:41:58 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Tuesday Tip]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=551</guid>
		<description><![CDATA[Right or wrong, it's still trendy in some C++ circles to use the singleton pattern for defining a type that can only be instantiated at most once in an execution run. However, this can cause problems when you bring more static data into the mix.]]></description>
			<content:encoded><![CDATA[<p>Right or wrong, it&#039;s still trendy in some C++ circles to use the singleton pattern for defining a type that can only be instantiated at most once in an execution run. An example might be a god class that manages the top-level of your framework:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct Kernel {
     
     /** .. useful code here .. **/
  
     static Kernel&#038; getInstance() {
          return instance;
     }
   
  private:
     Kernel() {};
     static Kernel instance;
};

Kernel Kernel::instance;</textarea>
<p>The constructor is private, so nobody can outright just instantiate a Kernel instance; in the meantime, the <code>Kernel::getInstance()</code> function will give you access to the static member Kernel instance that&#039;s created once during static initialisation.</p>
<p><b>Problem</b></p>
<p>However, this can cause problems when you bring more static data into the mix. Consider the following example:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct Kernel {
     
     std::map<int, int> m;
     
     static Kernel&#038; getInstance() {
          return instance;
     }
     
  private:
     Kernel() {};
     static Kernel instance;
};

struct Utility {
     Utility() {
          Kernel::getInstance().m[0] = 1;
     }
};

Kernel Kernel::instance;
Utility utility;</textarea>
<p>Because the Kernel instance is created before the Utility instance&#039;s constructor is invoked, this is safe.</p>
<p>But if we flip the static initialisation order of the two objects, then we&#039;re trying to use a data member inside Kernel that hasn&#039;t been initialised yet:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct Kernel {
     
     std::map<int, int> m;
     
     static Kernel&#038; getInstance() {
          return instance;
     }
     
  private:
     Kernel() {};
     static Kernel instance;
};

struct Utility {
     Utility() {
          Kernel::getInstance().m[0] = 1;
          // ^ the map does not yet exist;
          //   the [] operation is UB and may
          //   very well segfault.
     }
};

Utility utility;
Kernel Kernel::instance;</textarea>
<p>Worse, if your Utility and Kernel instances are defined in difference Translation Units (loosely corresponding to <code>.cpp</code> source files in most projects), then their order of initialisation is completely non-guaranteed. It&#039;s pot luck as to whether your &#034;simple&#034; code will function at all.</p>
<p><b>Solution</b></p>
<p>It may seem contrived but this pattern has been seen in production code. To get around this issue when one static object depends on another static object, you can instead rely on the create-on-demand semantics of <i>function-statics</i> (an altogether different feature of the language):</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct Kernel {
     
     std::map<int, int> m;
     
     static Kernel&#038; getInstance() {
          
          static Kernel instance;
          // ^ this is guaranteed to be created when we
          //   first need it, and to never be re-created.
          
          return instance;
     }
     
  private:
     Kernel() {};
};

struct Utility {
     Utility() {
          Kernel::getInstance().m[0] = 1;
          // ^ the Kernel instance and its map will be
          //   created by the first getInstance() call.
     }
};

Utility utility;</textarea>
<p>In fact, in general it&#039;s best to try to avoid relying on static data members as these sorts of errors can go unnoticed for some time, and exerting control over C++&#039;s static initialisation order is the sort of magic trickery left to gremlins and hyperdimensional beings.</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/09/tomalaks-tuesday-tip-8-outsmarting-static-initialization/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tomalak&#039;s Tuesday Tip #7: Improving Windows 7</title>
		<link>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-7-improving-windows-7/</link>
		<comments>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-7-improving-windows-7/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 12:10:07 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Tuesday Tip]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=539</guid>
		<description><![CDATA[This week I explore how, after struggling with my Windows 7 grinding to a halt over the last few months, I finally managed to get it up to speed again.]]></description>
			<content:encoded><![CDATA[<p><img src="http://kera.name/articles/wp-content/uploads/2010/09/windows-logo.png" alt="" title="windows-logo" width="150" height="134" style="float: right" />After struggling with my Windows 7 grinding to a halt over the last few months, I finally managed to get it up to speed again. Although some of the suggestions below may seem obvious, I&#039;ve selected them from a longer list as my recommendations for the four best ways to speed up your Windows 7 installation.</p>
<p><strong>Number Four</strong></p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/09/windows_media_player_jumplist.png" alt="" title="windows_media_player_jumplist" width="320" height="271" class="aligncenter size-full wp-image-542" /></p>
<p><a href="http://www.tweakwin7.com/articles/39447/disable-taskbar-jump-lists/">Disable the taskbar &#034;jump lists&#034;</a> to see a small improvement in the responsiveness of the taskbar in general. I never open &#034;recent items&#034; from a jumplist, mainly because I keep my favourite applications (<a href="http://www.mirc.com">mIRC</a>, <a href="http://www.mozillamessaging.com/en-GB/thunderbird/">Thunderbird</a>, my media player, <a href="http://notepad-plus-plus.org/">Notepad++</a> and <a href="http://www.mozilla-europe.org/en/firefox/">Firefox</a>) open at all times anyway. </p>
<p><strong>Number Three</strong></p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/09/libraries.png" alt="" title="libraries" width="149" height="275" class="aligncenter size-full wp-image-543" /></p>
<p><a href="http://www.askvg.com/how-to-disable-libraries-feature-in-windows-7/">Disable Explorer&#039;s &#034;libraries&#034;</a> to speed up Explorer loads. Even if you use a shell replacement (like the fantastic <a href="http://www.gpsoft.com.au/">Directory Opus</a>), you&#039;re still using Explorer for things like &#034;Save As&#8230;&#034; dialogs.</p>
<p><strong>Number Two</strong></p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/09/windows-7-homegroup-300x225.jpg" alt="" title="windows-7-homegroup-300x225" width="300" height="225" class="aligncenter size-full wp-image-544" /></p>
<p><a href="http://www.askvg.com/how-to-disable-homegroup-feature-in-windows-7/">Disable Explorer&#039;s &#034;homegroup&#034;</a> to yield the biggest speed benefits in launching Explorer instances. I don&#039;t need to interface with two system services to choose where to save a photo from <a href="http://imgur.com/gallery/">imgur.com</a>, thank you.</p>
<p><strong>Number One</strong></p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/09/clean-up-tool.jpg" alt="" title="clean-up-tool" width="389" height="467" class="aligncenter size-full wp-image-545" /></p>
<p>Delete everything in C:\Users\*\AppData\Local\Temp that&#039;s older than two days and not currently in use. I don&#039;t know whether my hard drive is particularly badly fragmented but I noticed an immediate and significant improvement in general responsiveness.</p>
<p><strong>Bootnote</strong></p>
<p>Let me know if any of these help you!</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-7-improving-windows-7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>It Is Not Called The &#034;STL&#034;, Mmkay?</title>
		<link>http://kera.name/articles/2010/08/it-is-not-called-the-stl-mmkay/</link>
		<comments>http://kera.name/articles/2010/08/it-is-not-called-the-stl-mmkay/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 00:42:34 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=530</guid>
		<description><![CDATA[ I ask everyone to stop using the erroneous term "STL".]]></description>
			<content:encoded><![CDATA[<p>I was reading an article the other day entitled &#034;Adding Perl to Your C++ Applications&#034;, a rather interesting read. However, like so many other sources, it refers to the &#034;STL&#034;, despite the fact that very few people still use the STL (which was designed at SGI). [1]</p>
<p style="text-align: center;"><a href="http://kera.name/articles/wp-content/uploads/2010/08/savelibrary.jpg"><img src="http://kera.name/articles/wp-content/uploads/2010/08/savelibrary.jpg" alt="[4]" title="savelibrary" width="250" height="258" /></a></p>
<p>Parts of the C++ Standard Library were based on parts of the STL, and it is these parts that many people (including several authors and the notoriously error-ridden cplusplus.com) still refer to as &#034;the STL&#034;. However, this is inaccurate; indeed, the C++ standard never mentions &#034;STL&#034;, and there <i>are</i> content differences between the two. [2]</p>
<p>So I am here to ask everyone to stop using the erroneous term &#034;STL&#034;!</p>
<p>Assuming that you are referring to the library that is defined by the C++ standard, the correct terminology is C++ Standard Library and a suitable abbreviation is stdlib, or libstdc++ to cheekily borrow the name of GCC&#039;s implementation.</p>
<p>I [arguably] wouldn&#039;t usually be so pedantic, but this is an extremely prevalent mistake and I am doing everything I can to prevent the new generation of C++ programmers from falling into this trap.</p>
<p>Naturally, there are those who have noticed this disturbing trend as I have, but who disagree that it&#039;s problematic. They tend to argue that language evolves and that the term &#034;STL&#034; has become a popularised and widely-accepted synonym for the current C++ Standard Library. [3]</p>
<p>Were this true then there wouldn&#039;t be much of a practical problem; it&#039;d simply be irritatingly incorrect in the strictest sense. Alas, it&#039;s not. &#034;STL&#034; is rarely used to refer to the bits of the stdlib that happen to be based on the SGI STL. People think it&#039;s the entire standard library. It gets put on CVs. And it is misleading.</p>
<p>As one commenter on Jesper&#039;s article explains:</p>
<blockquote><p>The issue is one of con­fu­sion. Which parts of the stdlib are in the STL? iostream? string? slist and oth­ers in the SGI STL, pro­vided by some imple­men­ta­tions, but not in the stan­dard? Addi­tions from TR1? What about 0x? Even though most peo­ple have very sim­i­lar def­i­n­i­tions, they are all slightly off from each other.</p>
<p>Why not just say &#034;stdlib&#034; if you mean the C++ Stan­dard Library?</p>
<p>How­ever, I some­times do want to talk about the SGI library &mdash; or rather the ideas and idioms it made pop­u­lar in C++, even if not the actual source code.</p></blockquote>
<p>So let&#039;s just stop it!</p>
<p>&#8212;<br />
[1] <a href="http://blob.perl.org/tpc/1998/User_Applications/When%20the%20STL%20Isn%27t%20Enough/paper.html"><em>&#034;When the STL Isn&#039;t Enough: Adding Perl to Your C++ Applications&#034;, Ken Fox, 1998</em></a><br />
[2] <em>C++ as defined by ISO/IEC 14882-1998 &#038; ISO/IEC 14882-2003.</em><br />
[3] <a href="http://jalf.dk/blog/2010/08/stl-language-lawyers-and-pedantry/"><em>&#034;STL, language lawyers and pedantry&#034;, Jes­per Alf Dam, 2010</em></a><br />
&#8212;<br />
<em>Image used with permission<br />
&copy; Elizabeth O. Dulemba, Children&#039;s Book Author/Illustrator<br />
Visit <a href="http://www.dulemba.com">www.dulemba.com</a> to learn more and download more coloring pages.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/08/it-is-not-called-the-stl-mmkay/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tomalak&#039;s Tuesday Tip #6: An Inclusion Pitfall</title>
		<link>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-6-an-inclusion-pitfall/</link>
		<comments>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-6-an-inclusion-pitfall/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 23:06:22 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Tuesday Tip]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=522</guid>
		<description><![CDATA[One of the evilnesses of the C++ Standard Library is that implementations &#8212; be they GCC's libstdc++ or the Dimkumware implementation used by MSVC &#8212; are free to have their headers include other standard headers as much as they like. This can lead to confusion.]]></description>
			<content:encoded><![CDATA[<p>One of the evilnesses of the C++ Standard Library is that implementations &mdash; be they GCC&#039;s libstdc++ or the Dimkumware implementation used by MSVC &mdash; are free to have their headers include other standard headers as much as they like. This can lead to confusion. For example, the oft-given:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">#include <iostream>

int main() {
	std::cout << "Hello world\n";
}</textarea>
<p>This is technically incorrect!</p>
<p>Although the most popular standard library implementations currently <i>just so happen</i> to have an <code>iostream</code> implementation that itself includes <code>ostream</code> (for any internal reason), you should include the header <code>ostream</code> yourself to gain access to <code>ostream</code>&#039;s <code>operator&lt;&lt;</code> that you use above. If one day your toolchain&#039;s code gets restructured and iostream no longer includes <code>ostream</code>, your build will break because you&#039;ve included the wrong header.</p>
<p>Unlikey though it is to be a problem in this specific case, it&#039;s important in general to include precisely the right header for the job according to the documentation, and not one that just seems to work for you at any given time. Even if you don&#039;t care about immediate portability or proper correctness, then at least think about future maintainability.</p>
<p>The corrected snippet reads:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">#include <iostream> // for std::cout
#include <ostream>  // for std::ostream::operator<<

int main() {
	std::cout << "Hello world\n";
}</textarea>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/08/tomalaks-tuesday-tip-6-an-inclusion-pitfall/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Overcoming Name Shadowing In C++</title>
		<link>http://kera.name/articles/2010/08/overcoming-name-shadowing-in-c/</link>
		<comments>http://kera.name/articles/2010/08/overcoming-name-shadowing-in-c/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 18:12:32 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=517</guid>
		<description><![CDATA[I briefly explore a common inheritance gotcha and its usual solution.]]></description>
			<content:encoded><![CDATA[<p>(In the below article, <a href="http://www.eelis.net/geordi/">geordi</a> is used to test snippets. &#034;BARK&#034; is a geordi macro that outputs the function name of the enclosing scope.)</p>
<p>Here I briefly explore a common inheritance gotcha and its usual solution.</p>
<h3>Normal overloading</h3>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int); void lol(string); };</textarea>
<p><code>A::lol(int)</code> and <code>A::lol(string)</code> are actually different functions.</p>
<h3>Overloading with inheritance</h3>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { void lol(string) { BARK; } };
int main() { B b; b.lol("d"); }
//B::lol(string)</textarea>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { void lol(string) { BARK; } };
int main() { B b; b.lol(3); }
//error: no matching function for call to 'B::lol(int)'</textarea>
<p>Here one might expect the second example to work, with the output &#034;A::lol(3)&#034; since the function clearly exists and should be inherited.</p>
<p>But in our example, <code>B::lol(string)</code> hides or &#034;shadows&#034; <code>A::lol(int)</code> so the lookup doesn&#039;t work. Since there is the function with the name &#034;<code>lol</code>&#034; in B, when you try to call <code>b.lol(3)</code> the compiler never bothers to look for other functions with the name &#034;<code>lol</code>&#034; that might be in <code>A</code>.</p>
<p>We could be a bit more explicit with our function call:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { void lol(string) { BARK; } };
int main() { B b; b.A::lol(3); }
//A::lol(int)</textarea>
<p>But that&#039;s a bit minging. It would be nicer to fix the lookup from within the class definition itself. To do so, we must bring <code>A::lol(int)</code> into scope of <code>B</code> with the `using` keyword so that the two functions <code>lol(string)</code> and <code>lol(int)</code> can live side by side in harmony.</p>
<h3>With &#039;using&#039;</h3>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { using A::lol; void lol(string) { BARK; } };
int main() { B b; b.lol("d"); }
//B::lol(string)</textarea>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { using A::lol; void lol(string) { BARK; } };
int main() { B b; b.lol(3); }
//A::lol(int)</textarea>
<p>It doesn&#039;t matter where you put the &#039;using&#039; statement; it won&#039;t ever cancel out <code>B::lol(string)</code>, even if it comes after the function definition:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { void lol(string) { BARK; } using A::lol; };
int main() { B b; b.lol("d"); }
//B::lol(string)</textarea>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(int) { BARK; } };
struct B : A { void lol(string) { BARK; } using A::lol; };
int main() { B b; b.lol(3); }
//A::lol(int)</textarea>
<p>Implicit conversions don&#039;t break this either:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct A { void lol(A*) { BARK; } };
struct B : A { using A::lol; void lol(B*) { BARK; } };
int main() { B b; b.lol((B*)&#038;b); b.lol((A*)&#038;b); }
//B::lol(B*) A::lol(A*)</textarea>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">struct B;
struct A { void lol(B*) { BARK; } };
struct B : A { using A::lol; void lol(A*) { BARK; } };
int main() { B b; b.lol((B*)&#038;b); b.lol((A*)&#038;b); }
//B::lol(A*) A::lol(B*)</textarea>
<p>So there you go.</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/08/overcoming-name-shadowing-in-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tomalak&#039;s Tuesday Tip #5: Synchronous Is Simply Superior</title>
		<link>http://kera.name/articles/2010/06/tomalaks-tuesday-tip-5-synchronous-is-simply-superior/</link>
		<comments>http://kera.name/articles/2010/06/tomalaks-tuesday-tip-5-synchronous-is-simply-superior/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 19:51:07 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Tuesday Tip]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=506</guid>
		<description><![CDATA[One of the most well-known "web 2.0" buzzwords is AJAX ("Asynchronous Javascript And XML") which, properly known as XMLHttpRequest is a mechanism to provoke the retrieval of data from a webserver at times other than the initial loading of a webpage. You see it when your Gmail inbox refreshes, or when you turn the page in a Facebook photo album. Unfortunately, AJAX is somewhat misunderstood.]]></description>
			<content:encoded><![CDATA[<p>One of the most well-known &#034;web 2.0&#034; buzzwords is AJAX (&#034;Asynchronous Javascript And XML&#034;) which, properly known as XMLHttpRequest, is a mechanism to provoke the retrieval of data from a web server at times other than the initial loading of a page. You see it when your Gmail inbox refreshes, or when you turn the page in a Facebook photo album.</p>
<p>Unfortunately, AJAX is somewhat misunderstood by web application developers.</p>
<p>Synchronous XMLHttpRequests are those whereby your browser makes the data request to the server, then waits for a response, then continues with the script. Asynchronous requests, on the other hand, involve firing off the request, then carrying on with the script and with the general operation of the browser; when the server responds, a callback function is invoked. This could be seconds later or even never at all in the worst case.</p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/06/firebugxmloptions_1.jpg" alt="" title="firebugxmloptions_1" width="201" height="185" style="float: right;" />The thing is, AJAX requests are rarely actually asynchronous, though many people insist upon calling every AJAX invocation &#034;asynchronous&#034; when in fact we mostly use synchronous calls. A better term would be &#034;inline&#034; requests.</p>
<p>The myth that synchronous calls add unnecessary delay to a web application is just that: a myth. In fact, most of the time, asynchronicity breaks a GUI. You usually have (a) no reason (b) no desire (c) specific reason not to allow multiple GUI responses at once; you want one button click to be handled before the next is noticed. This is because when a user presses button A they expect the result to occur &mdash; along with any side-effects &mdash; before the result of pressing button B is calculated, even if they press button B before the behind-the-scenes calculations of pressing button A are completed. It&#039;s human nature to expect linear procedurality, and breaking this expectation can lead to obscure bugs due to a discrepancy between the application&#039;s state on the server and its state in the GUI.</p>
<p>Unfortunately the obsession with &#034;speed&#034; and &#034;efficiency&#034; (which in reality are completely irrelevant here, but still) leads people to assume that they always want asynchronous calls, which may at times give the false impression of making an interface &#034;faster&#034; or &#034;more responsive&#034; when in fact usually they&#039;re simply incorrect and poorly designed.</p>
<p>I&#039;ll leave you to come up with your own examples and explore this idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/06/tomalaks-tuesday-tip-5-synchronous-is-simply-superior/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tomalak&#039;s Friday Fervent Opinion #1: Tabs Over Spaces</title>
		<link>http://kera.name/articles/2010/05/tomalaks-friday-fervent-opinion-1-tabs-over-spaces/</link>
		<comments>http://kera.name/articles/2010/05/tomalaks-friday-fervent-opinion-1-tabs-over-spaces/#comments</comments>
		<pubDate>Fri, 28 May 2010 13:49:56 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Friday Fervent Opinion]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=489</guid>
		<description><![CDATA[A programmer friend recently revealed that his company has a strict no-tabs policy, and that they are forced to use space indentation... at no fewer than eight spaces. This makes me sad. I explain why.]]></description>
			<content:encoded><![CDATA[<p>A programmer friend recently revealed that his company has a strict no-tabs policy, and that they are forced to use space indentation&#8230; at no fewer than eight spaces. This makes me sad.</p>
<p>The spaces vs tabs debate is an age-old one, with proponents on both sides fighting the cause as avidly as in the editor wars, browser wars, language wars and probably a bunch of others.</p>
<p>The spaces people argue that indentation should be applied by repeatedly pressing the spacebar key a certain, consistent number of times:</p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/05/spaces.png" alt="" title="spaces" width="400" height="383" class="alignnone size-full wp-image-499" /></p>
<p>The tabs people, on the other hand, believe in pressing the tab key just once. This makes the next character align vertically to the next tab stop:</p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/05/tabs.png" alt="" title="tabs" width="400" height="378" class="alignnone size-full wp-image-498" /></p>
<p>Personally I like to see code with its indents at 4-character widths, and when code has been indented nice and atomically with one tab per indent level, I can configure my editor to make that happen. When I make changes to the code and save it, the tabs are still there in place so the next reader could view it with tabs at 8-character widths.</p>
<p>With spaces, if I wanted to see a different amount of indentation I&#039;d have to go through every line and add/remove spaces as required, and then that change would affect all other viewers of the code. It would also involve pointless updates to a version control repository.</p>
<p>Which do you use? If tabs, how far apart are your tab stops when you code? (For indentation, that is, which is the only time you should use them.) If spaces, can you explain the benefit to me? Please?</p>
<hr /><b>Update:</b> Setting your client to insert multiple space characters when you hit the &#039;tab&#039; key does not count. It&#039;s just a keyboard shortcut; you&#039;re still inserting space characters into your code that render a fixed, hard-coded amount of spacing.</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/05/tomalaks-friday-fervent-opinion-1-tabs-over-spaces/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Society Demands Privacy In Public, Pisses Me Off</title>
		<link>http://kera.name/articles/2010/05/society-demands-privacy-in-public-pisses-me-off/</link>
		<comments>http://kera.name/articles/2010/05/society-demands-privacy-in-public-pisses-me-off/#comments</comments>
		<pubDate>Thu, 27 May 2010 10:40:47 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=480</guid>
		<description><![CDATA[If like me you lament the passing of the days when Facebook was just a tool used by twenty-somethings to post photos and have the odd flirty wallpost conversation with friends, you'll be at least partially as saddened as I to see it in the big news once again. And, once again, it's over "privacy".]]></description>
			<content:encoded><![CDATA[<p><img src="http://kera.name/articles/wp-content/uploads/2006/09/facebook-logo.gif" alt="" title="Facebook logo" width="157" height="33" style="float: right;" />If like me you lament the passing of the days when Facebook was just a tool used by twenty-somethings to post photos and have the odd flirty wallpost conversation with friends, you&#039;ll be at least partially as saddened as I to see it in the big news once again. And, once again, it&#039;s over &#034;privacy&#034;.</p>
<p>Let me start by asserting that the word &#034;privacy&#034; is vastly overused these days; in fact, it&#039;s not just that news outlets and newbs have the seven letters on reflex action speed dial, but that in most cases the concept of privacy is misapplied.</p>
<p>I shan&#039;t delve into detail on this point, but I continue to exist in a state of bemusement that thousands of teenagers, students and greying parents are publishing in what is essentially designed to be a public and largely open medium&#8230; then turning around and accusing that medium of somehow breaking the rules. In fact, I suspect it&#039;s more often the case that by the time it&#039;s clear that you&#039;ve published that drunk status message directly to your boss, colleagues, grandmother and ex-girlfriend, it&#039;s too late to realise that social networking is <em>not</em> about private communication but about public broadcast. You wouldn&#039;t project images of your face onto every building in Lenton, then complain that people had looked at them; &#034;privacy&#034; has very little to do with it.</p>
<p>Anyway, the news is that Mark Zuckerberg &mdash; the software developer who took a great product, capitalised on luck and market demand, and then turned the product into a steaming pile of rotting vegetables &mdash; has <a href="http://news.bbc.co.uk/1/hi/technology/10167143.stm" title="BBC News - Facebook reveals 'simplified' privacy changes">promised to revamp Facebook&#039;s privacy settings</a> amidst complaints that they have become &#034;too complex&#034; for users.</p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/05/computer-privacy.jpg" alt="" title="computer-privacy" width="180" height="131" style="float: right;" />But for every change mentioned &mdash; the settings grids, the blanket application controls, the new defaults &mdash; there&#039;s a paragraph about how Facebook &#034;may not have gone far enough&#034;. How much further can you go? And in which direction? If you add more controls, then you&#039;ve broken the idea of reducing the issue&#039;s complexity; if you remove controls, you run the risk of giving users far <em>less</em> control.</p>
<p>In fact, there is nothing wrong with Facebook&#039;s existing configurability (and it&#039;s good to read that those existing controls will still be available in some form). The real problem is that the untrained don&#039;t actually use the controls, because they can&#039;t be bothered to learn how to use them. As said Simon Davies, the director of Privacy International, &#034;the vast majority of people don&#039;t use privacy settings so the reforms are not likely to have as great an impact&#034;. It&#039;s far easier to expect Facebook to automatically determine, by reading your mind, exactly who should see what whilst you continue to voluntarily and openly reveal your most intimate daily secrets to the world.</p>
<p>What I really want to see is less complaining about the options on the privacy settings page and blaming Facebook for drunken messages distributed over the internet, and more personal responsibility. Internet applications, like most human inventions, are complicated tools the use of which must be learned. Unfortunately, society as a whole currently seems sadly ignorant to this idea, instead reliant on blaming service and infrastructure providers for not making things simple, complex, lightweight, comprehensive, automatic and fully configurable all at the same time.</p>
<p>The article I&#039;ve linked to ends with the very helpful, well-reasoned and informative paragraph:</p>
<blockquote><p>The European Commission described the changes as &#034;unacceptable&#034;.</p></blockquote>
<p>Excellent; thanks for that.</p>
<p><img src="http://kera.name/articles/wp-content/uploads/2010/05/_47929505_facebook_privacy466.jpg" alt="" title="_47929505_facebook_privacy466" width="400" height="271" class="alignnone size-full wp-image-483" /></p>
<p><strong>Bootnote</strong></p>
<p>Zuckerberg&#039;s claim that &#034;we don&#039;t sell your information and we have no plans to,&#034; while intended to allay fears that specific personal information may be clandestinely and explicitly sold for profit, is ironic given that Facebook makes its operational revenue from advertising on a site that actually exists based on the provision of information. In a <em>sense</em>, selling information is the company&#039;s entire business model.</p>
<p>Apparently Mark told BBC News that it was a &#034;misconception&#034; that the site relies on people sharing information to make money from adverts, but anyone who&#039;s used Facebook knows that the ads are tailored to what&#039;s on your profile&#8230; especially if your profile&#039;s just been banterously &#039;hacked&#039; by mates who&#039;ve changed all your listed interests to choices considerably less savoury than what they were originally.</p>
<p><a href="http://www.toothpastefordinner.com/archives/2008/Aug/"><img src="http://kera.name/articles/wp-content/uploads/2010/05/online-privacy-advocate.jpg" alt="toothpastefordinner.com" title="online-privacy-advocate" width="400" height="262" class="size-full wp-image-482" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/05/society-demands-privacy-in-public-pisses-me-off/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tomalak&#039;s Monday Monstrous Rant #1: Align Your Asterisks!</title>
		<link>http://kera.name/articles/2010/05/tomalaks-monday-monstrous-rant-i-align-your-asterisks/</link>
		<comments>http://kera.name/articles/2010/05/tomalaks-monday-monstrous-rant-i-align-your-asterisks/#comments</comments>
		<pubDate>Mon, 17 May 2010 10:03:43 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Monday Monstrous Rant]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=478</guid>
		<description><![CDATA[I address the age-old debate of C and C++; which pointer initialisation syntax to use?]]></description>
			<content:encoded><![CDATA[<p>Hi. I&#039;m here to address the age-old debate of C and C++; which pointer initialisation syntax to use?</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">Foo* ptr; // (1)
Foo * ptr; // (2)
Foo *ptr; // (3)</textarea>
<p>All three are equivalent because arbitrary spacing is meaningless in C/C++.</p>
<p>The problem with C and C++ is that its built-in operators have multiple meanings. In particular <code>*</code> means &#034;pointer type&#034;, &#034;multiplication&#034; and &#034;dereference&#034;. My goal when picking a convention is to, as much as possible, avoid using one that jars with another.</p>
<p>Therefore, we&#039;ll ignore syntax 2 because it looks so much like multiplication.</p>
<p>Unfortunately, there is no clear winner between the other two as each has at least one hindrance. Syntax 1 has the following:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">Foo* ptr1, ptr2;</textarea>
<p>In the code above, <code>ptr1</code> is a <code>Foo*</code>, but <code>ptr2</code> is only a <code>Foo</code>. One might have expected both to be <code>Foo*</code>s. Syntax 3 avoids this by keeping the asterisk with the name:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">Foo *ptr1, *ptr2;</textarea>
<p>This is really a throwback to C&#039;s desire to have you think in terms of &#034;I am declaring a <code>Foo</code> to which <code>ptr</code> points&#034;.</p>
<p>Unfortunately, this is misleading to language newcomers because in fact you&#039;re not declaring or defining a <code>Foo</code> at all. You&#039;re merely declaring a pointer; you still haven&#039;t allocated any actual <code>Foo</code> for it to point to.</p>
<p>A newbie reading &#034;<code>int *a</code>&#034; might think he&#039;s created an <code>int</code> and now gets to use &#034;the variable <code>*a</code>&#034; to access it, when in fact this is not the case at all; dereferencing such an undirected pointer would be very dangerous.</p>
<p>Further, aligning the asterisk with the variable name looks like a dereference operation. One of the biggest stumbling blocks to language newcomers is the multiple meaning of operators such as <code>*</code> and <code>&amp;</code> &mdash; learning the difference between <code>*</code> on the LHS as a pointer type indicator and <code>*</code> on the RHS as a dereference operator is not aided if you see code that always aligns the asterisk in the same way.</p>
<p>Additionally, the name of the type itself is &#034;<code>Foo*</code>&#034; (though array declaration and function type declaration syntax oddities do make this slightly more complicated in practice).</p>
<p>To summarise:</p>
<table width="100%" border="1" cellspacing="0">
<tr>
<th>Rationale</th>
<th>#1</th>
<th>#2</th>
<th>#3</th>
</tr>
<tr>
<td>Indicates the type properly</td>
<td style="background-color: green">&nbsp;</td>
<td style="background-color: red">&nbsp;</td>
<td style="background-color: red">&nbsp;</td>
</tr>
<tr>
<td>Not surprising when declaring multiple variables</td>
<td style="background-color: red">&nbsp;</td>
<td style="background-color: white">&nbsp;</td>
<td style="background-color: green">&nbsp;</td>
</tr>
<tr>
<td>Does not lie about allocation</td>
<td style="background-color: green">&nbsp;</td>
<td style="background-color: white">&nbsp;</td>
<td style="background-color: red">&nbsp;</td>
</tr>
<tr>
<td>Doesn&#039;t look like dereference</td>
<td style="background-color: green">&nbsp;</td>
<td style="background-color: green">&nbsp;</td>
<td style="background-color: red">&nbsp;</td>
</tr>
<tr>
<td>Doesn&#039;t look like multiplication</td>
<td style="background-color: green">&nbsp;</td>
<td style="background-color: red">&nbsp;</td>
<td style="background-color: green">&nbsp;</td>
</tr>
</table>
<p>In conclusion:</p>
<p><code>Foo *p</code> is rubbish; it has three cons and two pros. <code>Foo* p</code> is great; it has one con and four pros&#8230; important pros.</p>
<p>Thanks for reading.</p>
<p><strong>Updated 31/07/2010:</strong> Improved table layout for clarity.</p>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2010/05/tomalaks-monday-monstrous-rant-i-align-your-asterisks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C++ Variable Initialisation: How To Do It Properly</title>
		<link>http://kera.name/articles/2009/12/c-variable-initialisation-how-to-do-it-properly/</link>
		<comments>http://kera.name/articles/2009/12/c-variable-initialisation-how-to-do-it-properly/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 01:22:42 +0000</pubDate>
		<dc:creator>Tomalak Geret'kal</dc:creator>
		
		<category><![CDATA[Uncategorised]]></category>

		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://kera.name/articles/?p=469</guid>
		<description><![CDATA[I compare several approaches to object initialisation in C++.]]></description>
			<content:encoded><![CDATA[<p>There are two main ways to declare and initialise variables with automatic or static storage in C++: with <code>`='</code>; and with parentheses.</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">int x = 3;
int y(3);</textarea>
<p>Some C++ programmers prefer to use copyconstructor-style initialisation syntax for clarity because it is the copy constructor that&#039;s invoked in both cases, <em>not</em> the assignment operator as one might expect from the use of the equals sign.</p>
<p>But I think clarity is the complete opposite of what you get. It can cause problems where you do not expect them, leading to complicated diagnostics:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">int main() {
  int x(int());
  std::cout << x;
}

// error: undefined reference to 'x(int (*)())'</textarea>
<p>Although the linker error makes sense if you know that you have declared a function and never defined it, the diagnostic does not really help you fix the problem if you did not see this coming and expected <code>x</code> to be equal to 0.</p>
<p><em>&#034;Wait, what. I&#039;ve declared a function?&#034;</em></p>
<p>Yep! The only difference between a function declaration <code>int(T)</code> and a temporary construction <code>int(x)</code> is that <code>T</code> is a type whereas <code>x</code> is an expression. So:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">
// initialises a to value of temporary int 0
int a = int();

// initialises b to value of temporary int 3
int b = int(3);

// initialises c to value of temporary int 3
int c(int(3));

// fail: declares a function d taking a {function
// taking a T and returning int} and returning int
int d(int(T));

// fail: declares a function e taking a {nullary
// function returning int} and returning int
int e(int());</textarea>
<p>In the last case above, because the <code>int()</code> has nothing inside the parentheses it can be parsed as either, and function declaration is always assumed in C++ where it&#039;s possible.</p>
<p>There are plenty of cases where a type simply cannot be in a situation like this, and in the other cases you can hack around it by forcing the declaration to become an expression with extra parentheses:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">int x((int()));</textarea>
<p>Still, even if just because of this, I avoid &#034;<code>int x(3);</code>&#034; and instead prefer good-old equals-syntax which, although it doesn&#039;t actually invoke the assignment operator, at least does what it says it does: it declares and initialises an integer variable called <code>x</code>, equal to 3:</p>
<textarea name="code" class="cpp:nocontrols:nogutter" cols="60" rows="10">int x = 3;</textarea>
<p>Stick to this syntax and you won&#039;t have any trouble; problem solved. <img src='http://kera.name/articles/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><b>Further reading</b></p>
<ul>
<li><a href="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.19">[10] Constructors Updated! , C++ FAQ Lite</a></li>
<li><a href="http://yosefk.com/c++fqa/ctors.html#fqa-10.19">C++ FQA Lite: Constructors</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://kera.name/articles/2009/12/c-variable-initialisation-how-to-do-it-properly/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
