All entries for August 2008

August 29, 2008

Program Design

There are certain general precepts of program design that are quite general in nature, for example attempting to separate different components of a program away from each other so that if one needs to make changes to one component it only affects that component and not the whole program. A similar property that can be generally considered good design of a library is to reduce bugs in the usage of the library. The specific manner in which one implements these issues is quite specific to languages.

MissingPy is a library that aims to provide libraries missing from the Haskell standard libraries, by implementing a low level python binding and also some specific bindings on top of it. It seems to be relatively incomplete, and also implements things that are now part of Haskell – but the concept of giving an easy binding to python libraries offers general utility.

I was playing around with said bindings the other week, which caused me some frustration due to what I perceive as poor library design. The libraries themselves have a function called py_initialize, that it is necessary to call before any calls into the interpreter bindings are made. The unfortunate behaviour of this library is to segfault programs that call other methods before calling py_initialize.

Were one to implement this in an object oriented language a possible idea would be to have an interpreter class – and force initialization in the constructor. That way any execution of python code by your bound interpreter instance would have to occur after the interpreter had been initialized.

Unfortunately the translation of these concepts into Haskell was highly procedural in nature. ie one had to call the py_initialize – or be damned if they were foolish. This may be an appropriate choice in something like C – but not in a high level, strongly and statically typed language such as haskell. There are several viable solutions that I can think of – I strongly encourage readers to offer their own.

The simplest solution would be to have py_initialize return a value, that must be passed as an argument to other functions. One could export the type of this value from the module but not its constructor. This would ensure that any user of the module didn’t screw themselves (as I did 4 times in 35 minutes) by only allowing them to call the other function with this as an argument. Unfortunately – passing around immutable tokens in order to enforce security is a little bit ugly, it increases the length of the argument from every function, and is incredibly imperative. It also fails to hide the internal security of the module from the user.

An alternative, that I believe would be better, would be to introduce a new monad, that we shall call PY. Any function that involves a call to the interpreter would need to be in the PY monad. One would replace the py_initialize function with a runPY function that promotes oneself from the IO monad to the PY monad, and initialization could be performed here, thus statically ensuring that this module didn’t combine with my stupidity to cause my test code to segfault.

My point here is that idioms from different paradigms to the same basic problem can frequently be translated into alternative programming languages, but are unnatural in such a setting – resulting in errors that one wouldn’t otherwise expect. Yesterday Faux asked me if I felt programming for another 10 years would genuinely make me a better programmer. I cannot help but answer yes, there are plenty of things that I didn’t know 10 years ago, when I started programming, and plenty of things that I still haven’t figured out yet (list to be supplied on demand). The fact there will inevitably be new languages, new language features, new approaches and new idioms during that period means that I will need to understand solutions to existing problems, that I don’t yet know of. Norvig suggests I might have already reached competency – I hope that is right, but if you stop at competency you have already lost the game (as everyone reading this sentence has).


August 21, 2008

Olympics

I’m not interested in the Olympics at all – never gotten into it. I do like tables of numbers however! It struck me that everyone was going on about Britain doing well – which I neither deny, or want to detract from. What I was vaguely interested was in, was who was doing well in comparison to their population.

The following table scores countries performance by 3 points for Gold, 2 points for Silver and 1 for Bronze – which is entirely arbitrary, but I felt a better approach than the listings for official tables (Ordered by number of Gold Medals). if there is a scoring system somewhere, I’d love to know about it. These numbers are probably already out of date, since they use the figures from mid afternoon today, before I fell asleep. The population figures are taken from Wikipedia, and are all the most recent normative figures/estimates – rather than relying on aged, albeit positive, figures (eg a census).

i haven’t bothered formatting it particularly well, since as I say its already out of date. But I thought it might be interesting to someone else anyway. I’ll most likely try to write a complete version, once the olympics are actually finished, with more sanitized presentation. Ideally I’d like to be able to get better population figures, but that sounds like actual effort. A comparison with past events would also make excellent future work.

