Showing posts with label idle musing. Show all posts
Showing posts with label idle musing. Show all posts

Friday, April 1, 2011

Failing to learn from history again

Learning from history is often hard - without the perfect vision of hindsight, it's easy to overlook the similarities of your current situation with past experience. This isn't at all comforting when one recognised the similarities and dismissed them with "This time, it will be different".

I often write "throw away" code - usually to isolate some specific code path or test some specific case that's currently interesting from the larger system. As the code's initial life expentancy is quite short, I often don't bother with niceties like proper argument parsing or decent error handling. In theory, the technical debt from this never be a problem, just write a little wrapper program, learn what you need, and throw it away.

The scare quotes and "initial life expectancy" phrasing should immediately identify my problem, though. If I didn't but the code in the VCS, the theory might work, but, once the code is there, it's never going to be thrown away, and, since it exists, in a day or a week or a month or something, I'll need something similar, and it's easy enough to just quickly add an option and make the throw script do a little more, and, since it's still just a throw away script, there's still no need to do proper error handling or argument parsing. And, of course, the moment a couple of the command line options become enshrined in a test script or two, the effort required to actually fix things never seems worthwhile, despite the increasingly convoluted "simple quick code" handling things.

Given that I've trodden this path several times before, this week's effort of going from 100 lines of C requiring a single filename to two 250-line interlocked programs, each with complex combinations of options and error handling from the oblivious school (the actual important code of each program is still less than 100 lines each), via a steady stream of "I'll quickly add this", is one of my more impressive examples of failing to heed lessons from the past. Next week, I'll probably spend some time fixing things, although there's still that ever so seductive "it's just one last option and then you can throw it away" voice to deal with.

Saturday, September 25, 2010

Hinkey letter is Hinkey

Scams intrigue me [1]. While e-mail scams are a dime-a-dozen these days, paper based scams are less common, and thus stick out more.

Which brings me to the "SARS" letter I received last week. The letter itself was quite interesting stylistically, being a "Your deductions from 2006 are being re-examined, please send supporting documentation or call to query this", and mis-stating the income tax act in various threatening ways. The letter was a pretty good effort, with the correct letterhead, correct tax number, a valid return address and it arrived in what looked like an official SARS envelope. The tone and number to call were enough to make the letter hinkey, but it was convincing enough that I ended up calling SARS to check that it was actually fake. It was also accompanied by a "please call to confirm you've received the letter" SMS the day before. The amount of correct information is both non-unexpected proof that this information is not at all secret and represents a reasonable amount of effort on the part of the scammers.

I assume (based on very little evidence, but inferring from the tone of the letter and the emphasis on phoning them) that this is a "pay us to make this all go away" scam. If that is true, the people running reckon that there are enough people who are somewhat guilty about the deductions they've claimed and/or sufficiently convinced about the corruption in the system that this strikes them as an acceptable approach to getting rid of the problem for the scam to be profitable, which is an unflattering assessment of modern South African society.

Also, given the times-scales involved - probably a week to allow for letters to arrive, a few days for the people who are going to call to call, and them some time to talk them into something that will pay money, it look likely to tie them to an potentially identifiable number for at least a few weeks. Since they cannot be assuming that no-one will realise this is fake and report it, either this needs to move to the paying money part quickly (and I'm not seeing how they'd do that) or there's something in the risk mitigation part I'm not seeing.


[1] Based on the success of the various con caper films, I'm probably far from alone in this.

Friday, March 27, 2009

The benefits of expressivity

This is the result of a chain of thought kicked off by reading "The fallacy of high level languages".

While I agree with many points made, it did start me thinking about how the debate about high and low level language is framed almost entirely in terms of the main developers. This is probably since most people in the debate are heavily involved in commercial software development. One of the great strengths of FLOSS development is the existence of the casual contributor, the person who submits a fix to an bug they find personally annoying or such. They often are more interested in using the program than developing it, but they have the skills to make the occasional contribution.

Consequently, ease of contribution is a factor that is worth considering, and, based on my personal experience, the easier it is to get up to speed on the code around the problem, the more likely I am to write and submit a patch. Expressive, compact code is easier for me to get my head around, and thus easier for me to contribute to.

Of course, expressive code is only partly function of language choice, often being more a matter of developer discipline (nothing can save one from writing crap code, after all).

Compactness is just as important though. When dealing with a new codebase, the less I have to keep in my head in trying to follow the logic flow of the path of interest, the better. Here, language and library choices are important, and this is where high level languages can really shine.

