Journal Articles

CVu Journal Vol 16, #2 - Apr 2004 + Programming Topics + Francis' Scribbles from CVu journal
Browse in : All > Journals > CVu > 162 (8)
All > Topics > Programming (877)
All > Journal Columns > Francis' Scribbles (29)
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. 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/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: Francis' Scribbles

Author: Site Administrator

Date: 01 April 2004 22:53:48 +01:00 or Thu, 01 April 2004 22:53:48 +01:00

Summary: 

Look at the following code and decide what is wrong with it. When you have done so, decide what it has to do with the previous section in particular and this section of C Vu in general - well actually the whole of your life.

Body: 

Repository of Projects

ACCU has over a thousand paid up members and its periodicals are read by far more than that so I am very disappointed with the response to my request for help in the last issue of C Vu. Almost every reader is some kind of programmer (not quite all because I know that C Vu is also read by quite a few hangers on who enjoy the non-technical or at least the nonprogramming part.). Almost every programmer has learnt his or her trade by actually writing programs to solve problems. The lucky ones actually got to write programs that did something they found interesting or useful.

It takes about ten minutes to write up a simple description of a potential programming task. If each of you just added a single project, preferably one you would find interesting, we would soon have a real resource to help those aspiring to become skilled programmers.

I won't bore those of you familiar with the story of 'Stone Soup' but if you do not know it take a moment to visit http://spanky.triumf.ca/www/fractint/stone_soup.html. Some activities need a well-defined team working together but many other things can be done piecemeal with each individual adding a little bit. If you were bored by the assignments you were given when learning to program see if you can offer the next generation something better. On the other hand if you had a couple of thrilling assignments that brought programming to life for you, pass them on to the next generation.

Another way to add to the resource is to provide a link to a publicly available source of programming projects/assignments. I might archive a copy (with permission of the owner) in case it eventually goes away but I would be very happy to just supply a link from my Project Repository site. Whatever you do, don't do 'nothing'.

That neatly leads me to the following.

A Simple Program

Look at the following code and decide what is wrong with it. When you have done so, decide what it has to do with the previous section in particular and this section of C Vu in general - well actually the whole of your life.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  try {
    string input;
    vector<string> storage;
    while(true) {
      getline(cin, input);
      storage.push_back(input);
      if(!cin) cin.clear();
    }
  }
  catch(...) { cout << "I died\n"; }
}

It does not take very long to determine that the above program lacks an essential ingredient that we require of a program. It has the form of a program, it will compile and it will even execute. In doing so it will absorb all the input until one day it is full up and falls over dead.

Now this column turns up in a section of C Vu entitled 'Dialogue' which is meant to be a strong hint that there should be output from the reader as well as input. Reader and writer are supposed to interact.

If you think this is something similar to what I have written before (Hey, that is an idea James, how about me just repeating any section of my column which gets no response on the grounds that it obviously never reached intelligent processing.) my question is: 'What did you do about my moaning last time?'

More on Spam

Well since I last wrote on the subject my ISP started filtering spam, or claims to do so. Now what kind of email is one you do not ever want to receive? What kind of email would you never willingly send? So what kind of email is often not being rejected by ISPs?

Yesterday I received 270 emails. 102 of those contained one or other of the more recent viruses. My anti-virus software detected the problem, quarantined the offending item and then sent me a message telling me it had done so (which message I promptly told my mail reader to reject, but that is entirely internal to my system). Note that anti-virus software pretty quickly starts identifying new viruses as long as you keep it up to date.

113 of yesterday's emails were messages from elsewhere telling me that some item purporting to come from me (though actually nothing to do with me) had been rejected. Most of those rejections were because the email in question had a virus-infected attachment. Checking back to those 102 emails of the last paragraph revealed that a couple of dozen of the virus laden emails were actually such rejections (or at least purported to be).

Much of the rest of my email was plain ordinary spam that had managed to avoid my ISP's filter.

What I want to know is why any ISP is accepting email with a detectable virus in it for onward transmission. To my mind anyone whose email contains a detected virus should immediately have their account suspended. Note that an ISP has to be able to identify the origin of email from one of their clients. They know which client sent it. Of course address forgery happens but to send email I need a physical connection of some sort and it is that connection that needs to be snipped as soon as my machines start attempting to mail out virus-laden software.