Score/Pop Country Gold Silver Brz Total Population Score
1.04166666666667E-05 Malaysia 0 1 0 1 192000 2
6.63227708179808E-06 Jamaica 4 3 0 7 2714000 18
4.43568260226713E-06 Slovenia 1 2 2 5 2029000 9
3.94649603771798E-06 Bahrain 1 0 0 1 760168 3
3.74286516328249E-06 New Zealand 3 1 5 9 4274800 16
3.72967328062062E-06 Estonia 1 1 0 2 1340600 5
3.2718981482412E-06 Australia 11 12 13 36 21394309 70
2.0639834881321E-06 Belarus 2 3 8 13 9690000 20
2.03617995610366E-06 Slovakia 3 1 0 4 5402273 11
2.003999983968E-06 Denmark 2 1 3 6 5489022 11
1.90186382655002E-06 Mongolia 1 1 0 2 2629000 5
1.88343622475672E-06 Norway 1 2 2 5 4778500 9
1.86368477103301E-06 Cuba 1 6 6 13 11268000 21
1.82025028441411E-06 Georgia 2 0 2 4 4395000 8
1.6655562958028E-06 Armenia 0 0 5 5 3002000 5
1.58102766798419E-06 Netherlands 4 5 4 13 16445000 26
1.50037509377344E-06 Trinidad & Tob 0 1 0 1 1333000 2
1.30390362336661E-06 Great Britain 16 10 11 37 60587300 79
1.19008657879861E-06 Lithuania 0 1 2 3 3361100 4
1.17842693098346E-06 Switzerland 2 0 3 5 7637300 9
1.15349832973442E-06 Czech Republic 2 3 0 5 10403136 12
1.12822142473682E-06 Finland 1 1 1 3 5318105 6
1.06295027754813E-06 Azerbaijan 1 2 2 5 8467000 9
1.04708780014445E-06 Bulgaria 1 1 3 5 7640238 8
1.03682813536828E-06 South Korea 8 10 6 24 48224000 50
8.97397547113371E-07 Panama 1 0 0 1 3343000 3
8.96146569750075E-07 Hungary 0 4 1 5 10043000 9
8.42951627545065E-07 Kazakhstan 1 3 4 8 15422000 13
7.9298442018845E-07 Romania 4 1 3 8 21438000 17
7.75516750076078E-07 France 4 12 14 30 64473140 50
7.16467590718801E-07 Ukraine 5 5 8 18 46059306 33
7.05673370563687E-07 Germany 11 8 9 28 82191000 58
6.89636561532073E-07 Canada 2 6 5 13 33350900 23
6.74207805828152E-07 Zimbabwe 1 3 0 4 13349000 9
6.58616904500549E-07 Croatia 0 1 1 2 4555000 3
6.54150695186072E-07 Italy 6 7 7 20 59619290 39
6.5111083306267E-07 Sweden 0 3 0 3 9215021 6
5.99060250660904E-07 Russia 13 14 18 45 141888900 85
5.64227948091029E-07 Kyrgyzstan 0 1 1 2 5317000 3
5.24746727712203E-07 USA 26 27 28 81 304909000 160
4.79563175494705E-07 Austria 0 1 2 3 8340924 4
4.7224303662557E-07 Poland 3 4 1 8 38115967 18
4.62379150903741E-07 DPR Korea 2 1 3 6 23790000 11
4.55897357966264E-07 Spain 3 5 2 10 46063000 21
4.40917107583774E-07 Latvia 0 0 1 1 2268000 1
4.35862790393584E-07 Singapore 0 1 0 1 4588600 2
4.26234748787895E-07 Kenya 2 4 2 8 37538000 16
3.58840943751682E-07 Greece 0 1 2 3 11147000 4
3.52416007518208E-07 Japan 8 6 9 23 127690000 45
3.04321363359708E-07 Serbia 0 1 1 2 9858000 3
2.9050062941803E-07 Tunisia 1 0 0 1 10327000 3
2.55735788396902E-07 Uzbekistan 0 2 3 5 27372000 7
2.04918032786885E-07 Dominican Rep 0 1 0 1 9760000 2
1.88270733314506E-07 Portugal 0 1 0 1 10623000 2
1.61733786187935E-07 Cameroon 1 0 0 1 18549000 3
1.51860288534548E-07 Togo 0 0 1 1 6585000 1
1.4991379956525E-07 Ecuador 0 1 0 1 13341000 2
1.48456057007126E-07 Tajikistan 0 0 1 1 6736000 1
1.38048715354864E-07 China 45 14 20 79 1325619000 183
1.36930028755306E-07 Israel 0 0 1 1 7303000 1
1.30434782608696E-07 Chinese Taipei 0 0 3 3 23000000 3
1.21617512921861E-07 Netherlands Antilles 0 1 0 1 16445000 2
1.19307040845362E-07 Chile 0 1 0 1 16763470 2
1.1333651128911E-07 Turkey 1 2 1 4 70586256 8
1.00983325128438E-07 Ethiopia 2 1 0 3 79221000 8
9.92508373110794E-08 Argentina 1 0 1 2 40301927 4
8.86053517632465E-08 Algeria 0 1 1 2 33858000 3
7.93169264367393E-08 Thailand 1 1 0 2 63038247 5
6.73959053393058E-08 Colombia 0 1 1 2 44513090 3
4.266621156041E-08 Brazil 1 0 5 6 187502000 8
4.17966717310301E-08 South Africa 0 1 0 1 47850700 2
3.74944344198908E-08 Mexico 1 0 1 2 106682500 4
3.68391969055075E-08 Afghanistan 0 0 1 1 27145000 1
3.5773438372257E-08 Venezuela 0 0 1 1 27953701 1
3.45382878507255E-08 Indonesia 1 1 3 5 231627000 8
3.20266461696131E-08 Morocco 0 0 1 1 31224000 1
2.28898426323319E-08 Vietnam 0 1 0 1 87375000 2
1.41852458633624E-08 Iran 0 0 1 1 70495782 1
1.3295043607743E-08 Egypt 0 0 1 1 75216000 1
3.5182811648466E-09 India 1 0 1 2 1136918800 4


August 2008

Mo Tu We Th Fr Sa Su
Jul |  Today  | Sep
            1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search this blog

Tags

Galleries

Most recent comments

  • Apart from the plea "can I have your old one?" (the yearning never diminishes) I'd like to leave you… by Sue on this entry
  • Unfortunately I still haven't seen a film for which you have to read up on quantum mechanics as I mi… by Sue on this entry
  • I've never been to watch a film before when it's been recommended that you first read up on quantum … by Sue on this entry
  • Well this is very interesting, i really liked reading this blog, this was very informative and very … by Mio Navman Spirit S300 on this entry
  • I thought it was fascinating. Griffin isn't like any other, media–trained, polished politician, and … by Tim on this entry

Blog archive

Loading…

Hello

Not signed in
Sign in

Powered by BlogBuilder
© MMXXI