    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Editorial</title>
        <link>https://members.accu.org/index.php/articles/708</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Journal Editorial + CVu Journal Vol 16, #6 - Dec 2004</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c185/">Editorial</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c99/">166</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c185-99/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c185+99/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Editorial</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 09 December 2004 13:16:09 +00:00 or Thu, 09 December 2004 13:16:09 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>I really do enjoy being part of the open source movement. It
really does make the mind boggle at the speed of development of
software. I've been tracking Novell's Mono application for quite a
while now and since the 1.0 release (which was roughly 8 months
ago), things have gone on in leaps and bounds. Probably the most
interesting part has been the development of
System.Windows.Forms.</p>
<p>In the original version, Mono relied on Winelib to provide the
SWF parts. Unfortunately, Winelib and Wine moved all the time,
which meant that rather than concentrating on SWF, the Novell team
and those around the world which contribute to the source would be
trying to hit a moving target. In the end, it was decided that
there would be a ground up effort to implement SWF natively. That
was roughly 4 months ago. It is (at the time of writing) somewhere
close to being 88% complete. To anyone, that is a big achievement
and probably, without the sort of community which is found in the
open source movement, the completion would be closer to 60%.</p>
<p>Of course, I could be wrong, but I can only call what I see. It
certainly has been a rollercoaster of a ride and has been a lot of
fun.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e28" id="d0e28"></a>The Student
Code Critique</h2>
</div>
<p>The SCC is a critical part of C Vu. It is one of the ways for
you to all participate in the magazine. However, the numbers seem
to have dropped and dropped to such a point that in this issue,
there is one entrant. While it does make my judging for the book a
lot easier, it is worrying the level of members who will take about
20 minutes to enter. Please get involved - not only do you make it
more interesting, but you're also helping to educate others.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e33" id="d0e33"></a>Ever Had One of
Those Moments?</h2>
</div>
<p>I'm sure that you've all had one of those moments, those
gloriously inspired moments when you know <span class=
"emphasis"><em>exactly</em></span> how to fix that piece of code
which has been bugging you for days now and better than that, by
making a couple of changes to said code, you can fix a number of
other problems <span class="emphasis"><em>plus</em></span> make it
run faster and take less time to compile? It's wonderful isn't
it.</p>
<p>I had one of those a while back when I was hand optimising some
code within a program I help develop. By replacing a lot of
inefficient code with something like</p>
<pre class="programlisting">
QString combo[] = { &quot;Text&quot;, &quot;Link&quot;, &quot;External Link&quot;,
                    &quot;External Web-Link&quot; };
size_t comboArray = sizeof(combo)/sizeof(*combo);
for(uint prop = 0; prop &lt; comboArray; ++prop)
  ComboBox1-&gt;insertItem(tr(combo[prop]));
</pre>
<p>it made the program a lot tighter and quicker. There was a
problem with it which wasn't apparent under the test conditions
(aka on my machine with different EU locales set). <tt class=
"function">tr()</tt> is the Qt translator - it is a very powerful
piece of kit, but unfortunately with it set inside of the
<tt class="methodname">insertItem</tt> method, the translator
wasn't called. This did bite into the efficiency (as shown by
various calls to memory and CPU profilers) and the second version
was to replace</p>
<pre class="programlisting">
QString combo[] = { &quot;Text&quot;, &quot;Link&quot;, &quot;External Link&quot;,
                    &quot;External Web-Link&quot; };
</pre>
<p>with</p>
<pre class="programlisting">
QString combo[] = { tr(&quot;Text&quot;), tr(&quot;Link&quot;),
     tr(&quot;External Link&quot;), tr(&quot;External Web-Link&quot;) };
</pre>
<p>which oddly enough worked. At first, I thought the problem was
in the <tt class="varname">comboArray</tt> line, but then that
really didn't make sense - all that line does is give the size of
the created array. That could only mean that the <tt class=
"methodname">insertItem</tt> method couldn't take the tr conversion
step. Swine! I had altered a substantial amount of code to use my
original method and then find it doesn't work as well as
anticipated (though it did work).</p>
<p>This did lead me to suspect that perhaps my testing and
programming methodology was incorrect. Up to now, I had been a
single programmer, working on a project which really, not many
people would use and if they did, well, the problems would not be
that huge to work around. In other words, I'm not being lazy per
se, just not being as considerate as perhaps I should; software,
after all, is a global commodity.</p>
<p>What I finally concluded was that I should not have made so many
changes, had one and sent that out as a simple test case and worked
on the results of that. Okay, grepping through the code wasn't that
big a task, neither were the changes, but it was time I could have
spent doing things I enjoy - like having a relaxing pint of some
foaming nut brown ale and reading my collection of Dr Who books
(hey, even I have to rest sometimes!)</p>
<p>Leading on from that, I decided to do some more code - this
time, replacing normal code with template code to try and speed
things up - if not from the user's point of view, then definitely
from the system's point of view. This time, I started small...</p>
<pre class="programlisting">
/* While this version is simpler to read and the
   final binary is around 4k smaller than the
   template version, gcc 3.4 with a few
   optimisation tools being run show this to be
   slightly less efficient in terms of processor
   time. */

#include &lt;qapplication.h&gt;
#include &lt;qslider.h&gt;
#include &lt;qlcdnumber.h&gt;