Indeed, pretty much all of the arguments for the maintainability of code written in a high level language are much more relevant for casual contributers, who can't fall back on the sort of overview somebody who's worked extensively with the code base will have, than it is for the major developers.

Wednesday, February 18, 2009

DVCS musings

Every so often, there are a spate of blog posts ragging on git. Probably because of who wrote it, and it's importance to the kernel, negative criticism of git tends to get rather widely broadcast, and attracts the same sort of stupid fanboy'ish flamewars that plague many bits of the free software ecosystem, and there always seems to be a "my DVCS is better than yours" flamewar just waiting in the wings to really get the discussion going.

To me, much of the discussion feels very much like the old emacs vs vi flamewars, before they became parodies of themselves. Given the trend towards easy interoperability, with tools such as git-svn, the bzr svn plugin, the various git fastimport helpers, and so forth, increasingly, the choice of (D)VCS is as independent of the other people in the project as the choice of editor. In a few years, hopefully people will actually realise this, and the whole debate will calm down. At which point, we can all return to arguing about the important things, like editors.

Sunday, November 2, 2008

Identity

Emotional stress is, amongst many other things, quite educational. For me, it's quite good at stripping away some of the layers of deception (self and otherwise) I engage in to make my life more comfortable. The last few weeks have been rather good at forcing me to re-examine who I am, and, in particular, I've been forced to confront the extent to which I am extremely coy about my Christianity [1].

There are various reasons for this. In part, I am an extremely private individual. I'm REALLY not comfortable with personal information leaking across my boundaries (and something as fundamental as my beliefs counts as pretty darn personal). In addition, I don't want to get drawn into the inevitably pointless debates about belief and religion - no-one ever got converted in either direction by rational debate.

There's an aspect of not wanting to be identified with the extremes of Christianity [2], and, let's face it, the crackpot extremes are really screwy, really loud, and, based on the available evidence, annoyingly common.

Disappointingly, however, a very large portion is due to simple cowardice [3]. My reluctance to trust that other people will tolerate my beliefs is both uncomfortably revealing and more than somewhat sad. While I've generally avoided explicitly denying my faith, far too often, I've simply found it comfortably convenient to avoid committing to any particular position. I'm not sure when or why I became so defensive about my beliefs, but it's hardly one of my better character traits, and represents a rather significant failure to live up to my personal ideals.

Overall, a failing grade, but hopefully with potential to do better in future.


[1] I'm not going to go into the particulars of what exactly I believe here, but it's sufficiently based on the traditions of the Protestant Christian church that the label will do. Some more details are available here

[2] Let's not even start on the history of Western Christianity, which, with some extremely vigorous white-washing of the really bloody bits, may just make it to the point where it can be described as an utterly horrific failure for a religion with "love thy neighbour" as one of the central doctrines.

[3] For example, I've spent far too much time polishing this post instead of publishing it, for very little gain.

Thursday, October 16, 2008

Reasons for loving FLOSS, #<fairly large number>

As I've mentioned before, I've been poking at a gmail backup application based off libgmail. It's been making slow progress, partly because I've been distracted by other things (such as Project Euler), but it hasn't completely stalled.

Recently, while fiddling with it, though, I hit a snag - libgmail would throw an exception when trying to access certain threads. After much head scratching, and testing, I eventually twigged that the problematic threads all included messages sent via google chat. A little focussed debugging showed that gmail creates pseudo mail messages for these when accessed via the API libgmail uses that don't quite match the messages libgmail expects. A little crude patch later, and the problem was fixed for me.

Thus armed, I submitted a bug to the Debian bug tracker, at around 19:00 local time. At 21:00, I received a acknowledgement from the maintainer, who had forwarded upstream, and at 21:10, I received a note that a patch had been applied upstream. Just over 2 hours from bug report to upstream fix strikes me as pretty good going.

Saturday, October 11, 2008

Adding periodicity

Still generating complete sequences, so linear growth is expected.


