<?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>Dalton Filho &#187; Programming</title>
	<atom:link href="http://www.daltonfilho.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daltonfilho.com</link>
	<description></description>
	<lastBuildDate>Sun, 13 Sep 2009 03:41:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Arbitrary SQL order by</title>
		<link>http://www.daltonfilho.com/2008/10/04/arbitrary-sql-order-by/</link>
		<comments>http://www.daltonfilho.com/2008/10/04/arbitrary-sql-order-by/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 00:42:36 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/10/04/arbitrary-sql-order-by/</guid>
		<description><![CDATA[Consider the following scenario: the business analyst of your company sends you a business requirement in which the text results of a given query must be ordered arbitrarily according to the specifics of that business requirement. For example: Us should precede Cs, which should precede Uns, which should precede Bs, which should precede everything else. It can be very costly to resort to manipulations of the result set after the query has been executed, while a stored procedure is not very portable. You can make the query itself return the results in the arbitrary order you wish by modifying the select statement in such a way that your arbitrary order will output a number (or any other orderable output) that can be used as an order by condition.]]></description>
			<content:encoded><![CDATA[<p>Consider the following scenario: the business analyst of your company sends you a business requirement in which the text results of a given query must be ordered arbitrarily according to the specifics of that business requirement. For example: Us should precede Cs, which should precede Uns, which should precede Bs, which should precede everything else. It can be very costly to resort to manipulations of the result set after the query has been executed, while a stored procedure is not very portable. You can make the query itself return the results in the arbitrary order you wish by modifying the select statement in such a way that your arbitrary order will output a number (or any other orderable output) that can be used as an order by condition. An example of such technique is shown below (for PostgreSQL):</p>
<pre name="code" class="sql">
SELECT column_name
    CASE
        WHEN column_name LIKE pattern_1 THEN 1
        WHEN column_name LIKE pattern_2 THEN 2
        WHEN column_name LIKE pattern_3 THEN 3
        ELSE 4
    END AS arbitrary_order
FROM table_name
ORDER BY arbitrary_order</pre>
<p>I will test this ordering with the <a href="http://www.ip2nation.com/" target="_blank">ip2nation</a>&#8217;s table &#8220;ip2nationCountries&#8221;. Let&#8217;s assume the requirement says that the order should be based on the given list of prefixes: U, C, Un, B, remainder. Besides this order, all results should be returned in ascending order. At first, one can try the following query to fulfill this requirement:</p>
<pre name="code" class="sql">
SELECT country,
    CASE
        WHEN country LIKE 'U%' THEN 1
        WHEN country LIKE 'C%' THEN 2
        WHEN country LIKE 'Un%' THEN 3
        WHEN country LIKE 'B%' THEN 4
        ELSE 5
    END AS arbitrary_order
FROM "ip2nationCountries"
ORDER BY arbitrary_order, country</pre>
<p>The result of this query is <a href="http://www.daltonfilho.com/wp-content/uploads/2008/10/countries_1.html" target="_blank">here</a>. As you can see from the results, one problem is visible: &#8220;United States&#8221; appears before &#8220;China&#8221;, which does not fulfill the given requirements. This occurs because &#8220;United States&#8221; matches the first pattern in the case-switch (<code>U%</code>). This can be solved by placing the <code>Un%</code> case before <code>U%</code>:</p>
<pre name="code" class="sql">
SELECT country,
    CASE
        WHEN country LIKE 'Un%' THEN 3
        WHEN country LIKE 'U%' THEN 1
        WHEN country LIKE 'C%' THEN 2
        WHEN country LIKE 'B%' THEN 4
        ELSE 5
    END AS arbitrary_order
FROM "ip2nationCountries"
ORDER BY arbitrary_order, country</pre>
<p>The result of this query is <a href="http://www.daltonfilho.com/wp-content/uploads/2008/10/countries_2.html" target="_blank">here</a>.</p>
<p>This type of arbitrary ordering is very useful when you need to fill combos whose first results should reflect the interests of a particular group of customers, or when you need to decrease the amount of post-processing while creating a report.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/10/04/arbitrary-sql-order-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wxMatisse update #1</title>
		<link>http://www.daltonfilho.com/2008/06/08/wxmatisse-update-1/</link>
		<comments>http://www.daltonfilho.com/2008/06/08/wxmatisse-update-1/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 20:16:26 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[wxMatisse]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/06/08/wxmatisse-update-1/</guid>
		<description><![CDATA[wxMatisse is finally set up on <a href="https://wxmatisse.dev.java.net/">java.net</a>. Right now only 4 widgets, one top level window and one layout manager is supported. You are more than invited to collaborate! Growing the project is really easy with its current architecture. The next milestone is supporting the maximum number of widgets using null layout on a JFrame.
<p style="text-align: center"><a href="https://wxmatisse.dev.java.net/files/documents/8976/99540/translation_process.png" title="wxMatisse translation process"><img src="http://www.daltonfilho.com/wp-content/uploads/2008/06/translation_process_small.png" alt="wxMatisse translation process" /></a></p>]]></description>
			<content:encoded><![CDATA[<p>wxMatisse is finally set up on <a href="https://wxmatisse.dev.java.net/">java.net</a>. Right now only 4 widgets, one top level window and one layout manager is supported. You are more than invited to collaborate! Growing the project is really easy with its current architecture. The next milestone is supporting the maximum number of widgets using null layout on a JFrame.</p>
<p style="text-align: center"><a href="https://wxmatisse.dev.java.net/files/documents/8976/99540/translation_process.png" title="wxMatisse translation process"><img src="http://www.daltonfilho.com/wp-content/uploads/2008/06/translation_process_small.png" alt="wxMatisse translation process" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/06/08/wxmatisse-update-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing wxMatisse</title>
		<link>http://www.daltonfilho.com/2008/05/25/introducing-wxmatisse/</link>
		<comments>http://www.daltonfilho.com/2008/05/25/introducing-wxmatisse/#comments</comments>
		<pubDate>Sun, 25 May 2008 23:00:39 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Matisse]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/05/25/introducing-wxmatisse/</guid>
		<description><![CDATA[Towards the end of a <a href="http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/" target="_blank">previous post</a> I've exposed my thought of a wxWidgets plugin for NetBeans, more specifically, a plugin for C++ wxWidgets. If you have followed the tutorial through, you've probably realized how difficult it is to set up wxWidgets to be used on Windows using NetBeans. Even after the environment is completely configured, you still lack the power of tools like Matisse to prototype your frames. For now, a simple tool will address this problem: it's called wxMatisse. wxMatisse is a tool that uses windows created by Matisse to create equivalent windows in C++ wxWidgets. ]]></description>
			<content:encoded><![CDATA[<p>Towards the end of a <a href="http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/" target="_blank">previous post</a> I&#8217;ve exposed my thought of a wxWidgets plugin for NetBeans, more specifically, a plugin for C++ wxWidgets. If you have followed the tutorial through, you&#8217;ve probably realized how difficult it is to set up wxWidgets to be used on Windows using NetBeans. Even after the environment is completely configured, you still lack the power of tools like Matisse to prototype your frames. For now, a simple tool will address this problem: it&#8217;s called wxMatisse. wxMatisse is a tool that uses windows created by Matisse to create equivalent windows in C++ wxWidgets. The use case is simple: on a window created by Matisse, you select a context menu: &#8220;Create wxWidgets window&#8230;&#8221;. You then decide if you want to use event tables or <code>Connect()</code>, and if you want to use separate header and cpp files, for example. It&#8217;s basically a Swing to wxWidgets translator, but it does not translate Swing code; instead, it reads the windows&#8217; properties and child members to create the wxWidgets equivalent. The samples below demonstrate the pre-alpha capabilities of the translator:</p>
<p><strong>Window created by Matisse (Java)<br />
</strong></p>
<p><img src="http://www.daltonfilho.com/wp-content/uploads/2008/05/matisse.png" alt="Window created by Matisse" /></p>
<p><strong>Window created by wxMatisse (C++)<br />
</strong></p>
<p><img src="http://www.daltonfilho.com/wp-content/uploads/2008/05/wxmatisse.png" alt="wxmatisse.png" /></p>
<p><strong>Code created by Matisse</strong></p>
<pre name="code" class="java">
public class MatisseTest extends javax.swing.JFrame {    

/** Creates new form MatisseTest */
public MatisseTest() {
    initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
    button2 = new javax.swing.JButton();
    button1 = new javax.swing.JButton();
    panel1 = new javax.swing.JPanel();
    button3 = new javax.swing.JButton();
    panel2 = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    getContentPane().setLayout(null);
    button2.setLabel("Right button");
    getContentPane().add(button2);
    button2.setBounds(210, 310, 130, 30);
    button1.setLabel("Left button");
    getContentPane().add(button1);
    button1.setBounds(50, 310, 130, 30);
    panel1.setBackground(new java.awt.Color(204, 102, 255));
    panel1.setLayout(null);
    button3.setLabel("North button");
    panel1.add(button3);
    button3.setBounds(20, 20, 250, 60);
    panel2.setBackground(new java.awt.Color(255, 255, 0));
    panel2.setLayout(null);
    panel1.add(panel2);
    panel2.setBounds(20, 100, 250, 130);
    getContentPane().add(panel1);
    panel1.setBounds(50, 40, 290, 250);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-410)/2, (screenSize.height-403)/2, 410, 403);
}//GEN-END:initComponents

// Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton button1;
    private javax.swing.JButton button2;
    private javax.swing.JButton button3;
    private javax.swing.JPanel panel1;
    private javax.swing.JPanel panel2;

// End of variables declaration//GEN-END:variables

}</pre>
<p><strong>Code created by wxMatisse</strong></p>
<pre name="code" class="cpp">
// File created by wxMatisse

#ifndef _MATISSETEST_H
#define _MATISSETEST_H

#include &lt;wx/frame.h&gt;
#include &lt;wx/button.h&gt;
#include &lt;wx/panel.h&gt;

class MatisseTest : public wxFrame { 

public:

	MatisseTest(const wxString &amp;title);

private:

	wxPanel *wxpanel2;

	wxPanel *wxpanel1;

	wxButton *wxbutton1;

	wxButton *wxbutton2;

	wxButton *wxbutton3;

	void initComponents();

	enum {
		WXBUTTON1 = wxID_HIGHEST + 1,
		WXBUTTON2,
		WXBUTTON3,
		WXPANEL1,
		WXPANEL2
	};

};

#endif 	 /* _MATISSETEST_H */</pre>
<pre name="code" class="cpp">
// File created by wxMatisse

#include "matisse.h"

MatisseTest::MatisseTest(const wxString &amp;title) : wxFrame((wxFrame*) NULL, wxID_ANY, title) {
	initComponents();
}

void MatisseTest::initComponents() {
	wxbutton1 = new wxButton(this, WXBUTTON1, _T("Right button"), wxPoint(210, 310), wxSize(130, 30));
	wxbutton2 = new wxButton(this, WXBUTTON2, _T("Left button"), wxPoint(50, 310), wxSize(130, 30));
	wxpanel1 = new wxPanel(this, WXPANEL1, wxPoint(50, 40), wxSize(290, 250));
	wxpanel1-&gt;SetBackgroundColour(wxColour(204, 102, 255));
	wxbutton3 = new wxButton(wxpanel1, WXBUTTON3, _T("North button"), wxPoint(20, 20), wxSize(250, 60));
	wxpanel2 = new wxPanel(wxpanel1, WXPANEL2, wxPoint(20, 100), wxSize(250, 130));
	wxpanel2-&gt;SetBackgroundColour(wxColour(255, 255, 0));
}</pre>
<p>There are still many things to do until I release version 0.1, of course. For now, only null layout is supported. Support for other layout managers will be added in the future. The goal is to be able to translate all windows created by Matisse as long as they use the supported layout managers. As expected, there will be no support for widgets that wxWidgets offers for an operating system exclusively. Unlike Matisse, you will have total freedom to modify the generated code, as there is no coming back from it. The windows that wxMatisse translates need not be created by Matisse: as this translator uses the properties of the window rather than code, it does not rely on any code convention.  As long as the code compiles and runs, the code can be a complete mess that wxMatisse will still work. wxMatisse will be useful for migration projects where code needs to be translated from Java to C++. I will open the wxMatisse project on <a href="http://java.net/" target="_blank">java.net</a> as soon as the project support all the basic widgets in null layout. If you want to collaborate, or if you know anything about NetBeans programming and want to give a hand, you&#8217;re more than welcome to join the project!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/05/25/introducing-wxmatisse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>wxWidgets on Windows using NetBeans 6.0 with MinGW + MSYS</title>
		<link>http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/</link>
		<comments>http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 01:35:09 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[MinGW]]></category>
		<category><![CDATA[MSYS]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/</guid>
		<description><![CDATA[Setting up a wxWidgets project on Windows using NetBeans 6.0 is quite harder than doing the same on Linux, but if you want to be able to use the powerful features of NetBeans instead of smaller IDEs like wxDev-cpp, here is a quick guide to setup your environment.]]></description>
			<content:encoded><![CDATA[<p>Setting up a wxWidgets project on Windows using NetBeans 6.0 is quite harder than doing the same on Linux, but if you want to be able to use the powerful features of NetBeans instead of smaller IDEs like wxDev-cpp, here is a quick guide to setup your environment. The first thing you will need is to setup MinGW and MSYS to compile wxWidgets:</p>
<ol>
<li>Download and install <a href="http://www.mingw.org/download.shtml" title="MinGW download">MinGW</a> if you don&#8217;t already have it. Add MinGW&#8217;s <code>bin</code> subdirectory to your <code>PATH</code> environment variable. Note that if you use Vista, you <em>must</em> override GCC&#8217;s utilities with their corresponding <a href="http://sourceforge.net/project/showfiles.php?group_id=2435&amp;package_id=82723">Vista builds</a>;</li>
<li>Download and install MSYS &#8211; you will need it to compile wxWidgets. Add its bin subdirectory to <code>PATH</code> as you did with MinGW;</li>
<li>Open the MSYS console and navigate to the directory where you extracted wxWidgets (or where the installation put the files from wxWidgets);</li>
<li>Create a directory for your build (<code>mkdir build-static-debug</code>) and navigate to it. You may want to use other names;</li>
<li>Run configure with your preferred options, which may include
<ul>
<li><code>--enable-debug</code> &#8211; enable debugging info</li>
<li><code>--enable-optimise</code> &#8211; create optimised code</li>
<li><code>--disable-shared</code> &#8211; create static libraries (use this unless you want to distribute wxWidgets dlls with your application)</li>
<li><code>--enable-unicode</code> &#8211; compile wxWidgets with unicode support</li>
</ul>
<p>When you are done choosing, enter the configure command. In my build, I used <code>../configure --enable-debug --disable-shared --enable-unicode</code>. After configure is done, it will output the basic options of your build</li>
<li>Run <code>make</code> to build wxWidgets. As this may take quite a while, you may consider doing 100 push-ups to burn the calories of that burrito you&#8217;ve just eaten while following this guide;</li>
<li>Remove object files with <code>rm *.o</code> (you&#8217;re not going to need them);</li>
<li>Run <code>make install</code> to install wxWidgets;</li>
</ol>
<p>This is it for compiling wxWidgets. Now you need to setup a C/C++ project on NetBeans to use what you&#8217;ve just compiled:</p>
<ol>
<li>First of all, make sure NetBeans recognizes your MinGW + MSYS setup. Go to <code>Tools --&gt; Options</code>, then select <code>C/C++</code>. Check if MinGW and MSYS bin subdirectories are listed on the current path list. Add them if they aren&#8217;t. <code>make</code> should be found inside MSYS while <code>gcc</code>, <code>g++</code> and <code>gdb</code> should be found inside MinGW;</li>
<li>Now that NetBeans recognizes your MinGW + MSYS setup, it&#8217;s time to create a new wxWidgets project. Go to <code>File --&gt; New Project...</code> and select <code>C/C++ application</code>;</li>
<li>With your project open, enter the project properties dialog;</li>
<li>Select <code>C/C++ --&gt; C++ Compiler --&gt; General options</code>;</li>
<li>Open the MSYS console and navigate to the directory where you&#8217;ve made your wxWidgets build (e.g. <code>build-static-debug</code>) and enter <code>wx-config --cxxflags.</code><code> wx-config</code> will output the compiler flags for your project. On my machine <code>wx-config --cxxflags</code> outputs <span align="left"> <code><font color="#0000ff"> -I/c/wxWidgets-2.8.7/msw-debug/lib/wx/include/msw-uni<br />
code-debug-static-2.8 -I/c/wxWidgets-2.8.7/include -I/c/wxWidgets-2.8.7/contrib/include</font> <font color="#339966">-D__WXDEBUG__ -D__WXMSW__ -mthreads</font></code></span>. Remember to leave this console open;</li>
<li>Add all directories <font color="#0000ff">preppended with <code>-I</code></font> from <code>wx-config</code> output to the include directories of your project;</li>
<li>Select <code>Command line</code> and put the <font color="#339966">remaining flags</font> from <code>wx-config</code> there;</li>
<li>Now select <code>Linker --&gt; General options</code>;</li>
<li>Back on the MSYS console, type <code>wx-config --libs</code>. <code>wx-config</code> will output the linker flags for your project. On my machine <code>wx-config --libs</code> outputs <code><font color="#0000ff">-L/c/wxWidgets-2.8.7/msw-debug/lib</font>  <font color="#008000">-mthreads  -Wl,--subsystem,windows -mwindows </font><font color="#008000">/c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_richtext-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_aui-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_xrc-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_qa-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_html-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_adv-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_mswud_core-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud_xml-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud_net-2.8.a /c/wxWidgets-2.8.7/msw-debug/lib/libwx_baseud-2.8.a </font><font color="#008000">-lwxregexud-2.8 -lwxexpatd-2.8 -lwxtiffd-2.8 -lwxjpegd-2.8 -lwxpngd-2.8 -lwxzlibd-2.8 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi3</font></code>;</li>
<li>Add the directory <font color="#0000ff">preppended with <code>-L</code></font> to the <code>Additional library directories</code> inside <code>General options</code> and click OK to close this dialog;</li>
<li>Now select <code>Linker --&gt; Libraries --&gt; Add option... --&gt; Other option...;</code></li>
<li>Back on the MSYS console, copy the <font color="#008000">remaining linker flags</font>;</li>
<li>Paste the <font color="#008000">remaining flags</font> from <code>wx-config --libs</code> on your notepad and <strong>replace all occurrences of /c/ by C\:/</strong> (this letter may vary depending on where you installed wxWidgets), then paste the result on that field. Remember: replacing /c/ by C\:/ is utterly necessary if you don&#8217;t want to see ugly linker errors!;</li>
<li>Create a <a href="http://www.wxwidgets.org/docs/tutorials/hworld2.txt">simple wx program</a> and build it;</li>
</ol>
<p>That&#8217;s a lot of work for a first application, but for your next applications all you will have to do is to repeat the compiler and linker options. Now you can use your favorite IDE to make wxWidgets applications on Windows.</p>
<p>PS: A wxWidgets plugin for NetBeans (wxMatisse?) would be great.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/02/23/wxwidgets-on-windows-using-netbeans-60-with-mingw-msys/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>On the relevance of compilers</title>
		<link>http://www.daltonfilho.com/2008/01/27/on-the-relevance-of-compilers/</link>
		<comments>http://www.daltonfilho.com/2008/01/27/on-the-relevance-of-compilers/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 20:20:21 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[compilers]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/01/27/on-the-relevance-of-compilers/</guid>
		<description><![CDATA[I've just read Steve's rant about compilers, and believe me, it's not like the ones you've seen before (it's much better!).]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just read Steve&#8217;s <a href="http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html" title="Programmer's rich food">rant</a> about compilers, and believe me, it&#8217;s not like the ones you&#8217;ve seen before (it&#8217;s much better!). Whenever someone tells me about a blog entry about the importance of a given knowledge to the programmer profession, I know what to expect: someone to whom that knowledge is relevant writes about it as a means to demonstrate how utterly bright he is in contrast with the sordid majority, to whom that knowledge is less relevant. My perspective is based on the perception that oftentimes the authors use arguments that apply only to those with similar professional choices or personal taste. For example: how can you convince a programmer on the relevance of compiler knowledge just by saying that without compilers, programming would be too hard? As I wrote in an <a href="http://www.daltonfilho.com/2008/01/12/the-phytoplankton-analogy/" title="The phytoplankton analogy">earlier post</a>, these arguments have to be based on the relevance of such topics to our professional choices, not on any objective scale of importance. One can&#8217;t use that argument with programmers who aren&#8217;t going to write program compilers.</p>
<p>Fortunately, Steve has managed to be persuasive. What is very interesting about his post is that Steve, as someone who has managed to understand compilers, didn&#8217;t fall into the arrogance trap. Instead of arrogating himself for his compiler knowledge, Steve took the self-critical route, describing in a very candid manner what he thought about compilers early in his career. Instead of enumerating arguments that make sense only for the GCC team, Steve describes how different programmers in different contexts can benefit from this knowledge, showing his awareness for diversity in a post that instead of condemning, stimulates and encourages all of us to look further into compilers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/01/27/on-the-relevance-of-compilers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript time validation explained</title>
		<link>http://www.daltonfilho.com/2008/01/20/javascript-time-validation-explained/</link>
		<comments>http://www.daltonfilho.com/2008/01/20/javascript-time-validation-explained/#comments</comments>
		<pubDate>Mon, 21 Jan 2008 00:38:29 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[web programming]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/01/20/javascript-time-validation-explained/</guid>
		<description><![CDATA[Regular Expressions are one of the most overlooked things in programming. A simple search on Google for form validation returns many cook-book style tutorials that help making things worse by just showing an ugly finished expression (or an even uglier string parsing function). Because it's so easy to shy away from regular expressions just by seeing them finished, I've decided to demonstrate a regular expression construction step-by-step. The expression will validate an <code>hh:mm:ss</code> time pattern.]]></description>
			<content:encoded><![CDATA[<style type="text/css"> <!--  button {               height: 32px;  }  .centered-code { 	text-align: center; 	width: 100%; 	background-color:#FFFFCC; 	font-family:"Courier New", Courier, mono; 	font-size: small; } -->  </style>
<p>Regular Expressions are one of the most overlooked things in programming. A simple search on Google for form validation returns many cook-book style tutorials that help making things worse by just showing an ugly finished expression (or an even uglier string parsing function). Because it&#8217;s so easy to shy away from regular expressions just by seeing them finished, I&#8217;ve decided to demonstrate a regular expression construction step-by-step. The expression will validate an <code>hh:mm:ss</code> time pattern. Here it is:</p>
<p class="centered-code">^((\d)|(0\d)|(1\d)|(2[0-3]))\:((\d)|([0-5]\d))\:((\d)|([0-5]\d))$</p>
<p>On a first glance it looks ugly, but if you consider that it validates that time pattern in a single line, it starts to look better. Let&#8217;s proceed to the step-by-step construction.</p>
<p>First, let&#8217;s start with the body of the expression. You don&#8217;t want to validate anything before or after the expression itself, so you delimitate it with <code>^</code> (to match the beginning of string) and <code>$</code> (to match the end of the string):</p>
<p class="centered-code">^$</p>
<p>This results in an expression that will match only an empty string. Try it now:</p>
<p align="left">
<input id="test-1" type="text" /> <button onclick="validateField('test-1','^$')">Validate</button> Pattern: <code>^$</code></p>
<p>If you just used <code>^</code> or <code>$</code>, the expression would match anything that had a start or an end, respectively, which is not what you want. Try it now:</p>
<p align="left">
<input id="test-2" type="text" /> <button onclick="validateField('test-2','^')">Validate</button> Pattern: <code>^</code></p>
<p align="left">
<input id="test-3" type="text" /> <button onclick="validateField('test-3','$')">Validate</button> Pattern: <code>$</code></p>
<p>When we create regular expressions, we should be able to think in terms of expression cases. The first case is the hour value. It can be any value from 00 to 23, and we must consider the single digit cases too (0 to 9). Let&#8217;s create an expression for each case and test them. The first case is <code>0-9</code>:</p>
<p>The user may choose to type just a single digit, so we must be prepared for this case. A regular expression that can match is <code>\d</code>, which stands for &#8220;any digit&#8221;. The <code>^\d$</code> expression matches any string that contains only a single digit:</p>
<p align="left">
<input id="test-4" type="text" /> <button onclick="validateField('test-4','^\\d$')">Validate</button> Pattern: <code>^\d$</code></p>
<p>Besides <code>0-9</code> numbers, the user can also enter a two-digit number such as 18, but we must delimitate this range from 00 to 23. Because regular expressions work on a character basis (and not on a number basis), we must think in terms of which characters can vary and how they can vary. You can&#8217;t, for instance, use <code>\d\d</code>, because that would allow numbers like 45 to match. Neither can you use <code>[0-2][0-3]</code> because that would not allow numbers like 19 to match. It&#8217;s time to subdivide them into groups, which are the following:</p>
<ul>
<li><code>0\d</code> &#8211; allows numbers from 00 to 09 to match</li>
<li><code>1\d</code> &#8211; allows numbers from 10 to 19 to match</li>
<li><code>2[0-3]</code> &#8211; allows numbers from 20 to 23 to match</li>
</ul>
<p>When creating regular expressions it&#8217;s nice to test them one by one to be sure they&#8217;re working:</p>
<p align="left">
<input id="test-5" type="text" /> <button onclick="validateField('test-5','^0\\d$')">Validate</button> Pattern: <code>^0\d$</code></p>
<p align="left">
<input id="test-6" type="text" /> <button onclick="validateField('test-6','^1\\d$')">Validate</button> Pattern: <code>^1\d$</code></p>
<p align="left">
<input id="test-7" type="text" /> <button onclick="validateField('test-7','^2[0-3]$')">Validate</button> Pattern: <code>^2[0-3]$</code></p>
<p>Now we can validade any hour value by just grouping all cases so far. Grouping is very intuitive because it uses <code>(...)</code> to group and <code>|</code> to alternate between groups:</p>
<p class="centered-code">^((\d)|(0\d)|(1\d)|(2[0-3]))$</p>
<p align="left">
<input id="test-8" type="text" /> <button onclick="validateField('test-8','^((\\d)|(0\\d)|(1\\d)|(2[0-3]))$')">Validate</button> Pattern: <code>^((\d)|(0\d)|(1\d)|(2[0-3]))$</code></p>
<p>Time to include the <code>:</code> sign, but because it has a regexp meaning, you should precede it with <code>\</code> on the expression such as this:</p>
<p align="left">
<input id="test-8" type="text" /> <button onclick="validateField('test-8','^\\:$')">Validate</button> Pattern: <code>^\:$</code></p>
<p>Moving on to the minute and second values, the digits range from 00 to 59, and we should include the single digit value as well. The minutes case is much easier because we can give a lot of freedom for the second digit. The <code>[0-5]\d</code> expression does the trick:</p>
<p align="left">
<input id="test-9" type="text" /> <button onclick="validateField('test-9','^[0-5]\\d$')">Validate</button> Pattern: <code>^[0-5]\d$</code></p>
<p>Joining this expression with the single digit rule yields the following expression:</p>
<p class="centered-code">^((\d)|([0-5]\d))$</p>
<p align="left">
<input id="test-10" type="text" /> <button onclick="validateField('test-10','^((\\d)|([0-5]\\d))$')">Validate</button> Pattern: <code>^((\d)|([0-5]\d))$</code></p>
<p>With this expression ready, the seconds value is ready as well, since the seconds rule is the same as the minutes rule. Putting it all together we have the final expression:</p>
<p class="centered-code">^((\d)|(0\d)|(1\d)|(2[0-3]))\:((\d)|([0-5]\d))\:((\d)|([0-5]\d))$</p>
<p align="left">
<input id="test-11" type="text" /> <button onclick="validateField('test-11','^((\\d)|(0\\d)|(1\\d)|(2[0-3]))\\:((\\d)|([0-5]\\d))\\:((\\d)|([0-5]\\d))$')">Validate</button> The final <code>hh:mm:ss</code> validation pattern</p>
<p><script type="text/javascript"> function validateField(id,pattern) {var value = document.getElementById(id).value; if (value.match(new RegExp(pattern))) {window.alert(value + " matches the " + pattern + " pattern"); } else {window.alert(value + " does not match the " + pattern + " pattern");}} </script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/01/20/javascript-time-validation-explained/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java ranked 8th on Google&#8217;s Zeitgeist 2007</title>
		<link>http://www.daltonfilho.com/2008/01/01/java-ranked-8th-on-googles-zeitgeist-2007/</link>
		<comments>http://www.daltonfilho.com/2008/01/01/java-ranked-8th-on-googles-zeitgeist-2007/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 11:39:42 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2008/01/01/java-ranked-8th-on-googles-zeitgeist-2007/</guid>
		<description><![CDATA[The <a href="http://www.google.com/intl/en/press/zeitgeist2007/mind.html" target="_blank">results</a> are in: Java has hit the top of mind on Google's Zeitgeist 2007, scoring the 8th position on the "what ..." list. But... "what?" Exactly. If even the average Joe is wondering what is Java, I don't see how that can be a good thing. What these results tell me is not that there is a burst of new developers willing to learn Java, or that the language is so utterly good that even non-technical people are curious.  Google's Zeitgeist will probably never feature wxWidgets or C++, because they're just invisible to the end user. You don't see a wxWidgets logo when a wxWidgets application is loading, nor do you ask a user to update his libc. I would rather hear "I don't know what is Java" than to hear "Oh, I know. It is that <em>thing</em> that was <em>bugging</em> me!" Java needs better integration with browsers and OSes. Java should be invisible to the end-user.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.google.com/intl/en/press/zeitgeist2007/mind.html" target="_blank">results</a> are in: Java has hit the top of mind on Google&#8217;s Zeitgeist 2007, scoring the 8th position on the &#8220;what &#8230;&#8221; list. But&#8230; &#8220;what?&#8221; Exactly. If even the average Joe is wondering what is Java, I don&#8217;t see how that can be a good thing. What these results tell me is not that there is a burst of new developers willing to learn Java, or that the language is so utterly good that even non-technical people are curious.  Google&#8217;s Zeitgeist will probably never feature wxWidgets or C++, because they&#8217;re just invisible to the end user. You don&#8217;t see a wxWidgets logo when a wxWidgets application is loading, nor do you ask a user to update his libc. I would rather hear &#8220;I don&#8217;t know what is Java&#8221; than to hear &#8220;Oh, I know. It is that <em>thing</em> that was <em>bugging</em> me!&#8221; Java needs better integration with browsers and OSes. Java should be invisible to the end-user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2008/01/01/java-ranked-8th-on-googles-zeitgeist-2007/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>NetBeans 6.0 &#8211; First Impressions</title>
		<link>http://www.daltonfilho.com/2007/12/30/netbeans-60-first-impressions/</link>
		<comments>http://www.daltonfilho.com/2007/12/30/netbeans-60-first-impressions/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 17:33:30 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IDEs]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2007/12/30/netbeans-60-first-impressions/</guid>
		<description><![CDATA[Finally, after some RCs that didn't quite make it for me, <a href="http://download.netbeans.org/netbeans/6.0/final/" title="NetBeans IDE 6.0 - Final Release" target="_blank">NetBeans 6.0</a> (production release) has definitely won me over. These are my first impressions:
<ul>
	<li><strong>Editor</strong> - code font and colors are not always updated when I change settings on the Font &#38; Color dialog. For example: if I change the field color, I have to reopen the code to see the changes. Font &#38; Color settings weren't imported from my NB 5.5 settings, even though I've chosen to do so when I first opened NB 6.0. This is a minor issue that should be fixed soon;</li>
	<li><strong>MUCH better CSS support</strong> - clicking on a CSS rule updates a "Style Builder" form where you can change font, background, border and other settings <em>plus</em> a window where you can preview the style. That means much less dependency on tools like Dreamweaver;</li>
	<li><strong>Javascript support</strong> - in NB 5.5 I had to use a <a href="http://www.liguorien.com/javascripteditor/" title="Javascript Plugin for NetBeans 5" target="_blank">plugin</a> for Javascript code completion, which is now native to NB 6.0. To make things even better, you can see the minimum DOM version to use every function. With the widespread use of Javascript libraries like <a href="http://www.prototypejs.org/" title="Prototype Javascript Framework" target="_blank">Prototype</a> and <a href="http://script.aculo.us/" target="_blank" title="Scriptaculous">Scriptaculous</a>, I would like NB to parse all the Javascript files in my project just like it's currently done with Java files. That would yield a better code completion support for Javascript;</li>
	<li><strong>Easier encoding configuration</strong> - if you ever moved your code across different OSes and saw your "é" become a "?", you know  encoding is something you <a href="http://www.joelonsoftware.com/articles/Unicode.html" title="The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" target="_blank">have to care about</a>. It would be easy to write an entire project in NB 5.5 and forget that because the encoding option is so well hidden within the advanced options inside the options dialog. Now you can easily set the encoding for the project in a more intuitive manner by simply choosing a value in a combo box that is inside the very first page of the project options dialog;</li>
	<li><strong>Cool Code insertion</strong> - I remember I was once bashed in a forum for requesting method delegate facilities in the Java language. Maybe we're not quite there yet, but NB 6.0 now features a code insertion facility that makes it easy to proxify methods of objects that your class contains. Just press <span class="monospaced">Alt + Insert</span> and choose <span class="monospaced">"Delegate method..."</span></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>Finally, after some RCs that didn&#8217;t quite make it for me, <a href="http://download.netbeans.org/netbeans/6.0/final/" title="NetBeans IDE 6.0 - Final Release" target="_blank">NetBeans 6.0</a> (production release) has definitely won me over. These are my first impressions:<span id="more-5"></span></p>
<ul>
<li><strong>Editor</strong> &#8211; code font and colors are not always updated when I change settings on the Font &amp; Color dialog. For example: if I change the field color, I have to reopen the code to see the changes. Font &amp; Color settings weren&#8217;t imported from my NB 5.5 settings, even though I&#8217;ve chosen to do so when I first opened NB 6.0. This is a minor issue that should be fixed soon;</li>
<li><strong>MUCH better CSS support</strong> &#8211; clicking on a CSS rule updates a &#8220;Style Builder&#8221; form where you can change font, background, border and other settings <em>plus</em> a window where you can preview the style. That means much less dependency on tools like Dreamweaver;</li>
<li><strong>Javascript support</strong> &#8211; in NB 5.5 I had to use a <a href="http://www.liguorien.com/javascripteditor/" title="Javascript Plugin for NetBeans 5" target="_blank">plugin</a> for Javascript code completion, which is now native to NB 6.0. To make things even better, you can see the minimum DOM version to use every function. With the widespread use of Javascript libraries like <a href="http://www.prototypejs.org/" title="Prototype Javascript Framework" target="_blank">Prototype</a> and <a href="http://script.aculo.us/" target="_blank" title="Scriptaculous">Scriptaculous</a>, I would like NB to parse all the Javascript files in my project just like it&#8217;s currently done with Java files. That would yield a better code completion support for Javascript;</li>
<li><strong>Easier encoding configuration</strong> &#8211; if you ever moved your code across different OSes and saw your &#8220;é&#8221; become a &#8220;?&#8221;, you know  encoding is something you <a href="http://www.joelonsoftware.com/articles/Unicode.html" title="The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" target="_blank">have to care about</a>. It would be easy to write an entire project in NB 5.5 and forget that because the encoding option is so well hidden within the advanced options inside the options dialog. Now you can easily set the encoding for the project in a more intuitive manner by simply choosing a value in a combo box that is inside the very first page of the project options dialog;</li>
<li><strong>Cool Code insertion</strong> &#8211; I remember I was once bashed in a forum for requesting method delegate facilities in the Java language. Maybe we&#8217;re not quite there yet, but NB 6.0 now features a code insertion facility that makes it easy to proxify methods of objects that your class contains. Just press <span class="monospaced">Alt + Insert</span> and choose <span class="monospaced">&#8220;Delegate method&#8230;&#8221;</span></li>
</ul>
<p class="imagearea"><img src="http://www.daltonfilho.com/wp-content/uploads/2007/12/css_support.png" alt="NetBeans 6.0 CSS support" title="NetBeans 6.0 CSS support" /></p>
<p class="subtitle">Fig. 1. Improved CSS support now shows a preview of the rule</p>
<p class="imagearea"><img src="http://www.daltonfilho.com/wp-content/uploads/2007/12/javascript_support.png" alt="NetBeans 6.0 Javascript support" title="NetBeans 6.0 Javascript support" /></p>
<p class="subtitle">Fig. 2. Javascript code completion is now native to NB 6.0</p>
<p class="imagearea"><img src="http://www.daltonfilho.com/wp-content/uploads/2007/12/encoding_support.png" alt="Easier encoding configuration in NB 6.0" title="Easier encoding configuration in NB 6.0" /></p>
<p class="subtitle">Fig. 3. Encoding configuration is now on the very first page of the project configuration dialog</p>
<p>What I really like about this new version of NB is that things have either become easier or as easy as they were before. All these features are integrated, making NB worth the <em>Integrated</em> Development Environment title. Everyone who download it will benefit from these changes and there is no need to know which NB branch will match your needs. If you downloaded the RC versions of NB 6.0 and you were disappointed by editor problems, you can make your upgrade now since most of those issues were solved. If you were waiting to upgrate to NB 6.0, the time is now!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2007/12/30/netbeans-60-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAI saves the day</title>
		<link>http://www.daltonfilho.com/2007/12/23/jai-saves-the-day/</link>
		<comments>http://www.daltonfilho.com/2007/12/23/jai-saves-the-day/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 19:33:28 +0000</pubDate>
		<dc:creator>Dalton Filho</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[JAI]]></category>

		<guid isPermaLink="false">http://www.daltonfilho.com/2007/12/23/jai-saves-the-day/</guid>
		<description><![CDATA[A while ago I was working on a new feature of a CG project that involved loading hundreds of textures from disk. So far, so good. The images, however, were like an order from the devil: I needed RGBA images, but the images were all in BMP format (no chance for alpha channels) and splitted. How great is that?! To solve this problem, I had two alternatives: the first was joining and converting the images manually. If you consider the ammount of images (422) and the average time to join and convert them (aprox. 3 minutes), that would take more than 21 hours (assuming the bore factor wouldn't spoil my productivity in the meanwhile). Fortunately, there was a second alternative: automating the whole process. As I could not find a program that could supply my very specific need, I knew I had to make a little program for that, and there came JAI for the rescue.]]></description>
			<content:encoded><![CDATA[<p>A while ago I was working on a new feature of a CG project that involved loading hundreds of textures from disk. So far, so good. The images, however, were like an order from the devil: I needed RGBA images, but the images were all in BMP format (no chance for alpha channels) and splitted. How great is that?! To solve this problem, I had two alternatives: the first was joining and converting the images manually. If you consider the ammount of images (422) and the average time to join and convert them (aprox. 3 minutes), that would take more than 21 hours (assuming the bore factor wouldn&#8217;t spoil my productivity in the meanwhile). Fortunately, there was a second alternative: automating the whole process. As I could not find a program that could supply my very specific need, I knew I had to make a little program for that, and there came <a href="http://java.sun.com/javase/technologies/desktop/media/jai/" title="Java Advanced Imaging" target="_blank">JAI</a> for the rescue. I took almost an hour googling, reading API docs and trying different commands until I found the ones I needed to create an alpha channel from a color and saving the image to PNG format as below:</p>
<pre name="code" class="java">
    /**
     * Reads an image from disk and exports it to PNG format using <code>
     * alphaColor</code> as the transparent color.
     *
     * @param alphaColor the color to use as the trasparent color
     * @param src the path of the source image
     * @param dst the destination path of the exported image
     */
    void toPNG(Color alphaColor, String src, String dst) {
        RenderedImage image = JAI.create("fileload", src);

        PNGEncodeParam.RGB param = new PNGEncodeParam.RGB();

        param.setTransparentRGB(new int[]{alphaColor.getRed(),
                                          alphaColor.getGreen(),
                                          alphaColor.getBlue()});

        JAI.create("filestore", image, dst, "PNG", param);
    }</pre>
<p>The resize code:</p>
<pre name="code" class="java">
    /**
     * Reads an image from the given <code>src</code> and writes it to the
     * given <code>dst</code> resized to the given <code>width</code> and
     * <code>height</code>.
     *
     * @param src the path of the source image
     * @param dst the destination path of the exported image
     * @param width the width of the new image
     * @param height the height of the new image
     */
    void writeResizedPNGImage(String src, String dst, int width,
                              int height) {

        RenderedImage image = JAI.create("fileload", src);

        BufferedImage buf = new BufferedImage(width, height, BufferedImage
                                             .TYPE_INT_ARGB);

        Graphics2D g = buf.createGraphics();

        AffineTransform transform = new AffineTransform();

        // Resize to fit
        transform.setToScale(width / (double) image.getWidth(),
                             height / (double) image.getHeight());

        g.drawRenderedImage(image, transform);

        JAI.create("filestore", buf, dst, "PNG");
    }</pre>
<p>Useful links: <a href="https://jai.dev.java.net/binary-builds.html" title="Java Advanced Imaging download" target="_blank">JAI download</a>. <a href="http://java.sun.com/products/java-media/jai/docs/index.html" title="Java Advanced Imaging API docs" target="_blank">JAI API docs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daltonfilho.com/2007/12/23/jai-saves-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