int main(int argc, char* argv[]) {
  QApplication myapp(argc, argv);

  QWidget* mywidget = new QWidget();
  mywidget-&gt;setGeometry(400, 300, 170, 110);

  QSlider* myslider = new QSlider(0, 9, 1, 1,
                     QSlider::Horizontal, mywidget);
  myslider-&gt;setGeometry(10, 10, 150, 30);

  QLCDNumber* mylcdnum = new QLCDNumber(1, mywidget);
  mylcdnum-&gt;setGeometry(60, 50, 50, 50);
  mylcdnum-&gt;display(1); // display initial value

  // connect slider and number display
  QObject::connect(myslider, SIGNAL(sliderMoved(int)), 
                   mylcdnum, SLOT(display(int)));

  myapp.setMainWidget(mywidget);
  mywidget-&gt;show();
  return myapp.exec();
}
</pre>
<p>Okay, not exactly rocket science in terms of code (<span class=
"emphasis"><em>and as you've all been reading the Qt series over
the past couple of issues, you can tell me what it
does</em></span>). However, some of the methods are very similar
and how they work even more so.</p>
<p>Now, I could have written a simple wrapper, but instead came up
with this</p>
<pre class="programlisting">
// Qslider v2 - template version.
// qslider-template.cpp

#include &lt;qapplication.h&gt;
#include &lt;qslider.h&gt;
#include &lt;qlcdnumber.h&gt;

#include &quot;memory.h&quot;

template &lt;typename N, typename T&gt;
void setGeometry(N m, T *x) {
  m-&gt;setGeometry(x[0], x[1], x[2], x[3]);
}

int main(int argc, char* argv[]) {
  QApplication myapp(argc, argv);
  QWidget *mywidget(allocate_memory&lt;QWidget&gt;());
  testAlloc(mywidget);

  int geom[4];
  geom[0] = 400; geom[1] = 300; geom[2] = 170;
  geom[3] = 100;
  setGeometry(mywidget, geom);

  geom[0] = 0; geom[1] = 9;
  geom[2] = geom[3] = 1;
  QSlider *myslider(allocate_memory&lt;QSlider&gt;(geom,
                   QSlider::Horizontal, mywidget));
  testAlloc(myslider);

  geom[0] = geom[1] = 10; geom[2] = 150;
  geom[3] = 30;
  setGeometry(myslider, geom);

  QLCDNumber *mylcdnum(
         allocate_memory&lt;QLCDNumber&gt;(1, mywidget));
  testAlloc(mylcdnum);

  geom[0] = 60; geom[1] = geom[2] = geom[3] = 50;
  setGeometry(mylcdnum, geom);

  mylcdnum-&gt;display(1); // display initial value

  QObject::connect(myslider, SIGNAL(sliderMoved(int)), 
                  mylcdnum, SLOT(display(int)));

  myapp.setMainWidget(mywidget);
  mywidget-&gt;show();
  return myapp.exec();
}
</pre>
<pre class="programlisting">
// memory.cpp
#include &lt;qapplication.h&gt;
#include &lt;qslider.h&gt;
#include &lt;qlcdnumber.h&gt;
#include &lt;new&gt;
#include &lt;cstdlib&gt;
using std::nothrow;

template &lt;typename N&gt;
N *allocate_memory() {
  return new(std::nothrow) N;
}
template &lt;typename N, typename M&gt;
N *allocate_memory(int val, M *&amp;m) {
  return new(std::nothrow) N(val, m);
}

template &lt;typename N, typename M, typename O,
          typename T&gt;
N *allocate_memory(T *t, M m, O o) {
  return new(std::nothrow) N(t[0], t[1], t[2], t[3],
                             m , o);
} 

template &lt;typename N&gt;
void testAlloc(N &amp;w) {
  if(!w)
    exit(EXIT_FAILURE);
}
</pre>
<p>What is the advantage over the original version? Well, for a
start in <tt class="filename">memory.cpp</tt> I have a very simple,
yet very effective memory handling routine - given it was only a
test bed, it is probably not win any prizes for the best and
tightest code around, but the important thing was for what I threw
at it, the code worked and worked well (the profilers I use showed
roughly a 10% improvement over the original).</p>
<p>Was there really a point to the exercise though? The code never
did make the release version after all. Yes. Yes there was. It is a
proof of concept that demonstrates that it is entirely possible not
only make the code tighter and more importantly, more secure (there
is a planned network of the application so everything has to be as
secure as possible).</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e96" id="d0e96"></a>Sad Times</h2>
</div>
<p>Unfortunately, I have to report that our production editor of
many moons has decided to very reluctantly move on to pastures new.
Pippa has been possibly one of the best production editors I've had
the pleasure to work with. Not only has she been patient, but has
that rare quality of knowing about the subject matter in hand.</p>
<p>We will all miss her and wish her well. C Vu and Overload are
now after a new production editor. If you would like further
details, please contact John Merrells (<tt class=
"email">&lt;<a href=
"mailto:publications@accu.org">publications@accu.org</a>&gt;</tt>).</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e106" id="d0e106"></a>And
So...</h2>
</div>
<p>Well, this is the final edition of C Vu for 2004. All that
remains for me to say is that from all of the ACCU Committee and C
Vu + Overload production staff, may we all wish you a warm and
merry yuletide and that 2005 be a fantastic year for you all. See
you in 2005!</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