So do you know of an ISP that both filters out all email containing an identifiable virus and suspends the account of any client who sends such an email? Because if you do I would seriously consider moving my business to them.

You will have noted that I continued to qualify 'virus' with identifiable. Of course there will be new viruses that will remain undetected for a few hours but as soon as detection is possible an ISP should apply it and destroy (not return) all infected email as well as suspend clients who originate such email. Note that the suspension is also beneficial to the client because they will know very quickly that something nasty got through their defences.

Personal Data

I was recently attempting to register a product that I had bought. The registration required me to provide an email address even though there was no valid reason for the supplier to have that address. They had not even bothered to create some ersatz reason such as sending me a logon code. I think it is time that we all started digging in our heels when people ask us to supply personal data. They need to tell us why and for what it will be used.

Now it is hard to argue about such things when you need an updated driver so that your purchase can be used on something such as Windows XP. You need the update and they will not provide it until you hand out personal data. Isn't this demanding 'personal data' with 'menaces'? I.e. isn't it a form of extortion? Should we not identify this as a place where the Data Protection Act (or whatever is the equivalent in your country) is tightened up? Something along the lines of a substantial fine for asking for personal data without informing the person as to how it will be used.

It would probably need a revision of the 'Sale of Goods Act' (or equivalent) to make it illegal to withhold software upgrades on the basis that the customer does not want to provide personal data. Yes, of course I can return the goods, but when was the last time you did that on the basis that you could not use them unless you gave the manufacturer your telephone number?

Computers greatly increase the threat to our privacy because they allow mining of immense databases. We need to fight back by limiting what we are 'required' to provide to those databases. Telling someone they cannot use their newly purchased scanner till they hand over their email address is a 'requirement' in all but name.

Two Little Tools

In the days when I edited C Vu I tried to get readers to share their software experiences. With a couple of exceptions that was a dismal failure. Let me share my own experiences with you.

As a result of having to learn enough about HTML, CSS and the like in order to provide a website to support my book I found myself looking around for some reasonable tools both for preparing the files and for validating them. I have no doubt that there are many such products available but all I can tell you about is the ones that I eventually found, tried out and then purchased.

The first one is a product called 'Note Tab' which is intended to be a replacement for Windows' Notepad. I very soon realised after getting the free version from www.notetab.com that this was an immensely more powerful tool than the one it was replacing. Not only did it handle multiple open files but allowed me to select what sort of thing I was working on. I could select HTML and get a bundle of useful extras to work on HTML source. I could then select CSS and get another bundle of tools for working on a cascading style sheet. And so on. I could even add my own customised support for some other activity.

I was impressed enough that I skipped their 30-day free trial of the latest version and simply signed up for the full professional version for $19.95 + VAT (which is now levied on electronic purchases based on the origin of your credit card). The weakness of the dollar made that pretty painless.

I highly recommend this product, and if you use a MS Windows based machine try it out. If you know of something better please take a few minutes to tell me (and through me, the readers of C Vu) about it.

The second issue with preparing web pages is having some reasonably adequate validator. The one provided by W3C is OK but it doesn't help very much if something simply fails to pass. What I needed was a tool that not only validated my HTML (actually, XHTML transitional) but would give me some guidance about errors and some advice with regard to warnings.

[When a page fails at the W3C validator, the reasons for the failure are given on te results page with quite a comprehensive set of reasons for the failure - PFJ]

A search of the web came up with 'CSE HTML Validator'. Details can be found at www.htmlvalidator.com. This is another product that has a free version which in itself is a helpful tool, or at least I found it so. I went on to try the full standard version. At this point I discovered a further ability of Note Tab, it can call out to other tools and one of those is CSE HTML Validator. I could work on a web page and hit a single hotkey to get it validated (sort of like compiling source code).

This product is rather more expensive but at $69 for the full standard version it does not seem unreasonable.

Here again you may know of something better or simply an alternative. Please share your experiences. In the meantime, if you are maintaining a website, consider trying the lite version of this tool and see how you like it.

A Big Tool

The previous two programs were useful but with limited purpose. The next product is rather more substantial. I am preparing to write my next book and need a reasonable IDE that will run on both MS Windows machines and Linux ones. Everything I tried had serious flaws, like being awkward with console style programming because the developers assumed that everyone would want to write full GUI programs. Or they expected a bundle of overheads such as requiring wxWindows for graphics programs. [wxWindows recently changed its name to wxWidgets due to a potential problem with the original name - PFJ] I really do not want my readers learning more than one thing at a time. Learning to write good C++ is enough without having to struggle with the eccentricities of a complex graphics library or an all singing GUI support library.

