<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0"><channel><title>Hardcoded Software articles</title><link>http://www.hardcoded.net/articles/</link><description>Pointless babbling of a Python developer</description><lastBuildDate>Mon, 03 May 2010 00:00:00 GMT</lastBuildDate><item><title>Going Open Source</title><link>http://www.hardcoded.net/articles/going_open_source.htm</link><description>&lt;p&gt;Free Software and proprietary software are seldom seen as compatible. Free Software proponents are telling us that users should have the &lt;a href="http://www.gnu.org/"&gt;"freedom to run, copy, distribute, study, change and improve the software"&lt;/a&gt;, and proprietary software developers are arguing that it's very hard to earn money from producing Free Software. Both sides have good arguments, but a consensus can never seem to be reached.&lt;/p&gt;

&lt;p&gt;Recently, the author of &lt;a href="http://e-texteditor.com/"&gt;E Text Editor&lt;/a&gt;, Alexander Stigsen, has made a &lt;a href="http://e-texteditor.com/blog/2009/opencompany"&gt;very bold move&lt;/a&gt; by opening the source of his proprietary software. Although I'm not convinced by the Trust Metric system he proposes, I think it is a very interesting move, a move that could potentially, finally, reconcile shareware and open source.
&lt;a href="http://www.hardcoded.net/articles/going_open_source.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/going_open_source.htm</guid><pubDate>Wed, 05 Aug 2009 18:00:00 GMT</pubDate></item><item><title>Using QTreeView with QAbstractItemModel</title><link>http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm</link><description>&lt;p&gt;For someone coming from the Cocoa world, understanding how &lt;code&gt;QTreeView&lt;/code&gt; and &lt;code&gt;QAbstractItemModel&lt;/code&gt; work can be quite hard. While the concept of an item model for a tree view also exists in Cocoa, the way &lt;code&gt;QAbstractItemModel&lt;/code&gt; works is quite different from &lt;code&gt;NSOutlineDatasource&lt;/code&gt;'s.&lt;/p&gt;

&lt;p&gt;The biggest difference between the two models is in the way they refer to cells. In Cocoa, we use an arbitrary identifier supplied by the model through &lt;code&gt;outlineView:child:ofItem:&lt;/code&gt;. Then, this identifier is used in combination with a &lt;code&gt;NSTableColumn&lt;/code&gt; instance for calls like &lt;code&gt;outlineView:objectValueForTableColumn:byItem:&lt;/code&gt; (which is supposed to return what must be displayed for a particular cell). On the Qt side, we use a &lt;code&gt;QModelIndex&lt;/code&gt; instance that is supplied by the &lt;code&gt;index(row, column, parent)&lt;/code&gt; method. The strange thing with &lt;code&gt;QModelIndex&lt;/code&gt; is that it not only holds an identifier, but it also holds a row and a column. Therefore, if &lt;code&gt;index(1, 2, parentId)&lt;/code&gt; is called on the model, what must be returned is a &lt;code&gt;QModelIndex(1, 2, childId)&lt;/code&gt; instance.&lt;/p&gt;

&lt;p&gt;To a Qt newbie, this requirement for the model to return redundant data (row and column) might seem stupid. They might even think that it's downright insane when they discover that subclassing &lt;code&gt;QAbstractItemModel&lt;/code&gt; also requires you to implement a &lt;code&gt;parent(index)&lt;/code&gt; method. After all, the view &lt;em&gt;knew&lt;/em&gt; what was the parent of that index when it asked for it in &lt;code&gt;index(row, column, parent)&lt;/code&gt;! The poor Qt newbie might spend quite some time wondering what the heck was TrollTech thinking when they designed this API.&lt;/p&gt;

&lt;p&gt;It turns out that there's a reason for this strange and complex API: &lt;a href="http://labs.trolltech.com/blogs/2008/10/24/itemviews-the-next-generation/"&gt;TrollTech over-engineered this part of the toolkit&lt;/a&gt;. They wanted to design their item model so that it would be possible for a single model instance to have table views and tree views connected to it &lt;em&gt;at the same time&lt;/em&gt;. While I'm sure that there are cases where this feature is very useful, there's a lot of &lt;code&gt;QTreeView&lt;/code&gt; users out there who have no need for it and are suffering because of this over-engineering.
&lt;a href="http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm</guid><pubDate>Sat, 26 Sep 2009 18:00:00 GMT</pubDate></item><item><title>Cross-Toolkit Software</title><link>http://www.hardcoded.net/articles/cross-toolkit-software.htm</link><description>&lt;p&gt;Developing cross-platform software is easy: use cross-platform libraries, and you're set! When GUIs are involved, however, things get a little trickier. Different platforms tend to have different ways of doing things, GUI-wise. There are libraries that attempt to abstract away these differences to allow developers to build "write once, deploy everywhere" GUI-enabled applications (&lt;a href="http://qt.nokia.com"&gt;Qt&lt;/a&gt;, &lt;a href="http://www.wxwidgets.org"&gt;wxWidgets&lt;/a&gt;, &lt;a href="http://www.gtk.org"&gt;GTK+&lt;/a&gt;, etc.), but they always seem to fall short when it comes to the "nativeness" of the look and feel, especially for Mac OS X. To have a cross-platform GUI-enabled application that looks and feels native on all platforms, one obvious solution is to have a cross-&lt;strong&gt;toolkit&lt;/strong&gt; design.&lt;/p&gt;