Found period 32, difference 126
time to generate 200000 numbers (U (2, 5)) is 0.37129
time to generate 2000000 numbers (U (2, 5)) is 3.66487
time to generate 20000000 numbers (U (2, 5)) is 38.38641
Found period 26, difference 126
time to generate 200000 numbers (U (2, 7)) is 0.36446
time to generate 2000000 numbers (U (2, 7)) is 4.06793
time to generate 20000000 numbers (U (2, 7)) is 44.24620
Found period 444, difference 1778
time to generate 200000 numbers (U (2, 9)) is 0.40023
time to generate 2000000 numbers (U (2, 9)) is 5.73586
time to generate 20000000 numbers (U (2, 9)) is 38.33744
Found period 1628, difference 6510
time to generate 200000 numbers (U (2, 11)) is 0.41977
time to generate 2000000 numbers (U (2, 11)) is 3.65161
time to generate 20000000 numbers (U (2, 11)) is 37.85133
Found period 5906, difference 23622
time to generate 200000 numbers (U (2, 13)) is 0.65191
time to generate 2000000 numbers (U (2, 13)) is 3.69802
time to generate 20000000 numbers (U (2, 13)) is 36.82868
Found period 80, difference 510
time to generate 200000 numbers (U (2, 15)) is 0.36584
time to generate 2000000 numbers (U (2, 15)) is 3.61351
time to generate 20000000 numbers (U (2, 15)) is 37.08529
time to generate 200000 numbers (U (2, 17)) is 4.52874
Found period 126960, difference 507842
time to generate 2000000 numbers (U (2, 17)) is 7.54118
time to generate 20000000 numbers (U (2, 17)) is 39.30235
time to generate 200000 numbers (U (2, 19)) is 4.54097
Found period 380882, difference 1523526
time to generate 2000000 numbers (U (2, 19)) is 35.07058
time to generate 20000000 numbers (U (2, 19)) is 36.92766
time to generate 200000 numbers (U (2, 21)) is 4.10050
time to generate 2000000 numbers (U (2, 21)) is 43.80197
Found period 2097152, difference 8388606
time to generate 20000000 numbers (U (2, 21)) is 456.09959


There's a bunch of improvements that can be made to the code - especially the periodicity check is not that efficient, and tends to repeat work which could be avoided. This bites for the U(2, 21) sequence, for which the direct approach presented earlier can calculate 20000000 elements in around 290 seconds, but the overall problem is now something that can be solved in "reasonable" time periods

Presented without further comment.


# time python ./solve_167.py
Answer = <answer redacted, but confirmed correct>

real 7m15.052s
user 6m41.213s
sys 0m15.365s

Friday, October 10, 2008

This may actually be feasible now

With CTPUG 14 in the near future, and two failed attempts to tackle the Ulam seuqence problem from the previous meetings, I decided to give the problem some thought today.

So, from today's bright idea,:

$ python ./Ulam.py
time to generate 100 numbers (U (2, 5)) is 0.00426
time to generate 1000 numbers (U (2, 5)) is 0.03167
time to generate 10000 numbers (U (2, 5)) is 0.22796
time to generate 100000 numbers (U (2, 5)) is 1.44548
time to generate 1000000 numbers (U (2, 5)) is 14.71493
time to generate 100 numbers (U (2, 7)) is 0.00214
time to generate 1000 numbers (U (2, 7)) is 0.01558
time to generate 10000 numbers (U (2, 7)) is 0.15068
time to generate 100000 numbers (U (2, 7)) is 1.43910
time to generate 1000000 numbers (U (2, 7)) is 14.62419
time to generate 100 numbers (U (2, 9)) is 0.00245
time to generate 1000 numbers (U (2, 9)) is 0.01770
time to generate 10000 numbers (U (2, 9)) is 0.15190
time to generate 100000 numbers (U (2, 9)) is 1.45868
time to generate 1000000 numbers (U (2, 9)) is 14.93112
time to generate 100 numbers (U (2, 11)) is 0.00211
time to generate 1000 numbers (U (2, 11)) is 0.01602
time to generate 10000 numbers (U (2, 11)) is 0.15409
time to generate 100000 numbers (U (2, 11)) is 1.49055
time to generate 1000000 numbers (U (2, 11)) is 15.08445
...
time to generate 100 numbers (U (2, 21)) is 0.00486
time to generate 1000 numbers (U (2, 21)) is 0.03741
time to generate 10000 numbers (U (2, 21)) is 0.25073
time to generate 100000 numbers (U (2, 21)) is 1.78683
time to generate 1000000 numbers (U (2, 21)) is 17.9669

(Sequences U(2,5) and U(2,7) verified against the On-Line Encyclopedia of Integer Sequences (to 1000 elements))

The period detection and related footwork is still missing, but with a linear time growth, the problem looks much more doable.

So, the bright idea:

Looking at various articles, it's mentioned several times that Scherml and Speigel proved that "The sequence (2, v) for odd v >= 5 had precisely 2 even terms".
It can also be shown that the second even number occurs fairly early in the sequence.

Since we're dealing with sequences of that form, after the initial terms to reach the second even term, the candidate numbers we're dealing with must be odd. Generating the new candidates is thus trivial, and, with a little housekeeping, the list of candidates to consider can be kept short on every loop.

