<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ejohansson.se &#187; qt</title>
	<atom:link href="http://ejohansson.se/tags/qt/feed/" rel="self" type="application/rss+xml" />
	<link>http://ejohansson.se</link>
	<description>Random bits about Linux, programming, computers and occasionally other stuff.</description>
	<lastBuildDate>Sun, 18 Apr 2010 20:23:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Qt programming in&#160;Lisp</title>
		<link>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/</link>
		<comments>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/#comments</comments>
		<pubDate>Tue, 18 Apr 2006 17:11:29 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[qt]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/</guid>
		<description><![CDATA[We all know the following facts: Qt is good; Lisp is good. So when I found the Lisp Qt4 bindings I knew it had to be good. I have &#8211; of course &#8211; not tried it (yet), but I like the concept. And there&#8217;s nothing like judging by appearance. Plus, good + good must equal [...]]]></description>
			<content:encoded><![CDATA[<p>We all know the following facts: Qt is good; Lisp is good. So when I found the <a href="http://members.aon.at/lispolos/">Lisp Qt4 bindings</a> I knew it had to be good. I have &#8211; of course &#8211; not tried it (yet), but I like the concept. And there&#8217;s nothing like judging by appearance. Plus, good + good must equal good. Just look at milk and beer&#8230; or umm&#8230; *cough*</p>
<p>While on the subject, I have to remember to try <a href="http://developer.kde.org/language-bindings/ruby/index.html">Korundum</a> when I get back to Linköping.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using booleans to document&#160;code</title>
		<link>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/</link>
		<comments>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/#comments</comments>
		<pubDate>Sun, 09 Apr 2006 16:12:09 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/</guid>
		<description><![CDATA[Today I want to share a tip on how to write self-documenting code that I picked up from the book Code Complete 2 by Steve McConnell. I will do this be showing you some code I just wrote, but let us start with the actual tip. Instead of merely testing a boolean expression, you can [...]]]></description>
			<content:encoded><![CDATA[<p>Today I want to share a tip on how to write self-documenting code that I picked up from the book <a href="http://www.amazon.com/gp/product/0735619670/">Code Complete 2</a> by Steve McConnell. I will do this be showing you some code I just wrote, but let us start with the actual tip.</p>
<blockquote cite="http://www.cc2e.com/" title="Steve McConnell"><p>
Instead of merely testing a boolean expression, you can assign the expression to a variable that makes the implication of the test unmistakable.
</p></blockquote>
<p>The following code was my first try, not employing the tip.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp-qt" style="font-family:monospace;"><span style="color: #0057AE;">void</span> CETabWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">wheelEvent</span><span style="color: #006E28;">&#40;</span><span style="color: #22aadd;">QWheelEvent</span> <span style="color: #006E28;">*</span>e<span style="color: #006E28;">&#41;</span>
<span style="color: #006E28;">&#123;</span>
  <span style="color: #22aadd;">QTabBar</span> <span style="color: #006E28;">*</span>tabs <span style="color: #006E28;">=</span> tabBar<span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">||</span> e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&gt;</span> <span style="color: #006E28;">&#40;</span>tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> tabs.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span>
    e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">ignore</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
    return<span style="color: #006E28;">;</span>
  <span style="color: #006E28;">&#125;</span>
&nbsp;
  <span style="color: #888888;">// handle wheel event</span>
<span style="color: #006E28;">&#125;</span></pre></div></div>

<p>Even though I wrote the code myself, I have problems understanding it. And making sure it&#8217;s correct takes more than a quick glance. If you want to understand this code in six months, you have to add a comment. So let us take a look at the same code rewritten to use two extra booleans.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp-qt" style="font-family:monospace;"><span style="color: #0057AE;">void</span> CETabWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">wheelEvent</span><span style="color: #006E28;">&#40;</span><span style="color: #22aadd;">QWheelEvent</span> <span style="color: #006E28;">*</span>e<span style="color: #006E28;">&#41;</span>
<span style="color: #006E28;">&#123;</span>
  <span style="color: #22aadd;">QTabBar</span> <span style="color: #006E28;">*</span>tabs <span style="color: #006E28;">=</span> tabBar<span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #0057AE;">const</span> <span style="color: #0057AE;">bool</span> cursorAboveTabBar <span style="color: #006E28;">=</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #0057AE;">const</span> <span style="color: #0057AE;">bool</span> cursorBelowTabBar <span style="color: #006E28;">=</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&gt;</span> <span style="color: #006E28;">&#40;</span>tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>cursorAboveTabBar <span style="color: #006E28;">||</span> cursorBelowTabBar<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span>
    e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">ignore</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
    return<span style="color: #006E28;">;</span>
  <span style="color: #006E28;">&#125;</span>
&nbsp;
  <span style="color: #888888;">// handle wheel event</span>
<span style="color: #006E28;">&#125;</span></pre></div></div>

<p>Now you can quickly figure out that the wheel event is only handled if the cursor is inside the tabBar. And it&#8217;s actually possible to take a quick look and be sure that the code is doing what it&#8217;s supposed to.</p>
<p>Of course, for this to be of any good, you need to give the boolean variables meaningful names. Naming them a and b wouldn&#8217;t help a bit.</p>
<p>The best thing with this approach? You don&#8217;t have to write comments and still get code that people can understand. Ah, the joy!</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
