    <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  :: Francis' Scribbles</title>
        <link>https://members.accu.org/index.php/articles/1208</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">Francis' Scribbles from CVu journal + CVu Journal Vol 15, #2 - Apr 2003</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/c181/">Francis' Scribbles</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/c109/">152</a>
<br />

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

                    -                        <a href="https://members.accu.org/index.php/articles/c181+109/">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;Francis' Scribbles</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 06 April 2003 13:15:56 +01:00 or Sun, 06 April 2003 13:15:56 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a>Teaching
Programming</h2>
</div>
<p>Two things turned my thoughts to the problems of teaching
programming. The first was a letter in the recent issue of C Vu in
which the writer thought he had detected a radical change in
editorial direction. The second was sitting talking with my editor
about why Java would not work for the book I was writing.</p>
<p>It is very easy to confuse teaching programming with teaching a
programming language. To some extent you cannot do one without the
other, though it is possible to invent a programming language
purely for the purpose of teaching programming. The outstanding
example of that route is Donald Knuth's MIX language that he uses
in <i class="citetitle">The Art of Computer Programming</i>. Indeed
if you are going to focus on fundamental computing issues that is,
in my opinion, about the only viable choice.</p>
<p>In general Computer Science/Engineering Departments want to
focus on teaching programming and the language used for practical
work is just that, the language used by students to provide
practical experience of what they have learnt in theory. I think
the objective of teaching good basic programming is very laudable,
and is not, in intent, different to the way science and engineering
disciplines are generally taught at that level. However, practical
work is important and so students need to learn a computing
language in which they can experiment.</p>
<p>The thing that concerns me is both the choice of language and
the accuracy with which it is taught.</p>
<p>Suppose you were designing a course on human communication, what
language would you choose for the practical side? For the sake of
argument, suppose that you decided that it would benefit students
to learn a new natural language so that they did not import their
bad habits from the language they currently use.</p>
<p>Should those teaching this language be reasonably fluent in the
language? Should they understand correct idiomatic usage?</p>
<p>Should they have a basic grasp of the syntax and semantics?
Remember that their objective is not teaching the language but
teaching communication skills. Nonetheless, I suspect most students
would be disappointed to have invested a great deal of time
learning a new language badly or inappropriately.</p>
<p>I am reminded of a friend of my parents who read a degree in
Oriental Languages at Oxford. He then joined the British Diplomatic
Corps and because of his degree was posted to Khartoum. He used to
relate the story of his arrival at the rail station where he leapt
out of the train bubbling with youthful enthusiasm and instructed
the local railway porters in fluent classical Arabic. They just
stood open mouthed and deeply puzzled by this weird Englishman who
seemed to be spouting some curious language that vaguely related to
their normal speech. There was very little communication, until he
reverted to English (though later he became fluent in spoken
Arabic, and was awarded the title of Sheik by the local population
out of respect for his profound knowledge of the Koran and his
ability to settle disputes).</p>
<p>Returning to the subject of teaching programming; whatever
language is used for the practical side must not, in my opinion,
control what is taught on the theoretical side. It needs to be a
good general-purpose language and not one tied to a specific
paradigm. If the course is substantially about computing then it
will almost certainly be necessary to use more than one language
because I do not know of any single language that enables the
student to gain practical experience of such distinct paradigms as
object orientation and functional programming.</p>
<p>My contention is that the specialist student should finish with
a sound understanding of programming coupled with a practical
knowledge of at least one programming language. They need to
understand the broad range of programming techniques and how those
are implemented in one or more languages.</p>
<p>They should also, in my opinion, understand that programming
requires responsibility. Such simple misconceptions as using a
compiler to attempt to determine what a piece of code should do
should have been long eradicated from their thinking. They should
not be the computing equivalent of the Oxford graduate chemist who,
needing to know the boiling point of nitro-glycerine set up a
standard experiment to determine it (he had never thought of
looking up such information in a book; that would have been
cheating!)</p>
<p>The computing specialist probably should learn most, if not all,
about the languages they are using but that does not apply to the
student for whom programming is either an adjunct to their main
subject or for whom it is provided as a form of educational
enrichment.</p>
<p>Such students should not be required to delve into fundamental
theory nor should they be expected to master an entire language.
Their course should be designed to meet their needs. To some extent
academics from a Computer Science Department can be very bad news
to such students because such people often find it hard to restrain
themselves from teaching everything. If I want to mend a fuse, I do
not need to know about the physics of blowing a fuse. I need to
know a number of practical things such as checking what caused the
fuse to blow in the first place (yes, it was a current surge but
that is too low level to be practically useful). Basic programming
is not that difficult, and definitely much easier than many
programmers would have you believe. Using C++ to write simple
programs is not that hard if you do not require that the student
learn everything about the language.</p>
<p>I do not think Java is a good tool for this level of programming
because the student has too many ways in which things can come
unstuck, and too restricted a way in which code must be written.
From the instructor's position, Java demands too much knowledge.
Granted that those statements are my personal opinion but they are
based on my experiences in writing my book and those of my test
students. Object-orientation is a great way to write some types of
program but it is far from a great way to learn to program. At the
cutting code level most people think procedurally and the knowledge
required to implement ideas as objects is unhelpful.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e52" id="d0e52"></a>On Writing for
Publication</h2>
</div>
<p>Quite a few of the current crop of books on C++ are based on
articles that have either been published in magazines or on the
Internet. When I look at books like <i class="citetitle">C++
Ruminations</i> by Andy Koenig &amp; Barbara Moo I see work that
has clearly been rewritten for the different medium. This is not
always the case and in my opinion it matters.</p>
<p>When I write for a periodical I can afford to express my
strongly held opinions without distinguishing them from facts
because the readers, other columnists and even my own future
writing can make it clear that there are alternative viewpoints. It
is a mistake to water down one's opinions and ideas when writing
for a periodical.</p>
<p>This also applies to books that are clearly about personal
opinion, the reader is forewarned that my excellent ideas are just
mine and others may have even better ones or just plain different
ones.</p>
<p>When writing a technical book where the reader is led to believe
that the author is writing factual material, the rules change.
Taking a series of articles most of which are factual but some of
which are opinion and wrapping them up in a book removes the
context that validates such mixtures.</p>
<p>Over the last decade Stephen Dewhurst has written over 120
columns under the title <i class="citetitle">C++ Gotchas</i>. The
readers of those columns had immediate access to alternative views
from other columnists in the same publications (initially <i class=
"citetitle">C++ Report</i>, then <i class="citetitle">CUJ</i>) so
they would have been immediately aware of the places where Stephen
was in strong disagreement with others such as Dan Saks, Herb
Sutter and Andy Koenig.</p>
<p>A couple of months ago I received a signed copy of his book,
<i class="citetitle">C++ Gotchas.</i> I read it, and decided to
leave the review process to someone else. The book is waiting for a
review. But if you see a copy on the shelves of your local book
supplier take it off the shelf and give serious consideration to
buying it. I think the author has done himself a serious disservice
by including several articles that are pure opinion and have little
to do with what I consider a Gotcha. That only matters in so far as
that those items are largely near the start and may lead the
prospective purchaser into misjudging the book as a whole.</p>
<p>What is more serious is that some of the other articles include
material that is also a matter of opinion, but in contexts that
make that far from obvious.</p>
<p>My conclusion is that this is an example of writing that needed
much closer consideration before being transferred from periodical
to book.</p>
<p>As I have got further into the process of writing my own book I
have become increasingly sensitive to the different objectives that
a book must meet. Typos and small technical errors in magazine
articles are warts that we could do without, those same mistakes
moved to a book can be deeply damaging because few people buy a
book and immediately download errata from the Web. Indeed they
would expect that a well-written book would not contain errors.</p>
<p>Authors will defend themselves on the basis that books are
always their personal opinions. I do not think that is true.
Technical books should clearly distinguish between technical
answers and issues of idiom, personal style and presentation.
Expressing an opinion as fact is likely to detract from the
authority with which the author's factual statements are taken.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e90" id="d0e90"></a>The Concept of
Membership</h2>
</div>
<p>Clubs, societies and the like come in many forms. The two
extremes are clubs that are run entirely by members and for the
benefit of members, and commercial clubs run for the financial
benefits of the organisers.</p>
<p>ACCU is very close to the first extreme. Because certain work
places a vast load on an individual we have recently moved to
accepting the contracting of some work to members for their
financial gain. However volunteers do the overwhelming majority of
the work.</p>
<p>If you and a group of colleagues went down to the local place of
refreshment you would soon notice the person who never contributed
but always consumed. ACCU is different because many members never
see the work that is quietly done by many individuals but it is
still a community in which all should seek to contribute as well as
consume.</p>
<p>Writers of articles need readers, but they also need
appreciation or else they will stop writing. I know that many of
you do appreciate all that is done because over the years you have
told me and thanked me. But the people you should really be telling
are all those who make a little contribution of time or skill.</p>
<p>Time is the most precious thing we have because it flows
inexorably from the moment of our birth to the moment of our death.
We can never go back, time once spent is gone. We should appreciate
when others give us a gift of their time. We should also have the
courage to speak out when someone is spending time on some
well-intentioned pursuit that we think is unproductive.</p>
<p>Please take a few moments of your time to write down three good
things about ACCU and three things that you think could be done
better or differently. Now ask yourself how the ACCU Committee can
know about those notes if you do not tell them.</p>
<p>When you pay your subscription to ACCU it is more like buying a
ticket to a dance than to the theatre. The latter is just your
entry to be allowed to watch but the former is your payment to be
allowed to contribute. A dance in which no one danced would be
pretty meaningless, and a play where the audience all wanted to be
on stage would please no one.</p>
<p>Know the difference and act accordingly.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e109" id="d0e109"></a>Problems</h2>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e112" id="d0e112"></a>Problem 7
restated</h3>
</div>
<p>Look at the following code that is designed to draw an
approximate circle by drawing a polygon with a sufficiently large
number of sides.</p>
<p>The function that draws a side is based on the same design
principles as <tt class="function">yline()</tt>. The supplied
software uses the closest pixel to each vertex as the start/end
point of a side.</p>
<p>The programmer has determined that a 100-sided polygon is
indistinguishable from a circle when drawn at a resolution of 800
by 600. However he is very surprised when he draws a set of nested
circles to create a filled in disc because the result is a doughnut
shape with a central disk in background colour. Why? And how should
he change the circle drawing function?</p>
<pre class="programlisting">
void drawcircle(double radius, 
                point2d centre) {
  drawpolygon(radius, 100, centre);
}
</pre></div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e126" id="d0e126"></a>Commentary</h3>
</div>
<p>This is another little problem that arose out the book I am
writing. Writing a fill function for an arbitrary closed curve is a
difficult programming task. The one algorithm I know that is
theoretically guaranteed to work for all closed curves has a severe
practical problem, it is deeply recursive and blows up most stack
based machines.</p>
<p>Nesting ever-smaller versions of a polygon has a number of
problems. One is that some polygons simply do not nest however much
you try. But regular polygons do not suffer from that problem.</p>
<p>The problem with the above code is that when the circumference
of the circle reduces to less than 100 units our line-drawing
algorithm decides that there is nothing to draw because each side
of the polygon is less than 1 unit in length. The error in the
above code is in the concept that a 100-sided polygon is a good
representation of a circle regardless of the radius of the circle.
If we define a 'circle' something like this:</p>
<pre class="programlisting">
void drawcircle(double radius, 
                point2d centre) {
  drawpolygon(radius, 2*radius, centre);
}
</pre>
<p>We have a better chance of achieving what we want. Small circles
are represented by polygons with few sides, large circles need far
more sides for a good approximation.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e139" id="d0e139"></a>Question</h3>
</div>
<p>Does anyone know a good fill algorithm? Good in this context
means one that a relative novice could understand even if the code
lacks the efficiency you would want for your high-speed game.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e144" id="d0e144"></a>Problem 8</h3>
</div>
<p>Many of you know that C++ strings can contain embedded nulls.
However how do you get them there? And what about C arrays of
<tt class="type">char</tt>?</p>
<p>Look at the following code and decide what happens in each
case.</p>
<pre class="programlisting">
int main() {
  char const * mess = &quot;One\0Two\0Three&quot;;
  cout &lt;&lt; mess &lt;&lt; '\n';
  cout &lt;&lt; mess+4 &lt;&lt; '\n';
  cout &lt;&lt; mess+8 &lt;&lt; '\n';
}
</pre>
<p>And now repeat the exercise for:</p>
<pre class="programlisting">
int main() {
  char mess[] = &quot;One\0Two\0Three&quot;;
  cout &lt;&lt; mess &lt;&lt; '\n';
  cout &lt;&lt; mess+4 &lt;&lt; '\n';
  cout &lt;&lt; mess+8 &lt;&lt; '\n';
}
</pre>
<p>And for:</p>
<pre class="programlisting">
int main() {
  std::string mess(&quot;One\0Two\0Three&quot;);
  cout &lt;&lt; mess &lt;&lt; '\n';
  cout &lt;&lt; mess[4] &lt;&lt; '\n';
  cout &lt;&lt; mess[8] &lt;&lt; '\n';
}
</pre>
<p>And now correct that last program so that mess is initialised by
the whole of the literal not just part of it.</p>
<p>For bonus credits decide whether the <tt class=
"methodname">c_str()</tt> member of string behaves more like a
pointer to literal or an array initialised with a literal.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e171" id="d0e171"></a>Cryptic Clues
for Prizes</h3>
</div>
<p>In my days as a teacher I used to encourage my pupils to have
fun with numbers. I found the kind of cross-number problem that got
inserted into textbooks boring in the extreme. There was no great
pleasure in solving them. Solving a clue should give you some kind
of emotional kick.</p>
<p>Cryptic crossword clues can be great fun. Seeing into the mind
of the setter can be a pleasure. Distorting your view of a clue
till you see it clearly is both a challenge and the bringer of
intellectual pleasure.</p>
<p>I tried the same thing with cross number problems and many of my
pupils enjoyed both setting them and solving them. I think that
some of my readers may enjoy them as well. I do not have time to
work out an entire cross number puzzle but let me give you a clue
to think about.</p>
<p><span class="bold"><b>A tailless Roman mile.</b></span></p>
<p>The answer is a four-digit number. When you get the answer it
will obviously be correct. Do not send me the answer but send me a
clue to another number using the same general conventions. I will
publish the answer to my clue in the next issue. I will also
include all your clues with the names of those setting them.</p>
<p>I will choose one name at random for a small prize.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