I'm not sure whether to feel chuffed about spotting this, or annoyed that I didn't spot this earlier.

Wednesday, October 8, 2008

Paging Captain "Ya know, that's really pretty obvious"

Occasionally, it's useful to be able to write a one-line script (it's especially handy for pasting into IRC channels). Python's one-line capabilities are somewhat limited though. Statement lists (see the offical grammer) are always terminated by a newline. Thus, it's impossible to directly express the following snippet as a single line:

z=0
for x in range(5):
   z += x
print z


Of course, there are a vast number of ways to achieve the same effect using the constructs that can be placed on a single line, and, other than showing off, there's usually very little need to coerce something to be a single line.

Today, however, it occurred to me that it's also possible to abuse eval for this (I don't know why this only struck me today), leading to:

python -c 'eval(compile("z=0\nfor x in range(5):\n z+=x\nprint z", "test", "exec"))'


While not exactly readable, I think combination of eval, compile + a one-liner is just too amusing to ignore. I'm sure that eventually, somewhere, I'll be able to convince myself that this trick will be just what I need.

Thursday, July 31, 2008

Thoughts on test driven development

At the start of May. Simon and I redid the database layout for Sutekh, and, since then, have been working on fixing all the fallout of that. I recently spent a bunch of time working on finishing off some parts of the transition. Since we had a good idea of what the code should accomplish, I ended up doing most of this in a very test-driven fashion. Since most of my work is much more experimental in flavour, and doesn't thus doesn't lend itself to strongly test-driven development, it was an interesting exercise.

Some observations
  1. Having the test available is nice, especially given the number of interactions involved
  2. It tended to get sucked into "let just get this test working", and, as a result, the first version that successfully passed all the tests is a poster case for the difference between "working code" and "decent code". I'm still busy refactoring the code to amalgamate common bits, and there's still considerable work before the code is maintainable.
  3. I frequently erred towards being overly concerned with not breaking the tests. I ended up duplicating code unnecessarily in places as a result.
  4. Refactoring is made easier by the test, though.
  5. Largely as a result of 2, I don't actually have that good a mental map of the code, which feels rather weird. Spotting repetitions between the different code paths is thus quite time consuming.
  6. I do have quite a lot of confidence in the tests.
A fair bit of this list boils down differences in the manner in which code is produced. In my usual development model, by the time I'm satisfied that the code is doing what it should, I've spent a lot of time worrying about specific details and all sorts of implementation issues, and consequently, the code is vastly more polished. Here, because I was usually focused on short term gains, I have something which does what I want, but still needs considerable work before I'll regard it as complete. Also, as the list illustrates, I made the error of treating this as a bug-fixing exercise, rather than as development, so that's something I'll have to bear in mind in future. Point 5, though, is the real problem, though, and I'm not quite sure how to fix that, although things should hopefully be a lot better by the time I finish refactoring.

Still, despite my complaints about the resulting code, it did make the development a lot easier, and, for a part-time project, being able to deal with it in the smallish chunks of "let's get this test case working" did make it much easier to maintain momentum via visible results.

Tuesday, June 3, 2008

Curiosity is a funny thing

