<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6080271</id><updated>2012-02-16T19:24:45.339-08:00</updated><title type='text'>Programmer's Notebook</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6080271.post-113739807740477716</id><published>2006-01-15T23:24:00.000-08:00</published><updated>2006-01-15T23:56:07.836-08:00</updated><title type='text'>Towards Truly Useful Computer Applications</title><content type='html'>&lt;p style="margin-bottom: 0in;"&gt;&lt;sdfield type="DATETIME" sdval="38732.9449206019" sdnum="1033;0;NNNNMMMM D, YYYY"&gt;&lt;/sdfield&gt;In thinking about Personal Information Management or PIM, the main topic of this the January 2006 Communications of the ACM monthly, I started thinking deeply about how useless I find computers.  And by that I mean simply the user interfaces we all have to work with and that come with the operating systems from which we all have to choose (and there aren't many).  It seems to me that it's a constant battle to do anything useful on or with these things.  Although not necessarily in bad shape I sometimes get winded just trying to get work done.  These machines are stupid.  They are certainly not a natural extension of us, and they certainly do not help us.  We are users indeed.  Like a heavy, lifeless, inanimate hammer, a computer today is simply a tool that does nothing lest we take it by the handle (or the keyboard) and wield it, blow after blow, until we've nailed down our poblem...or until we just finally give up and realize that we have little aptitude for tools of any sort.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;I've been having these emerging thoughts (keep "emerging" or "emergence" in mind for later) about how a computer might become more useful, and it all stems from my work in Presence (when I was at Personity working with Thanos Diacakis on Presence and Instant Messaging systems) and my recent readings regarding PIM, computational linguistics and the relationship between geometry and meaning (Dominic Widdows' book).&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;One of the things I got out of reading some of the PIM articles was an idea about Contexts, Perspectives and Aspects when browsing, bookmarking and searching the Internet and the Web (I make the destinction because although the Web, today, seems to be the primary portal to the Internet for the common person, it's not the only way.  There still remains email systems of course, and various other protocols such as network news (USENET), etc.) and how a more intellegent system that learns by observing will eventually, and seemingly Serendipitously, become more useful by assisting you because it comes to "know you."  It comes to know your patterns, your ways of thinking, your interests and your desires.  It becomes and extension of you.  But before any of that you need to know yourself.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;When it comes to knowing who I am or what I like, I have a hard time categorizing myself.  The best way to describe me is to describe me as a kind of polymath or Homo Universalis (Universal Man or Person, if you prefer), although certainly not in the same way as one might describe Archimedes or Aristotle, da Vinci or Copernicus, or, in modern history, someone such as Chomsky or Feynman, Fuller or Gell-Mann, Von Neumann or Douglas Hofstadter as being a polymath.  For these men were born great.  I was simply born.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;But Contexts, Perspectives and Aspects.  What do I mean by them?  Imagine someone polymathic, and my definition here is "someone with a great many and varied interests in the arts and humanities and whatnot who does not &lt;u&gt;necessarily&lt;/u&gt; excel at them all."  In fact he should consider himself lucky if he excels at just one of them.  And this would describe me, I think.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;Now imagine that this person's interests lie within the following categories, broadly speaking (the idea is that we can get more specific later which will help our new Intelligent PIM system get to know us better):&lt;br /&gt;&lt;/p&gt;  &lt;ol&gt;&lt;li&gt;Computers&lt;/li&gt;&lt;li&gt;Books&lt;/li&gt;&lt;li&gt;Art&lt;/li&gt;&lt;li&gt;  Music&lt;/li&gt;&lt;li&gt;  Science&lt;/li&gt;&lt;li&gt;  Mathematics&lt;/li&gt;&lt;li&gt;  History&lt;/li&gt;&lt;li&gt;  Sports&lt;/li&gt;&lt;li&gt;  Games&lt;/li&gt;&lt;li&gt;  Gormet Food&lt;/li&gt;&lt;li&gt;  Movies&lt;/li&gt;&lt;li&gt;  Politics&lt;/li&gt;&lt;/ol&gt;  &lt;p style="margin-bottom: 0in;"&gt;There is a lot of stuff in this list, but it's all fairly vague and not necessarily indicitive of the genius of a budding polymath.  But these words, these "Contexts" are enough for the computer to begin with in order for it to begin to understand the nature of its user and thus to begin to learn how its user thinks and eventually augment the user's own mental functions.  In other words, a computer system that makes it simpler for someone to think and to work (that is to think better and to work better), is a very worthwhile computer system indeed.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;A polymath is described by his interests, he is described by what he is and what he does.  Looking at our list we see that these are simple objects.  What we need, however, are descriptive nouns, things that describe who we are and that can provide "contexts" for the various "roles" we play, whether professionally or otherwise.  Therefore my interest in computers is more than a passing interest.  I am a computer scientist, a software engineer, a software architect, etc.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;As one interested in Books I would refer to myself as a "reader" or, more strongly still, a "bibliophile," which conveys my love of books and would go far in explaining the thousands of books that crowd our home.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;With Art there are several avenues one could explore.  There is the appreciator or art, the collector, say, or the art historian.  And then there is the artist himself; the producer of art.  Two branches from a single interest that would certainly assist our Intellegent PIM in segregating seemingly related material.  Of course the artist is himself an appreciator of art, but it certainly is not always the case that the appreciator of art, the art collector, necessarily is an artist.&lt;br /&gt;&lt;br /&gt;  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-113739807740477716?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/113739807740477716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=113739807740477716' title='42 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/113739807740477716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/113739807740477716'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2006/01/towards-truly-useful-computer.html' title='Towards Truly Useful Computer Applications'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>42</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-111136984732641388</id><published>2005-03-20T17:49:00.000-08:00</published><updated>2005-03-20T17:50:47.333-08:00</updated><title type='text'>The New Computer Science?</title><content type='html'>Computer Science traditionally is known as the branch of mathematics that concerns itself with the analysis of computer programs, or algorithms.  Over the years, I think, the term has blurred, and has grown to encompass more meaning so that if you enter college as an undergraduate to study “Software Engineering” you get your degree in Computer Science.  In a recent article in Software Development Times entitled “Is Software Engineering an Oxymoron?” Allen Holub, however, puts forth the proposition that this traditional discipline, Computer Science, has little to do with actually creating computer programs.  In fact he states that while computers are good at solving mathematical problems the “vast majority of programs have little or nothing to do with algorithms and number crunching. Consequently, training in mathematics is of little or no value when it comes to writing good computer programs.”  His argument, of course, is that if training in mathematics was valuable in writing good computer programs then mathematicians and physicists would be brilliant programmers.  He then states without demonstration, although he must know something about this group because he states it, that this group [mathematicians and physicists] “tends to write miserable code that's focused too much on algorithms and too little on structure.”  &lt;br /&gt; &lt;br /&gt;Because computer science encompasses software engineering he then continues, “...computer science is neither a science nor an engineering discipline.”  “Science,” he argues, “concerns itself with the formulation of proof of hypotheses.”  Which, explains, we programmers simply just don't do.  Engineering, on the other hand, is primarily concerned “with the mathematical analysis of structures, by they physical structures or electronic circuits.”  We don't concern ourselves with that, either.  The one odd thing to note here is that when Allen speaks about how mathematicians and scientists aren't brilliant programmers specifically because they focus too little on structure, he seems to imply that as good programmers what we do is focus both on algorithms and structure, in other words strike some sort of balance between the two.  But then as he continues he describes how programmers aren't engineers either because we don't concern ourselves with structure as engineers do.  Which is true in the ways he points out, which is to say we don't concern ourselves with the analysis of either physical structures or electronic circuits, unless we're designing software for engineers, for example, that requires us to have this sort of knowledge built into it, and then, of course, we would need to understand whatever it is that we would need to in order to design the target system.&lt;br /&gt;&lt;br /&gt;What he finally goes on to say is that software engineering is about process and not about structural analysis, which is apparently what real engineering is all about.  But for some reason, and I don't know why, I thought, too, that real engineering disciplines concerned themselves as well not only with structural analysis but also with structural synthesis, but then I would be digressing, so never mind.&lt;br /&gt;&lt;br /&gt;According to Holub the closest that software engineering gets to real engineering is in the study of design patterns which, in his words, are “nebulous...because there is no single 'correct' structure for the realization of a design pattern.”  And while you can present a real engineer with a structure and test him by asking whether or not the structure is sound, in other words whether it will stand or fall because “there is a provable right answer and a wrong answer.  You can't do this with software... there's no right design and wrong design, just different designs.”  Of course with this I would add good and bad designs but then he rebuts “the only definition of 'good' is 'I agree with the test writer.'”  His point being that “it's not possible to certify software engineers,” how certification has to be based on standards of correctness as within the engineering disciplines, but that within software engineering there is no such thing despite the numerous certification programs available to programmers or “software engineers” or what have you—I am presuming that he means that certification programs (past, present and any foreseeable programs) for software engineers are essentially meaningless.&lt;br /&gt;&lt;br /&gt;It's at this point where I found the article to become extremely interesting.  If there is one thing that Allen Holub's words do it's to inspire ideas.  I haven't explored any of his other works, so I'm no expert on Holub, but his short columns in SD Times, the few I've read, certainly contain nuggets of ideas that just inspire one to want to think further.  There are times when I don't agree with a lot of what he might have to say and then there are other times when he makes a lot of sense, but always there seems to be something to fuel the imagination.  &lt;br /&gt;&lt;br /&gt;And so it's at this point where he begins to redefine programming, certainly not an original stance, but one that I've not heard in a while.  In his mind programming should no longer be seen as a science nor as an engineering discipline because programming was really never either of these, but rather as a “liberal art.”  He compares programming more to creative writing than to either engineering or physics and this is where I begin to understand him and in fact where I begin to even empathize and perhaps even “agree.”  He continues, “to create a program is almost identical to the process that you use to write a book: research, formulating a thesis (or problem definition), an orderly exposition of the thesis.”  He says that “these steps are  central to both expository writing and object-oriented analysis and design,” and that “UML diagrams are really an application of symbolic linguistics...they diagram the structure of the problem statement and use cases in the same way that a sentence diagram illustrates the structure of a sentence.”  He argues that the best way to train for this is not, if we look back to his opening argument, mathematics but rather the study of languages and writing.  We should, instead of learning hard-core mathematics be learning English composition and “which teaches [us] how to write large, complex, documents like computer programs...and Latin...which teaches [us] how to analyze complex linguistic systems.”&lt;br /&gt;&lt;br /&gt;He reminds us that Logic, which is a branch of mathematics, is not taught in the mathematics department but rather by the philosophy department, which I presume is further evidence for his ultimate thesis.  And what mathematics we programmers might actually need, that is to say, what he believes to be relevant such as “set theory and the like...is easily covered in a one-semester class on the order of the Math-for-English-Majors classes offered by most universities.&lt;br /&gt; &lt;br /&gt;And so his ultimate thesis, then, is that programming has changed and is no longer the “study and implementation of algorithms.”  Programming, instead, has become the creation of complex documents.  It's move, as if it were somehow inevitable, from the realm of mathematics and science to the realm of English composition and, I suppose, art is now complete.  In other words, we programmers are not to be seen as the nerdy, analytical, number crunching geeks; the Fermats and the Newtons and the Liebnitzes of the twenty-first century.  Rather we are now to be seen as some new kind of cyber avant-garde that somehow combines literature, linguistics, philosophy and logic to compose and so create not just English compositions, but rather compositions that move, or rather works of active complexity, documents in motion, if you will.  We are the Shakespeares and the Miltons, the Whitmans and the Wordsworths, and the Keroucs and the Creeleys of the new Computer Science and for the new millennium.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-111136984732641388?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/111136984732641388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=111136984732641388' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/111136984732641388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/111136984732641388'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2005/03/new-computer-science.html' title='The New Computer Science?'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-110766344754291489</id><published>2005-02-05T20:12:00.000-08:00</published><updated>2005-02-05T20:17:27.543-08:00</updated><title type='text'>Exception Handling and Design Techniques in Java</title><content type='html'>In an effort to put together information about good practices in exception handling, especially when it comes to design issues, I've written a paper called &lt;a href="http://home.comcast.net/%7Etjclancy/OOD_ExceptionHandlingAndDesignTechniques.pdf"&gt;Exception Handling and Design Techniques&lt;/a&gt;, which is a work in progress and not quite complete.&lt;span class="down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-110766344754291489?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/110766344754291489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=110766344754291489' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110766344754291489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110766344754291489'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2005/02/exception-handling-and-design.html' title='Exception Handling and Design Techniques in Java'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-110731225470405499</id><published>2005-02-01T18:32:00.000-08:00</published><updated>2005-02-03T13:00:20.046-08:00</updated><title type='text'>Thoughts on XML and Beyond</title><content type='html'>XML is verbose. It seems necessary that we need to describe a thing by naming it and so we start out by delimiting it in XML with an element. The root element names and, by its name, should tell us something about the entire XML document (still unsure about 'document' as the name for the XML thing/bundle/blob).&lt;br /&gt;&lt;br /&gt;And so we make an attempt as we might when considering what we'd do when modeling classes of objects in an object oriented language—or so this is how I see it.  Let's describe in an XML document a book, but we'll leave out all the details.  I am just starting out by naming the what I want my document to eventually contain, information about a book, which we'll see might not be enough, but then this might also be a fundamental shortcoming of the language.  I don't know.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=”1.0” ?&amp;gt;&lt;br /&gt;&amp;lt;book&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So far so good, if not a little verbose already.  Ignoring attributes for the moment and sticking with elements (and from this point forward assuming the &amp;lt;?xml?&amp;gt; header, let's put some more meat into what kind of information a book XML document would contain (for brevity, for now, I will use the short-form for elements that contain no sub-elements because I don't, as yet, intend to include any actual information about any particular book.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;book&amp;gt;&lt;br /&gt;    &amp;lt;title/&amp;gt;&lt;br /&gt;    &amp;lt;author/&amp;gt;&lt;br /&gt;    &amp;lt;isbn/&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This, I think, would be the minimum amount of information one might need to collect about a book.  Perhaps, for convenience, you could also add the elements &amp;lt;publisher/&amp;gt; and &amp;lt;publication-date/&amp;gt;, but having the &amp;lt;isbn/&amp;gt; would allow you to discover this information.  Then again if you simply collected the ISBN and did away with every other element then you'd have a truly minimalist representation of a book XML entity.  But we'll just keep things as we have them.&lt;br /&gt;&lt;br /&gt;With this XML entity we can, in a single document (unfortunately, or fortunately, however you see it), describe a single book.  To describe more than one book you'd have to create many such documents or revisit the structure of your document and consider revising it just a bit.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;books&amp;gt;&lt;br /&gt;    &amp;lt;book&amp;gt;&lt;br /&gt;        &amp;lt;title/&amp;gt;&lt;br /&gt;        &amp;lt;author/&amp;gt;&lt;br /&gt;        &amp;lt;isbn/&amp;gt;&lt;br /&gt;    &amp;lt;/book&amp;gt;&lt;br /&gt;    &amp;lt;book&amp;gt;&lt;br /&gt;        &amp;lt;title/&amp;gt;&lt;br /&gt;        &amp;lt;author/&amp;gt;&lt;br /&gt;       &amp;lt;isbn/&amp;gt;&lt;br /&gt;    &amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;/books&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now our new structure allows us to place many book elements within a single document under the &amp;lt;books&amp;gt; root elements (note the clever use of plural). Anyway, this is all leading up to something else entirely.&lt;br /&gt;&lt;br /&gt;When I first heard of XML I thought it was a very cool idea.  When I saw an example very much like this one, my imagination took off and I didn't bother reading on until a little later.  For one I thought that the XML described the structure of the document and I didn't think that the actual XML elements accompanied the data itself (I had been working on an odd kind of object/relational mapping technology using some client/server middle ware for E-Transport at the time and XML was still in it's infancy... in fact I hadn't heard about it until after we were all well into the project).&lt;br /&gt;&lt;br /&gt;Upon seeing the XML structure above I imagined that the stream of data, flattened for transfer for example, looked something like the following (I didn't know about attributes).&lt;br /&gt;&lt;br /&gt;&amp;lt;&amp;lt;&amp;lt;The Odyssey&amp;gt;&amp;lt;Homer&amp;gt;&amp;lt;0140268863&amp;gt;&amp;gt;&amp;lt;The Iliad&amp;gt;&amp;lt;Homer&amp;gt;&amp;lt;0140275363&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;Unflattened, for readability, I thought it might look like this&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;&lt;br /&gt;    &amp;lt;&lt;br /&gt;        &amp;lt;The Odyssey&amp;gt;&lt;br /&gt;        &amp;lt;Homer&amp;gt;&lt;br /&gt;        &amp;lt;0140268863&amp;gt;&lt;br /&gt;    &amp;gt;&lt;br /&gt;        &amp;lt;The Iliad&amp;gt;&lt;br /&gt;        &amp;lt;Homer&amp;gt;&lt;br /&gt;        &amp;lt;0140275363&amp;gt;&lt;br /&gt;    &amp;gt;&lt;br /&gt;&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then, as with simple expression parsing (e.g. matching the '&amp;lt;' and '&amp;gt;'), you'd know which piece of data matched which element in the XML “document” description.  But I was mistaken.  For every XML document we have a crap load of overhead.  Every piece of data that has an element naming it is accompanied by that element... twice; not to mention the the parent element, book (open and close elements), one for every book and of course the root element.  Oh, right, and for every close element there is one extra character, the '/'.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;books&amp;gt;&lt;br /&gt;    &amp;lt;book&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;The Odyssey&amp;lt;/title&amp;gt;&lt;br /&gt;        &amp;lt;author&amp;gt;Homer&amp;lt;/author&amp;gt;&lt;br /&gt;        &amp;lt;isbn&amp;gt;0140268863&amp;lt;/isbn&amp;gt;&lt;br /&gt;    &amp;lt;/book&amp;gt;&lt;br /&gt;    &amp;lt;book&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;The Iliad&amp;lt;/title&amp;gt;&lt;br /&gt;        &amp;lt;author&amp;gt;Homer&amp;lt;/author&amp;gt;&lt;br /&gt;        &amp;lt;isbn&amp;gt;0140275363&amp;lt;/isbn&amp;gt;&lt;br /&gt;    &amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;/books&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But I was thinking that it might be interesting it you could standardize on a compact form of XML where instead of the XML we've come to know and love, come up with (or perhaps just use XSD) a standard for describing in XML the structure of data (a document, for example, or an image or whatever).  Or perhaps this should just be for documents (see the OpenDocument standard presented by the OpenOffice people for the new OpenOffice 2.0 stuff—not sure what this is).&lt;br /&gt;&lt;br /&gt;Anyway, you could do something like I had naively imagine oh so many years ago:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=”1.x” document-definition=”books.xdd” ?&amp;gt;&lt;br /&gt;&amp;lt;&lt;br /&gt;    &amp;lt;&lt;br /&gt;        &amp;lt;The Odyssey&amp;gt;&lt;br /&gt;        &amp;lt;Homer&amp;gt;&lt;br /&gt;        &amp;lt;0140268863&amp;gt;&lt;br /&gt;    &amp;gt;&lt;br /&gt;        &amp;lt;The Iliad&amp;gt;&lt;br /&gt;        &amp;lt;Homer&amp;gt;&lt;br /&gt;        &amp;lt;0140275363&amp;gt;&lt;br /&gt;    &amp;gt;&lt;br /&gt;&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So I just now made up the first line, taking artistic license.  Xdd, XML Document Definition.  Why not?  It's up to the system to find the definition in some way, maybe via JNDI.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-110731225470405499?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/110731225470405499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=110731225470405499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110731225470405499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110731225470405499'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2005/02/thoughts-on-xml-and-beyond.html' title='Thoughts on XML and Beyond'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-110136485323958163</id><published>2004-11-24T22:36:00.000-08:00</published><updated>2004-11-26T17:21:47.526-08:00</updated><title type='text'>On McCulloch-Pitts Artificial Neural Networks</title><content type='html'>I’ve spent several weeks, on and off, learning about artificial neural networks and, thus like my GO-writing days, I am attempting to put down on paper my understanding of artificial neural networks (ANN from now on).&lt;br /&gt;&lt;br /&gt;I have been reading, albeit slowly, a book called “Fundamentals of Neural Networks: Architectures, Algorithms and Applications,” by Laurene Fausett. There is no code in the books, but rather it is filled with diagrams, explanation of the kinds of ANNs out there and the algorithms that they employ. It is also heavy in mathematics, but I have been slowly pressing my way through, trying to understand.&lt;br /&gt;&lt;br /&gt;As I’ve been going along in the book, I’ve been thinking about how to go about writing a general library of classes that would allow me to model the kinds of ANNs and then execute them given some input data. So far I’ve designed a crude little class library that contains the following classes: Edge, Neuron, Activation, and Network. The Network class is not completed or working yet, but I have been able to, by hand, string together Neurons and Edges with simple Activation objects and get something to work.&lt;br /&gt;&lt;br /&gt;A little bit of theory&lt;br /&gt;&lt;br /&gt;The following diagram shows the general architecture of a McCulloch-Pitts Neural Network. The weights on X1 and X2 are said to be “excitatory,” while the weight, -1, coming from X3, because it is negative, is said to be “inhibitory.”&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;img src="http://home.comcast.net/%7Etjclancy/mcCulloghPittsANNArch.png" /&gt;.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Figure 1. McCulloch-Pitts General ANN Architecture.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;So far I can model McCulloch-Pitts neurons for solving simple binary logic functions (AND, OR, AND NOT, and XOR). Here is a diagram of an XOR network. Its interesting to look at.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;img src="http://home.comcast.net/%7Etjclancy/McCullochPittsXORFunc.png" /&gt;.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Figure 2.  A McCulloch-Pitts neural network for XOR function.&lt;/span&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Z1, Z2, and Y each have a threshold of 2.  If you follow, in turn, the input bits for the XOR truth table:&lt;br /&gt;&lt;br /&gt;&lt;table style="width: 173px; height: 160px; text-align: left; margin-left: auto; margin-right: auto;" border="2" cellpadding="2" cellspacing="2"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;A&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;B&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;XOR&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;C&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;1&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;0&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Thus ‘a XOR b’ where a=1 and b=1 yields 0. If you input a into X1 and b into X2 and run the network, Y will yield 0 when completed.&lt;br /&gt;&lt;br /&gt;The routines I’ve am designing work with the different layers. For example, X1 and X2 are layer 0, or the input layer (I’ve read many documents online and such that do not treat the inputs as neurons and thus layer 0, in their models, would begin at Z1 and Z2. In the book, Fausett talks about the inputs as neurons, and so I’ve taken to viewing them as a layer. Thus while the diagram above shows a 2-layer network, my layer architecture would have three layers.&lt;br /&gt;&lt;br /&gt;Originally I had a separate vector of input neurons, but then the code began to look a little more complicated than it really was. The Activation class is where some of the magic occurs. Essentially the Activation function for the McCulloch-Pitts neuron states the following: f(x) = {1 if x &gt;= θ, 0 if x &lt; θ}, where θ is the threshold.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-110136485323958163?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/110136485323958163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=110136485323958163' title='25 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110136485323958163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/110136485323958163'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2004/11/on-mcculloch-pitts-artificial-neural_24.html' title='On McCulloch-Pitts Artificial Neural Networks'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>25</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-106991256527081977</id><published>2003-11-26T21:56:00.000-08:00</published><updated>2004-11-21T17:19:02.806-08:00</updated><title type='text'>On Artificial Neural Networks</title><content type='html'>I've always had a fascination with artificial neural networks although I have only a vague idea of how they work.  I suppose that I’ve feared the mathematical aspects that I have imagine accompany them.  But this evening taking a stab at reading a book entitled “The Fundamentals of Neural Networks,” I finally began to understand more than I had thought I might.&lt;br /&gt;	&lt;br /&gt;I was reading about the McCulloch-Pitts neuron and the book demonstrates how to use it as a function that solves simple logic equations: AND, OR and AND NOT.  I decided to see if I could code something in C++ that would model these kinds of neurons and my solution worked.  I’ll have a little more on this later.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-106991256527081977?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/106991256527081977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=106991256527081977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106991256527081977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106991256527081977'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2003/11/on-artificial-neural-networks.html' title='On Artificial Neural Networks'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-106973685652096044</id><published>2003-11-24T21:07:00.000-08:00</published><updated>2004-11-21T17:18:34.460-08:00</updated><title type='text'>Thoughts about Graphs and Artificial Neural Networks</title><content type='html'>I’ve been reading about Graph algorithms and a book called Fundamentals of Neural Networks.  Both of these topics really interest me, but I think I am more interested in graphs and graph theory, but learning about graphs in computer science, the algorithms, etc., really help me understand some of the theory.&lt;br /&gt;&lt;br /&gt;Sometimes I’ll close my eyes and see small graphs in my head.  Usually they’re not directed, but I’ll imagine myself traversing the graph, going from node to node, seeing where an edge takes me, trying to think how I might automate a process to do this in order to find its way around.  I sometimes thing that a process could have memory or perhaps lay breadcrumbs at the vertices.  I then sometimes think about how a process could solve a maze and I sit again in the dark with closed eyes and imagine a small square (A. Square?)  running around the maze in a certain way that will make him always solve the maze.  I am afraid to try to solve these problems myself.  I think that I am entirely too stupid, and that I will fail.  Then there are times when these thoughts don’t even enter into my mind and I try, perhaps foolishly, to solve these problems.  &lt;br /&gt;&lt;br /&gt;I learned the other day about two kinds of a. neural networks.  One, a single level network and a multi-level network with the first level (after the input) being a hidden level within the network.  I also discovered that the edges connecting nodes to other nodes hold great significance.  They are weighted and it apparently is the fundamental reason why neural nets work.  Calculating the weights properly helps the network sense the pattern it needs to sense in order to create an output of something it recognizes.  I suppose this could be used in reading in a scanned report written on a typewriter, for example.  Or a scan from a page of a book.  When you scan these sorts of things you get an image, which is simply a bunch of seemingly random goop that some program knows how to display.  Using neural nets (that are trained) you can teach it to recognize the pixels of the scanned image as actual text and thus you translate the words of an image to actual computer data.  From image to a word document.  These sorts of programs are called optical character recognizers, or OCRs and today they are apparently very accurate.  Although none are foolproof and it still takes some mucking about afterward to fix the mistakes it makes after doing its magic.&lt;br /&gt;&lt;br /&gt;I don’t yet know much about neural networks, and the math does seem to be a little intimidating to me, but I can at least read what I can from the book and think of neat ways to use neural networks to solve problems.  I have that entrepreneurial gene.  I like having the ideas, but I want someone else to worry about the technicalities.  Still, I want to know enough about these technical issues so that I can have good ideas.  Nothing is more embarrassing that coming up with an idea using knowledge of something that was completely flawed.  Then again, it could lead to something brilliant, or at lease entertaining.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-106973685652096044?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/106973685652096044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=106973685652096044' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106973685652096044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106973685652096044'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2003/11/thoughts-about-graphs-and-artificial.html' title='Thoughts about Graphs and Artificial Neural Networks'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-106953979472509868</id><published>2003-11-22T14:23:00.000-08:00</published><updated>2004-11-21T17:17:49.710-08:00</updated><title type='text'>Thoughts on XML Web Services</title><content type='html'>I’ve been reading more about C# and Web Services. I have been trying to think of some sorts of web services that I could write and then perhaps make them into products to sell or at the very least, sell the services. I would need to host these services on some other machine or get static IP addresses here with faster upload time. As it is my web server over this cable modem is very slow. I mean download to my PC screams but going the other way I think is no faster than a 56kbps modem. With the professional package I believe that its over 300kpbs, which would be adequate, perhaps, to host some kinds of services.&lt;br /&gt;&lt;br /&gt;Some things that come to mind are services for game logic. In the book I am reading there is an example of using a web service with session state for hosting black jack games between a player and virtual dealer. I was thinking of creating a company called GameLogix or GameLogic or something along those lines where I would provide Web Services for various popular card and board games, provide the proxies stubs for C# and Java, for example, and then let people write clients (web or windows forms or whatever).&lt;br /&gt;&lt;br /&gt;An idea I got from the MSDN site is to host a Favorites web service where people can securely maintain their list of favorite web sites and retrieve them from anywhere at any time. Also from MSDN was to create what they call ColdStorage (I think), which is basically a limited amount of file storage space. I could also provide a web page for uploading and maintaining people’s personal file storage or perhaps create a rich windows client to do this. The web service would allow people to browse, delete, rename and save files remotely.&lt;br /&gt;&lt;br /&gt;An idea that I thought of was to create a web service that allowed you to run a finite state machine whose state actions would be themselves web services. You essentially would upload an XML document that describes the state machine (states, actions, etc.) and then feed it input. At the moment, however, I am at a loss for what sort of state machine you might wish to design using this sort of system. One thing that does come to mind would be a state machine for controlling remote devices. Turn something on, turn it off, change some property, whatever. &lt;br /&gt;&lt;br /&gt;I suppose you with this sort of state machine you could create a system that would monitor and control remote servers. For example during the Personity days we had a web application that would allow us to monitor and control at a basic level the presence and instant messaging servers at some location. Imagine if you wrote a FSM to control the service. You could send Start and it would call another web service that started the remote Presence server. The response OK might be returned putting the FSM in the Running state. We also had a kind of paused state where we would no longer accept connections. And of course we could take a server down, putting it in the FSM in the stopped state.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-106953979472509868?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/106953979472509868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=106953979472509868' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106953979472509868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106953979472509868'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2003/11/thoughts-on-xml-web-services.html' title='Thoughts on XML Web Services'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-106886764156314999</id><published>2003-11-14T19:40:00.000-08:00</published><updated>2008-07-10T08:43:08.206-07:00</updated><title type='text'>Creating a Filecopy Routine to Work with std::copy()</title><content type='html'>In an attempt to figure out how I might use the std::copy() method with istream and ostream iterators to copy, byte by byte, data from one file to another, I’ve come up with several solutions.&lt;br /&gt;&lt;br /&gt;The std::copy algorithm uses the standard stream input operator, &gt;&gt;, and if you set up the copy statement like such:&lt;br /&gt;&lt;br /&gt;copy(istream_iterator&lt;char&gt;(in), istream_iterator&lt;char&gt;(), ostream_iterator&lt;char&gt;(out));&lt;br /&gt;&lt;br /&gt;when run it seems to skip characters, namely end-of-line and perhaps even other white space. &lt;br /&gt;&lt;br /&gt;Before I bothered delving into ways that I could manipulate the streams in such a way as to not skip such things when reading bytes into memory, I thought that I might have to  write my own version of copy (something I would eventually have to do anyway because of other criteria that I’ve yet to mention), or perhaps work on a new kind of stream iterator, which didn’t really make sense. &lt;br /&gt;&lt;br /&gt;After some contemplation and taking a gander at the source code for copy I realized, as  mentioned above, that it uses the stream input operator, &gt;&gt;, and like any other operator this one, too, can be overloaded for different types.  Thus I created a new type (a very small, shallow class) called Byte whose stream input and output operators simply called stream::get() and stream::put(), respectively, and damn if it didn’t work.  Here is the snippet:&lt;br /&gt;&lt;br /&gt;copy(istream_iterator&lt;tjc_std::byte&gt;(in), istream_iterator&lt;tjc_std::byte&gt;(),&lt;br /&gt;       ostream_iterator&lt;tjc_std::byte&gt;(out));&lt;br /&gt;&lt;br /&gt;The definition for Byte is:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class Byte {&lt;br /&gt;  public: Byte()&lt;br /&gt;   : m_byte(0) {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  operator char&amp;amp;() {&lt;br /&gt;    return (char&amp;amp;)m_byte;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private:&lt;br /&gt;    unsigned char m_byte;&lt;br /&gt;  &lt;br /&gt; friend std::istream&amp;amp; operator &gt;&gt; (std::istream&amp;amp; stream, Byte&amp;amp; byte);&lt;br /&gt; friend std::ostream&amp;amp; operator &lt;&lt; (std::ostream&amp;amp; stream, const Byte&amp;amp; byte); &lt;br /&gt;};  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The implementation of the stream input and output operators is very simple.  &lt;br /&gt;&lt;br /&gt;std::istream&amp;amp; operator &gt;&gt; (std::istream&amp;amp; stream, Byte&amp;amp; byte) {&lt;br /&gt;  stream.get(byte);&lt;br /&gt;  return stream;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;std::ostream&amp;amp; operator &lt;&lt; (std::ostream&amp;amp; stream, const Byte&amp;amp; byte) {&lt;br /&gt;  stream.put(byte.m_byte);&lt;br /&gt;  return stream; &lt;br /&gt;}  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When I tried this on a fairly large (about 49 megabytes) file, the thing turned out to be dog slow, taking minutes to complete rather than seconds.  I assumed that the streams were being buffered in some way, and perhaps they are, but it was unbelievably slow (although as I discovered, building these classes and my copy routines in debug mode, with the exception of my ByteBlock type, resulted in extremely slow input and output, but when I built everything in release mode, I realized that some solutions worked the same as my ByteBlock, but read on).    So, I thought more about it and an idea occurred to me.  Why not create another type that has a built-in buffer (an array of characters) and whose stream input and output operators made use of the streams’s read() and write() methods, respectively?  And thus ByteBlock was born, which isn’t so complicated except for the input stream operator function.  Here is the code.  &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class ByteBlock   {   &lt;br /&gt;  public: ByteBlock() : m_bytesRead(0),       &lt;br /&gt;    m_fileSize(-1),       &lt;br /&gt;    m_totalRead(0) {     &lt;br /&gt;  }    &lt;br /&gt;  private: &lt;br /&gt;    unsigned char m_block[10240];     &lt;br /&gt;    int m_bytesRead;     &lt;br /&gt;    long m_fileSize;     &lt;br /&gt;    long m_totalRead;&lt;br /&gt;    friend std::istream&amp;amp; operator &gt;&gt; (std::istream&amp;amp; stream, ByteBlock&amp;amp; byte);&lt;br /&gt;    friend std::ostream&amp;amp; operator &lt;&lt; (std::ostream&amp;amp; stream,  const ByteBlock&amp;amp; byte);   };    &lt;br /&gt;    std::istream&amp;amp; operator &gt;&gt; (std::istream&amp;amp; stream, ByteBlock&amp;amp; block) {&lt;br /&gt;      if (block.m_fileSize == -1) {&lt;br /&gt;        stream.seekg(0, std::ios::end);&lt;br /&gt;        block.m_fileSize = stream.tellg();&lt;br /&gt;        stream.seekg(0, std::ios::beg);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      std::size_t leftToRead = block.m_fileSize - block.m_totalRead;&lt;br /&gt;&lt;br /&gt;      if (leftToRead) {&lt;br /&gt;        stream.read((char*)block.m_block,&lt;br /&gt;          std::min(sizeof(block.m_block), leftToRead));&lt;br /&gt;        block.m_bytesRead = stream.gcount();&lt;br /&gt;        block.m_totalRead += block.m_bytesRead;&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;        stream.setstate(std::ios_base::eofbit | std::ios_base::badbit);&lt;br /&gt;      }&lt;br /&gt;  &lt;br /&gt;      return stream;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  std::ostream&amp;amp; operator &lt;&lt; (std::ostream&amp;amp; stream, const ByteBlock&amp;amp; block)   {     &lt;br /&gt;    stream.write((char*)block.m_block, block.m_bytesRead);     return stream;   &lt;br /&gt;  }  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that the input stream operator, the first time it is run, calculates the size of the file being copied.  It then keeps a running total so that it always, in the end, reads precisely what is left in the file to read.  This keeps the stream from becoming invalid and from the copy algorithm from skipping the final call to the output operator, which always resulted, in this manner, with an incomplete copy.  Note that I check to see if there are any bytes left to read, if not I simply force the stream to be bad and to be at eof.  Thus copy quits, the streams close and all is made right.  Here, by the way, is the simple copy function:  void blockCopyFile(const char* source, const char* dest) {   ifstream in(source, ios::in | ios::binary);   ofstream out(dest, ios::out | ios::binary);    copy(istream_iterator&lt;tjc_std::byteblock&gt;(in),&lt;br /&gt;      istream_iterator&lt;tjc_std::byteblock&gt;(),&lt;br /&gt;      ostream_iterator&lt;tjc_std::byteblock&gt;(out));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Of course the more I dug into streams the more I began to realize that there must be a simpler way.  A query on the comp.lang.c++ newsgroup revealed a simpler solution.  Essentially just output to the output stream the input’s stream buffer like such:&lt;br /&gt;&lt;br /&gt;void simpleCopyFile(const char* source, const char* dest)&lt;br /&gt;{&lt;br /&gt; ifstream in(source, ios::in | ios::binary);&lt;br /&gt; ofstream out(dest, ios::out | ios::binary);&lt;br /&gt;&lt;br /&gt; if (in &amp;amp;&amp;amp; out)&lt;br /&gt; {&lt;br /&gt;   out &lt;&lt; in.rdbuf();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;When I tried this, however, it turned out to be piss slow.  I mean I couldn’t believe that this would take minutes to complete over a 40 megabyte file.  However, once I built this in release mode rather than debug mode using VC++ 7.1, it flew!  It only took seconds to copy the file. &lt;br /&gt;&lt;br /&gt;The odd thing, however, is that while this takes its time in debug but flies in release mode, my solution using the ByteBlock worked very fast no matter the mode in which the project was built.&lt;br /&gt;&lt;br /&gt;The real reason I wanted to explore copy, however, was that I wanted to use the standard library and extend it as needed to solve the problems I was facing implementing Netspoke’s Archive Viewer software.  Using hand coded loops I can control when a loop needs to terminate prematurely (e.g. if I press Cancel, for example, on the progress dialogue).&lt;br /&gt;&lt;br /&gt;A Netspoke conference archive contains several pieces.  There is a standard header of a specific size (for now).  After the header there is an index that contains the information, in the order that they occurred, regarding the events that were captured during a conference.  After the index is a large section that contains the binary data, if any, that each event carried with it.  For example, a slide show image, a JOIN or LEAVE event would contain the id and name of the person joining or leaving, etc.  The very last part of the archive is the voice data that is captured during the voice portion of the conference, which of course happens in parallel with the web conference events.&lt;br /&gt;&lt;br /&gt;The Archive Viewer actually takes its queues from the voice stream and fires the web events during the appropriate times.  Essentially I have a thread that polls the media player and then checks the next web event to see if the current time index that the media player returns is equal or greater than the next event’s time index.  If it is the event is fired and applied to the viewer.&lt;br /&gt;&lt;br /&gt;The Archive Viewer can load an archive from disk or stream it over the web.  When it loads from disk a progress dialog is displayed.  Because loading involves decompressing elements of the archive and saving the event data and voice data into separate, randomly named files (in case we want to add events, but the Archive Viewer is read-only and shouldn’t have to worry about this sort of thing) I need a way to copy and/or append data from one file to another.  And so I had an idea.&lt;br /&gt;&lt;br /&gt;I thought that if I could use the std::copy algorithm with istream and ostream iterators to copy and append data to files, I thought I could extend the standard library by creating a copy_while algorithm that would loop and copy data while some state where true (or false).  That is, while the user hasn’t pressed Cancel, and if during the save or load we’re copying a file, keep copying, otherwise quit so that the Archive save or load mechanism can recover, remove any temp data files and revert to the state it was in prior to the load or copy.&lt;br /&gt;&lt;/tjc_std::byteblock&gt;&lt;/tjc_std::byteblock&gt;&lt;/tjc_std::byteblock&gt;&lt;/tjc_std::byte&gt;&lt;/tjc_std::byte&gt;&lt;/tjc_std::byte&gt;&lt;/char&gt;&lt;/char&gt;&lt;/char&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-106886764156314999?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/106886764156314999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=106886764156314999' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106886764156314999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106886764156314999'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2003/11/creating-filecopy-routine-to-work-with.html' title='Creating a Filecopy Routine to Work with std::copy()'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6080271.post-106885205048013881</id><published>2003-11-05T15:20:00.000-08:00</published><updated>2004-11-21T17:30:36.226-08:00</updated><title type='text'>Writing a Computer GO Game</title><content type='html'>This is the tale of a mediocre GO player who is attempting to write a computer game called GO, one of the hardest games to write and, indeed, it has stumped the best minds who have tried to create a game worthy of even a mere amateur ranked player.&lt;br /&gt;&lt;br /&gt;So, I’ve taken on the extremely ambitious and perhaps somewhat foolhardy journey into the realm of writing GO.  It all began with a simple idea, really.  I was bored and wanted something to do, and having only my books and some PC-based GO games with which to study and play, I began to think not about playing the game so much as about creating my own computer GO game.  The idea kept eating away at my brain, burrowing, in fact, into the depths of my subconscious, and I began to even dream about a computer GO game.  And unfortunately when I get my mind wrapped around something like this, I can’t stop obsessing over it, and so one day, recently, I decided to take action.&lt;br /&gt;&lt;br /&gt;I decided that I didn’t necessarily want to jump right in and take on the creation of an entire GO-playing computer program, but rather I thought that I should, over time, write the tools in C++ necessary to begin the creation of a GO-playing program.  Basically, I began writing a foundation, a framework, if you will, for designing a GO game.  And I plan, over time, to learn more about the AI necessary in creating a computer GO player, what I call the GO-engine.  Actually, I’ve come up with a slightly snazzier name than simply “GO-engine.”  I thought the “Revelation Engine” had a nice ring to it, what with its connotations of divine truth and biblical rapture.&lt;br /&gt;&lt;br /&gt;In fact, the Merriam Webster Collegiate Dictionary, 10th edition, defines revelation as “an act of revealing or communicating divine truth,” or “an enlightening or astonishing disclosure.”  Perhaps the name, being biblical and apocalyptic, isn’t necessarily appropriate, but I like it.  Then again, perhaps the “Wrath of God” connotations it seems to evoke will inspire me to delve deeply into creating from nothing this monstrous beast, a Dan-level-strong game, and thus aid me in procuring that million or so reward that has thus far eluded many an attempt at writing such a thing.  &lt;br /&gt;&lt;br /&gt;Now you might think that like any disciplined researcher I would have spent many days, nay weeks! pouring through the literature and theory of games, especially the game of GO.  Perhaps you might also have thought that I would have downloaded whatever source code that I could find (gnugo anyone?), studying it for hours in order to understand the nature of a GO computer game.  But no, not me.  I admit that I did download the source to gnugo and I do, every once in a while, even browse through it.  And I also admit having, from time to time, read some bits and pieces of GO computer game theory, but for the most part, and like the lazy fool that I am, I decided instead to go about doing my own work, my own thinking, making my own mistakes.  &lt;br /&gt;&lt;br /&gt;While I plan to read about neural networks and other potentially useful ideas for creating my Revelation engine, I’ve decided that I should not pollute my mind with the thoughts of others.  At least not now.  I’d like, rather, to crash and burn on my own than to take the easy way out.  And besides, it gives me the intellectual stimulation I need away from work, the stimulation that I don’t get anywhere else, the stimulation that only comes through self-discovery and meditation.&lt;br /&gt;&lt;br /&gt;The Game…&lt;br /&gt;&lt;br /&gt;Thus far I don’t have a game, but rather I have the notion of a GO board, playing pieces (go stones), points in space on the GO board, the notion of chains (‘Friend’ stones that are linked on the GO board), and a rudimentary display abstraction for displaying the GO board (currently it shows a simple text-based board similar to that of gnugo’s text board; and no, I did not look at the source code, I merely copied the output).  &lt;br /&gt;&lt;br /&gt;So far you can place a stone on the board, and some rudimentary rules will check to make sure that you didn’t place it on a point out of bounds (e.g. x(20), y(32) on a 19x19 Board) or on a point already occupied by a stone.&lt;br /&gt;&lt;br /&gt;The board keeps track of a map of stones keyed by normalization of the points.  By normalization I mean (X*100+Y).  Thus, a point on the board at x(1), y(2) hashes to a value of 102.  The second piece of data of the map pair is a smart pointer to a stone.  I try to not waste memory by keeping smart pointers to each piece used, thus a stone on the board is the same as the same stone managed in a chain or in the captured pile of a player--a single instance of a stone is the same stone throughout its lifetime during the game.&lt;br /&gt;&lt;br /&gt;Chains are merely another way of looking at the stones, and are useful in determining the strength or weakness of a group of connected stones on the board, or so I imagine.  That is to say, while the board keeps track of all stones on the playing field, chains keep track of those ‘like’ or ‘friend’ stones (i.e. stones of the same color) on the field that are connected.  These are sometimes called strings, or perhaps they’re always called strings.  I like the notion of chains.  Chains to me are symbols of strength.  Maybe I can take the metaphor further and speak of walls and barricades.  And I haven’t even begun to think about eyes.  Whilst my toolkit can managed and recognize chains, and soon be able to count the liberties of a chain, it has no notion of eyes… Eyes will be an interesting challenge.  And truthfully I have no idea if I’m even going about this in the right manner, but I suppose that any manner in which one chooses to go is right for him, as long as it gets the job done to his satisfaction, or until he becomes completely bored of the entire thing and decides to go do something else.&lt;br /&gt;&lt;br /&gt;A little background…  I began one night last week just putzing around.  I created a simple console application called gotools, and then began creating each of the C++ classes in the same file.  My next step, I think, is to reorganize the source code, putting each class into its own header file and source file, thereby making things a little easier to read.  Not that Microsoft’s Visual Studio doesn’t do a good job what with it’s class browser, but I don’t plan to keep it specifically a Visual C++ application.  I am designing it purely in standard C++ so that it can be built on any platform that has a standard C++ compiler.  Of course specific platform code will reside in subclasses of the IDisplay interface allowing it to be compiled conditionally, or perhaps through project and make file configurations.  I don’t know yet.  Right now my main concern is building the framework so that I can begin to design the Revelation engine.  A text-based interface, for the moment, will suffice.&lt;br /&gt;	&lt;br /&gt;Here in fact, in Figure 1, is a printout of what my go tools look like.  Well, the text-based display, anyway (click this link: &lt;a href="http://thomasclancy.homedns.org/images/text_go_screen.png"&gt;text screen&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I had in fact created a version previous to this one, but after I’d noticed that the text board that comes with gnugo was better presented, I decided to borrow it’s design.  Note that the ‘I’ is missing from the coordinates across the X axis.  I don’t know why this is except that in a number of books and in a number of GUI-based interfaces for IGS (Internet GO server), the ‘I’ is left out on purpose.  I’ll have more on this later.  My first thought is that it’s left out so that it doesn’t clash with the number ‘1’.  I9 seems a little odd, but I wouldn’t think that it would be too difficult to interpret by eye.  Still, there is a reason and I shall uncover it.&lt;br /&gt;&lt;br /&gt;The thing to note here, too, is that the letter ‘x’ stands for black pieces while ‘o’ stands for white pieces.  Using ‘b’ and ‘w’ seemed awkward.  The x and o are symmetrical enough that they appear to be round stones, assuming you can stretch your imagination just a bit.&lt;br /&gt;&lt;br /&gt;11:49 PM&lt;br /&gt;&lt;br /&gt;Rudimentary chain management works.  I can merge chains if a stone connects two or more chains together.  For example assume I have the following scenario (forgive the crudeness of these sketches):&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  A B C D E&lt;br /&gt;5 . . . . .&lt;br /&gt;4 . x . . .&lt;br /&gt;3 . x . x .&lt;br /&gt;2 . . . . .&lt;br /&gt;1 . . . . .&lt;br /&gt;&lt;br /&gt;Initially, after these black pieces have been placed, the board’s chain manager recognizes two chains of black stones, [B4, B3] and [D3] (I’ll use the simple set notation here to denote a chain of stones.)  If I were to then place a black stone at C3, the chain manager would merge the second chain [D3] with the first chain [B4, B3] and then add C3 to the merged chain, thus creating one chain from two.  &lt;br /&gt;&lt;br /&gt;  A B C D E&lt;br /&gt;5 . . . . .&lt;br /&gt;4 . x . . .&lt;br /&gt;3 . x x x .&lt;br /&gt;2 . . . . .&lt;br /&gt;1 . . . . .&lt;br /&gt;&lt;br /&gt;I now have a single chain [B4, B3, C3, D3].&lt;br /&gt;&lt;br /&gt;The next task will be to calculate a chain’s liberties.  A liberty is a free adjacent point of a stone.  Thus&lt;br /&gt;&lt;br /&gt;  A B C D E&lt;br /&gt;5 . . . . .&lt;br /&gt;4 . . . . .&lt;br /&gt;3 . . x . .&lt;br /&gt;2 . . . . .&lt;br /&gt;1 . . . . .&lt;br /&gt;&lt;br /&gt;[C3] has four liberties, (C4), (D3), (C2) and (B3) (note here I used parenthesis around points on the board that are empty.  This is, of course, my own notation and, apart from the standard coordinate system of numbers on the Y-axis and letters on the X-axis, adheres to nothing else that I know of.  &lt;br /&gt;&lt;br /&gt;For future reference, I will have to remember to make my toolkit compatible with SGF, which I believe stands for “Standard Game Format.”  It is a standard file format for storing moves made in two-player games such as GO, Backgammon, Chess (I think), etc.  I looked at a sample of an SGF file and it seems quite cryptic.  But I think I’ve found some BNF grammars for the SGF language and thus I can probably write a parser and generator to read and write SGF files, respectively.  I might probably create, for the moment, my own persistent storage mechanism based on XML for storing GO moves.  And I might, at first, keep it simply for GO and not worry about keeping it abstract enough for any two-player game, although that, in itself, shouldn’t be too difficult a task.&lt;br /&gt;&lt;br /&gt;TODO:&lt;br /&gt;&lt;br /&gt;1. Create static handicap Points for the different board sizes and then allow a handicap to be specified when generating the board.&lt;br /&gt;2. Allow the create of a stone’s coordinates (point) to be specified as “&lt;letter&gt;&lt;#&gt;”.  For example, “C5”, “T19”, “D7”, etc.  Add this to the StoneFactory.&lt;br /&gt;3. Design the liberty counting function for chains.&lt;br /&gt;4. Pray for divine inspiration.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6080271-106885205048013881?l=programmers-notebook.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmers-notebook.blogspot.com/feeds/106885205048013881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6080271&amp;postID=106885205048013881' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106885205048013881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6080271/posts/default/106885205048013881'/><link rel='alternate' type='text/html' href='http://programmers-notebook.blogspot.com/2003/11/writing-computer-go-game.html' title='Writing a Computer GO Game'/><author><name>Thomas Clancy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-4HoaDOtwrhw/AAAAAAAAAAI/AAAAAAAAB_I/Sw4XlNhYnmo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry></feed>