&lt;p&gt;By "cross-toolkit", I mean an application that uses more than one toolkit for the different platforms it supports. For example, my own applications use two toolkits: Cocoa (through &lt;a href="http://pyobjc.sourceforge.net/"&gt;PyObjC&lt;/a&gt;) under Mac OS X, and Qt (through &lt;a href="http://www.riverbankcomputing.com/"&gt;PyQt&lt;/a&gt;) under Windows.&lt;/p&gt;

&lt;p&gt;But going cross-toolkit, although it gives your software nativeness, brings its own share of problems. When you create a cross-toolkit software, you have to decide what code belongs to the core, and what code belongs to the toolkit-specific code. If you put too much code in the core, you end up re-writing your own little toolkit wrapper. Then, you realize you abstracted away too much when a platform's specificity forces you to either hack around your core design or rethink that design. If you don't give your core enough responsibilities, you end up with logic duplication among your different toolkit-specific codebases.&lt;/p&gt;

&lt;p&gt;In this article, I'm going to take a look at three softwares: A single-toolkit-cross-platform software (OpenOffice), a cross-toolkit software with logic duplication in it (Transmission), and then my own attempt a creating a great cross-toolkit software (moneyGuru).
&lt;a href="http://www.hardcoded.net/articles/cross-toolkit-software.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/cross-toolkit-software.htm</guid><pubDate>Sun, 20 Dec 2009 18:00:00 GMT</pubDate></item><item><title>How To Customize QTableView's Editing Behavior</title><link>http://www.hardcoded.net/articles/how-to-customize-qtableview-editing-behavior.htm</link><description>&lt;p&gt;&lt;code&gt;QTableView&lt;/code&gt;'s default editing behavior seems to have been designed with spreadsheet-like usage in mind. When your table needs a more "row-based" editing with some columns being read-only, it becomes rather difficult to customize &lt;code&gt;QTableView&lt;/code&gt; to support that. I recently needed to do it for &lt;a href="/moneyguru/"&gt;moneyGuru&lt;/a&gt; and this article explains how I did it.
&lt;a href="http://www.hardcoded.net/articles/how-to-customize-qtableview-editing-behavior.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/how-to-customize-qtableview-editing-behavior.htm</guid><pubDate>Mon, 28 Dec 2009 18:00:00 GMT</pubDate></item><item><title>Building 64-bit PyObjC Applications With Py2app</title><link>http://www.hardcoded.net/articles/building-64-bit-pyobjc-applications-with-py2app.htm</link><description>&lt;p&gt;64-bit is upon us and has been for a while now. With Mac OS X Snow Leopard putting so much emphasis on 64-bit applications, you don't want to be left behind with your py2app built applications, don't you? Well, it turns out you're not entirely out of luck! It requires a bit of tweaking, but building 64-bit Python based applications with py2app is possible.
&lt;a href="http://www.hardcoded.net/articles/building-64-bit-pyobjc-applications-with-py2app.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/building-64-bit-pyobjc-applications-with-py2app.htm</guid><pubDate>Tue, 19 Jan 2010 18:00:00 GMT</pubDate></item><item><title>Embedded PyObjC</title><link>http://www.hardcoded.net/articles/embedded-pyobjc.htm</link><description>&lt;p&gt;When people think of a &lt;a href="http://pyobjc.sourceforge.net/"&gt;PyObjC&lt;/a&gt; application, they usually think of a Python application that uses Objective-C libraries. However, it's also possible to do the opposite: An Objective-C application that embeds Python code through a plugin. Building an application this way has advantages (speed, integration and memory usage) and should be used more often. This article explains why and how to achieve this.
&lt;a href="http://www.hardcoded.net/articles/embedded-pyobjc.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/embedded-pyobjc.htm</guid><pubDate>Mon, 08 Feb 2010 18:00:00 GMT</pubDate></item><item><title>High Level Testing</title><link>http://www.hardcoded.net/articles/high-level-testing.htm</link><description>&lt;p&gt;Too often, developers new to unit testing see them as a liability. They're hard to write, and when you want to deeply refactor your code (for example, when you want to re-organize your classes' respective responsibilities), you have to change your unit tests. This then discourages you to refactor your code, making you &lt;em&gt;less agile&lt;/em&gt;. These developers will probably abandon unit testing and write on their blog that TDD sucks (because it's common knowledge that unit testing is &lt;em&gt;good&lt;/em&gt;, so you can't say that it sucks. It's easier to attack TDD, aka. too many unit tests).&lt;/p&gt;