I kept looking and a few days ago I came across MinGWStudio. The MS Windows version certainly looks good and has a quality feel to it. Of course it is early days and it will have to be stress tested before being let near my readers. There is also the issue as to whether the Linux version will also pan out OK. Ian Bruntlett is preparing to test that with my library source code. If that works OK then it looks like another product whose praises I will be willing to sing.

It is free but the developer is asking for donations, which considering the magnitude of the product seems very fair to me.

If you already know about this product please share your experiences. If you do not I think it might be worth your trying it. You can get more details at www.parinya.ca. By the way it also provides a FreeBSD version, if anyone reading this uses that OS and would like to try the Unix version of my library with it please drop me a line.

Australia

By the time you read this I will have got back. I hope that my absence for three weeks has not caused anyone any problems. I will let you know what gets done out there in the next issue. However as a result of my last column I got an email from a long-standing ACCU member who now lives in Melbourne. I knew Alec Clews when he lived and worked in England and I am very much looking forward to meeting him again. I am glad I told you all where I was going otherwise I would have missed meeting Alec. Friendships that endure over the years and over long distances are made so much easier by modern technology. Do not get conned by those who claim that computers turns us into recluses; they can but they do not have to.

Commentary on Problem 13

Look at the following C code. Why does qsort() fail? Please note that the compare() function does rank any two objects of type X.

struct X {
  int i;
  int j;
  int k;
};

int compare(void * p1, void * p2) {
  struct X * x = p1;
  struct X * y = p2;
  if(x.i > y.i) return 1;
  if(x.j > y.j) return 1;
  if(x.k > y.k) return 1;
  return x.i + x.j + x.k - y.i - y.j - y.k;
}

int main() {
  struct X array[10];
  /* code initialising array */
  qsort(array, sixeof(X), 10, compare);
  /* etc. */
  return 0;
}

One of the key assumptions for sorting is that there is a well-defined final order excluding that items that compare equal may be re-ordered from one invocation of a sort algorithm to another. The problem with the above compare() is that there is no such guarantee. It is perfectly possible to have three X items a, b, c such that a>b, b>c, c>a. That breaks the fundamental requirement for sorting.

This reminds me of all those other cases where there is no ordering. We assume that x is better than y, y is better than z implies that x is better than z. That is a fundamental flaw in our thinking. As soon as our choice is based on more than one criterion the assumption is false. To put it another way, there is often no best choice and we have to make value judgements as to what is more important to us.

Good team captains implicitly understand that 'better' is not an absolute when they seek to exploit their opponents' weaknesses. For example, if your cricket opponent does not have any leg spin bowlers you can safely select a batsman who is vulnerable to leg spin.

Christmas Competition

Well there were no other entries other than those from John Kewley and Richard Blundell. I see no reason to distinguish between their excellent clues so they each win a copy of any book from the C++ In Depth Series or a copy of either the C or the C++ Standard as published by Wiley.

If they will email me their choices I will get copies out to them as soon as I have recovered from my visit to Australia.

Another form of numerical clue is to use the time or date of some event that is well known to the readership. Clues actually using a time tend to be very much local to groups but dates can be more general:

When next Julian has one that Gregory skips. (4 digits)

If you saw that clue without any context you might not immediately think of Gregorian and Julian calendars. However the clue does hint at time by use of 'When next' and so the experienced solver of cryptic clues should stop and think about calendars. What is the difference between the Julian and the Gregorian calendar? The algorithm for determining leap years. And now the answer should be clear. 2100 AD is the next time that the Julian calendar inserts a leap day when the Gregorian one does not.

On Reflection

Some of the digits have reflective symmetry (0, 1, 3, 8) though '3' only reflects vertically. Note that 0, 1, 8 also have rotational symmetry. '6' and '9' are special because they are rotations of each other.

This property of the glyphs we use to represent digits opens up some potential for cryptic clues:

The beast turning round causes a very British call for help.

Gives '999' to anyone who either knows their Bible or the English emergency phone number.

Now see if you can come up with a good clue for '9901'. Of course you can use any of the ideas I have presented over the last year as well as any of your own.

Notes: 

More fields may be available via dynamicdata ..