For various reasons, many to do with my instinctive distrust of university IT departments (what can I say, I've been around academia for too long), I find myself responsible for our departments web-server.
The web-server hosts various things, such as the course pages, a wiki for the South African OR society and a few other things.

Unsurprisingly, pursuing the logs reveals a great deal of refer spam, and, unsurprisingly, I have a set rewrite rules to deny access to obviously bad refers, and various automated steps in place to keep the blacklist updated, and some manual processes, since not everything can be automated. This does have the side effect that I have a automatically updated record of referrer spam in our logs. Which is where curiosity kicks in and asks "I wonder if there are any interesting stats to be gather from this?"

Perhaps fortunately, the data isn't well organised for analysis - I can't readily extract temporal information or frequencies of repeated patterns without correlating stuff against the logs, which is more effort than it's worth, but some simple keyword grepping is enough t at least roughly break things down into categories, which is already interesting.

So, based pretty much on the junk seem so far this year, dip's stats are:

Leading the way, at a little under 35%, are gambling related terms, with poker the big winner, followed by various spellings of blackjack.

Insurance surprisingly comes next - accounting for just over 20%. Medical and health insurance are the major keywords, with the vehicle insurance terms running a fairly distant third.

Next, at just under 10%, are various loan and debt management terms. Bills and debt are the most popular keywords here, with loans close behind.

Viagra and such account for around 7.5%

Porn does surprisingly badly, only accounting for around 5% of the cases - with a huge variety of terms used.

The rest is a mish-mash of music sites, link sites and various other junk., with nothing really worth singling out into a single category, although 1% is taken up by cigar and cigarette related links, which I find somewhat bizarre.

Well, at least I'm no longer that curious - in due course, no doubt, the bug will bite again, and I'll do the correlation against the logs, in which case, dear innocent reader, you shall be confronted by graphs (and even possibly pie-charts).

Friday, February 15, 2008

Humanity

I'm usually fairly upbeat about humanity. I generally believe that most people are pretty decent, and so forth, despite the, at times, overwhelming evidence to the contrary. On days when I have to be early, though, this tends to be much less true.

While part of this is due to my just not being an early morning person, and the consequent bad mood that puts me in, much of the blame is due to having to deal with early morning traffic. The selfishness, lack of forethought, general stubbornness and sheer stupidity to be seen in a few minutes of driving is enough to severely strain my tolerance.

Of course, this raises all sorts of questions: Is driving merely well suited to bringing out the worst in people? Are people always like this, and I just don't notice most of the time? Is it just because I'm really irritable at that time of the morning (and usually running late)? All of them?

Probably the only firm conclusion that can be drawn is I really do need to work harder at avoiding early mornings.

Wednesday, December 5, 2007

On criticism

I write short notes on every movie a see on the big screen. This is mainly to keep track of what I've seen, and to remind myself about the movies later.

Looking at the collection of comments, however, reveals a trend that I find rather interesting. The movies I like tend to get quite short entries (see the 2005's entry for the Incredibles for example), while the longest entries tend to be for movies I did not enjoy (see 2003's comments on the Reign of Fire, for example). While there are numerous short entries for movies I didn't enjoy, there are very few long entries about movies I did enjoy.

I'm not quite sure what this reveals about me, but it does suggest that I find it easier to analyze where something didn't work than what aspects did work.

While my behaviour is unlikely to change, it is an interesting observation.

Monday, September 17, 2007

Playing with panoramas

As anyone looking at my photos might notice, I'm rather keen on playing with my digital camera.

It's probably inevitable that, at some point, I'd be tempted by the idea of creating panorama shots. And, as people who attended my CTPUG talk on PIL can testify, I've sued very simple techniques (simple correlation matching, and PIL's blend stitching, without camera corrections) to demonstarate ideas in on a few occasions before, but never got around to actually doing all the heavy lifting needed to create proper panoramas. Fortunately, the beauty of open source software means I don't need to.

I've been aware of panorama tools for a few years, without ever getting around to playing with them. This changed when I recently discovered hugin, a nice GUI frontend for all the various panorama tools stages. The frontend is pretty intuitive, although it took me a while to grasp adding horizontal and vertical guidelines to help prevent unnecessary curvature of the horizon, and the result, when combined with enblend's stitching, is pretty impressive, I think. See this for example.

So, in short, expect more panorama's from me.

Tuesday, August 14, 2007

Musing on the Shipman's Tale

Every so often, the following joke (or variations thereof) winds up in my email.

Bob, a good friend of Bill, calls on Bill's pretty wife Sue one afternoon while Bill is away at work.

Bob tells Sue that he's always wanted to sleep with her, and offers her $50 to do so. She refuses, so he offers her $100. This continues until eventually he offers $500, and she relents. Bob pays the money and they do the dirty.

That evening, when Bill returns, Sue tells him "your friend Bob called today. That man has some strange notions". Bill replies "yes he does. By the way, did he give you the $500 he owes me? He said he'd do a turn around today to drop off the money."

The joke isn't very funny, but it has considerable longevity. Indeed, anyone who's read Chaucer will recognise that this is a simplification of the Shipman's Tale, and there's no reason to assume that the basic joke isn't a great deal older than Chaucer's version.

But it's not the age that interests me (after all, several such situational jokes can easily be traced back to the Greek comedies), but the rather significant change in emphasis between Chaucer and the modern version. In the modern version, Sue is very much the dupe. As a morality play, the moral is at best "don't compromise your principles for money, you'll lose". In Chaucer's version, though, Bob is the dupe. Sue spends the money, and Bob only learns that it's been paid to Sue when he confronts Bill about this, and is then stuck with the fact that, since he never told Sue about the loan, Sue has no reason to assume the money isn't a gift. Chaucer's moral is largely about the flow of information in a marriage.

Which leaves me with the question of when the shift in emphasis happened? Much as I'd like to blame the Victorians (who don't get blamed for enough of the ills of modern society, I feel), I suspect it's a much more recent reworking, but can't find any evidence either way.