&lt;p&gt;You know what? They're right. I think we do way too much &lt;a href="http://en.wikipedia.org/wiki/Unit_testing"&gt;unit testing&lt;/a&gt; when we should be doing &lt;a href="http://en.wikipedia.org/wiki/Integration_testing"&gt;integration testing&lt;/a&gt; instead. If you have a class that is all neat and cute and unit tested and that a new requirement in your application requires you to split that class in two (to do it correctly), you either have to change all your tests, or you implement a kludge that allows you to keep your former architecture (don't do that).&lt;/p&gt;

&lt;p&gt;What I've been doing for about 2 years (for &lt;a href="http://hg.hardcoded.net/moneyguru"&gt;moneyGuru's development&lt;/a&gt;, to be precise) is what I call &lt;em&gt;high level testing&lt;/em&gt;, which is like integration testing, but without (or very little) unit testing. It has some downsides, but it's been working great so far and has empowered me with nearly unlimited refactoring potential on the whole project. I'm under the impression that a lot of developers have a narrow view of unit testing, which prevents them from even considering this possibility. I hope, with this article, to broaden their horizon a little bit.
&lt;a href="http://www.hardcoded.net/articles/high-level-testing.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/high-level-testing.htm</guid><pubDate>Wed, 03 Mar 2010 18:00:00 GMT</pubDate></item><item><title>Send Files To Trash On All Platforms</title><link>http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm</link><description>&lt;p&gt;If you've ever needed to send files to trash in your cross-platform application, you've probably noticed the painful void in your toolkit. It's just not there. You can copy, move, delete files, but you can't send them to the trash. There's no easy solution (until now) and you need to implement platform-specific code for Mac OS X, Windows and Linux.&lt;/p&gt;

&lt;p&gt;On Mac OS X, you have to call &lt;code&gt;FSMoveObjectToTrashSync&lt;/code&gt; (or its async friend) from &lt;code&gt;CoreServices&lt;/code&gt;. But then, either you have to make a C extension for it or you have to call it through &lt;a href="http://pyobjc.sourceforge.net"&gt;PyObjC&lt;/a&gt;. If your app is a Qt based app, you might dislike having to add such a big dependency just for a little &lt;code&gt;FSMoveObjectToTrashSync&lt;/code&gt; call.&lt;/p&gt;

&lt;p&gt;On Windows, a &lt;code&gt;SHFileOperation&lt;/code&gt; (in fact, &lt;code&gt;SHFileOperationW&lt;/code&gt; if you're not stuck in the last unicode-less decade) is needed. Again, if you're not comfortable with C (or you don't want to touch the win32 API with a ten foot pole), you need a dependency on &lt;a href="http://sourceforge.net/projects/pywin32/"&gt;pywin32&lt;/a&gt; (and Tim Golden's &lt;a href="http://timgolden.me.uk/python/winshell.html"&gt;winshell&lt;/a&gt; if you want to make your life even easier).&lt;/p&gt;

&lt;p&gt;On Linux, it's free-for-all (pun intended... in hindsight). There's no unified API to send files to the trash. The convention seems to be that sending stuff in &lt;code&gt;~/.Trash&lt;/code&gt; is good enough, but then there's always the problem of external volumes (you don't want to copy files from external volumes on your main hard disk when you send them to the trash!) and systems with alternate trash conventions (Ubuntu makes further organization of the files inside the &lt;code&gt;.Trash&lt;/code&gt; folder).&lt;/p&gt;

&lt;p&gt;In other words, it's a mess. You thought you could code your cute Qt app once an run it everywhere, but that damn trash thing gets in your way. Well, if you use Python, you're in luck because there's a library for that now! Say hello to &lt;a href="http://hg.hardcoded.net/send2trash"&gt;send2trash&lt;/a&gt;. It's a cross-platform library that sends files to trash using native API calls (without external dependencies).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from send2trash import send2trash
&amp;gt;&amp;gt;&amp;gt; send2trash('some_file')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm"&gt;More&lt;/a&gt;&lt;/p&gt;</description><guid isPermaLink="true">http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm</guid><pubDate>Mon, 03 May 2010 11:56:53 GMT</pubDate></item></channel></rss>