Sam Dutton’s blog

C++, Python and other animals

Eliza lives!

leave a comment »

...in the form of IKEA's Anna!

Nice top

http://193.108.42.79/ikea-uk/cgi-bin/ikea-uk.cgi

Sample conversation below.

You just said : That's a lovely microphone you're wearing.
I have an outfit that my creators made for me, but because
I'm an IKEA Online Assistant, I don't wear real clothes.

You just said : Saucy!
I'm not sure what you're trying to exclaim. Please be a little more detailed if you can.

You just said : You wear virtual clothes?
I think you're confused or trying to ask me a question, but I need more than that
to give you a proper answer. Please try again.

You just said : Do you sell Volvos?
Transport is not something about which I'm programmed to discuss. Sorry.

You just said : Are you Swedish?
Let's talk about IKEA now.

Written by samdutton

6 June, 2009 at 4:22 pm

Posted in Uncategorized

Wolfram Alpha: don’t ask the wrong questions

with 2 comments

I’ve had a go at the Wolfram Alpha ‘knowledge engine’ preview.

Sadly, in my experience, it’s a bit disappointing: US-centric and effective only in specific, limited domains.

It gave no results for many of my queries, for example:

  • ‘What is the population of Adelaide’ (capital of South Australia)
  • ‘Tim Winton prizes’ (Australian writer)
  • ‘where is Kapunda’ (town in South Australia — misinterpreted as an animal, kakunda)
  • ‘where is Wandsworth, London’ (Wandsworth is a London borough — gives a ‘did you mean wadsworth’ response)
  • ‘why is DAB radio delayed’ (and variations — ‘Wolfram|Alpha isn’t sure what to do with your input’)

Alpha is a great project with a lot of potential – to provide well presented, accurate answers to questions asked in natural language.

But they better be quick or the world — or Google – will move on.

Written by samdutton

12 May, 2009 at 11:08 am

Posted in Uncategorized

Treat Yourself Right

leave a comment »

The UK’s National Health Service is running a good and sensible campaign on how best to seek medical treatment.

Thankfully they haven’t wasted any NHS cash on campaign artwork, resorting instead to pictures from a cheap and very cheerful People of Many Lands clip-art collection:

Treat yourself right

Beware the demented dentist

Unfortunately, their miniature ‘healthcare professionals’ don’t really look like real people. Don’t trust them — they’re zombies! Everyone has nice, healthy pink cheeks — even the black man!  The sweet girl with the almond-shaped face and plaits looks like she sprang from some dodgy old Ladybird story with a title like Little Running Bird’s Big Adventure. The guy with the bag (’You forgot your lunch!’) is meant to be ‘ethnic’ in some way. Is he Turkish or Portuguese, or a bit of both? And what do his triangular hair and big eyebrows signify?

But… It’s the technology that really worries me. The mad, waving dentist who’s been at the nitrous oxide — wild orange hair, Jaws teeth — has on his head one of those old torch things that doctors used to wear in cigarette ads.  What a fun guy, with his green latex hands! Another man is holding up what I think is meant to be a good-news X-ray, but looks like some scary relic of medical history.

If advertisements for the NHS computer department featured floppy disks and men wielding soldering irons, I’d be tempted to go elsewhere. I suspect that younger patients won’t even recognise these objects from a (thankfully) bygone age.

…and not to be picky, given the NHS’s daily miracles, but the dress sense of their mini-zombies leaves a lot to be desired. I can’t believe my National Insurance is funding their terrible wardrobe. Blue-and-green-should-never-be-seen was never more true, Mr Dentist  — and  big trousers, big red trousers, Mr X-ray White Stripes, I don’t think so…

Written by samdutton

9 March, 2009 at 12:32 am

Posted in NHS, Wandsworth

Tagged with

Bad language must be punished

leave a comment »

It’s time to get tough on the jive-talking jargonistas and lecture-circuit logopaths who persist in ****ing up the Queen’s (or President’s) English.

Renditionable words and phrases listed below.


Cute the first time, but not any more

goodness: when used in techy contexts, as in ‘filled with API goodness’ or ‘pure XSLT goodness’

love: as in ‘we’re loving the new desktop’ or ‘that kitten meme is getting a whole lotta love down here in W1′, ‘get a little API loveliness’

stuff: as in ‘cool stuff for your iPod’

-ista: as in Pythonista, Cameronista, jargonista (see above)

Down with the subculture

Any phrase like ‘down with my homies!’ or ‘epic fail!’, uttered by people who should know better: sometimes executives, sometimes after consuming stimulants, sometimes even with hand gestures.

Tough-talking Americanisms

barn storming

boil the ocean

chops: as in ‘Steve Jobs didn’t have the chops to stick it with NeXT’

deep pocketed

spin up: as in ‘once we spin up the project’

tie the bow: as in ‘once Google tie the bow on desktop integration’

No idea what these mean, but I don’t like them

bootstrapping

burndown: as in ‘can someone give me a sprint burndown’

business logic

cadence (in an ‘agile’ project management context)

captured all the givens

convergence in terms of delivery

decisioning

ensemble of features

meme

suite: as in ’suite of applications’ or ’suite of resources’

skinnable

tech spikes

thought leaders

tick all our boxes

user journeys

viral email

walled garden

workstreams

… and these are still bad

around: as in ‘issues around resourcing’ (i.e. problems with staff); a tertiary-educated alternative to the prosaic ‘about’ or ‘with’.

issues: see around. (It’s pathetic to whine when language morphs in ways you don’t approve of, but ‘issue’ did used to be useful, as in ‘a number of complex issues’. Now the word is just a posh or euphemistic replacement for ‘problem’ — which itself is now regarded as harsh, almost rude. Similarly, when I was growing up in Australia, the good word ‘got’ was declared non-U, or even taboo: we were taught to say ‘received a letter’ not ‘got a letter’. An English professor told me that at one school children were each made to write the word ‘got’ on a piece of paper – then they all went outside, dug a big hole and buried the words.)

offering: as in ‘Channel 4’s VOD offering’ or ‘the Salesforce CMS offering’, for some reason much loved by IT managers

Written by samdutton

26 February, 2009 at 6:42 pm

Posted in language

Tagged with

Snowpersons of Balham

with 2 comments

Written by samdutton

3 February, 2009 at 9:54 am

Debugging signals and slots in Qt

leave a comment »

Below are some suggestions for troubleshooting signals and slots in the Qt C++ library.

1. Check for compiler warnings about non-existent signals and/or slots.

2. Use break points or qDebug to check that signal and slot code is definitely reached:
- the connect statement
- code where the signal is fired
- the slot code.

3. Check that the parameter types of the signal and slot are exactly correct and, as appropriate, that they match.

4. Make sure you haven’t added a name to the signal or slot argument: for example, use textChanged(const QString &) not textChanged(const QString &text).

5. Check that the connect argument types and syntax are correct. The connect statement should look like this: SIGNAL(mySignal(…)), receiver object, SLOT(mySlot(…)). Check brackets, check that SIGNAL and SLOT are capitalised and that the sender and receiver are both objects, not class names.

6. Check that the signal is being fired as expected. You can do this with code like the following:
connect(this, SIGNAL(mySignal()), qApp, SLOT(aboutQt()));

7. Check that slots are declared correctly in the public/protected/private slots sections of your class declaration (not the public/protected/private sections).

8. If you use custom signals, check that these are declared correctly, with a void return type, in the signals section of your class declaration.

9. Make sure the Q_OBJECT macro is inserted at the beginning of your class declaration.

10. Check that classes using signals and slots inherit QObject or a QObject subclass.

11. Make sure to run qmake after adding the Q_OBJECT macro to a class.

12. Use break points or qDebug to check that slots are being called the appropriate number of times: make sure the connection isn’t made repeatedly.

13. Put all connect statements before functions calls that may fire their signals, to ensure that the connections are made before the signals are fired. For example:

   _myObj = new MyClass();
   connect(_myObj, SIGNAL(somethingHappend()), SLOT(doSomething()));
   _myObj->init();

not


   _myObj = new MyClass();
   _myObj->init();
   connect(_myObj, SIGNAL(somethingHappend()), SLOT(doSomething()));

14. Check that your connections aren’t affected by disconnect statements.

15. Don’t add a semi-colon after Q_OBJECT:

   {
   Q_OBJECT
   ...
   }

not

   {
   Q_OBJECT;
   ... 
   }

16. Check the return value of the connect statement: connect returns true if it successfully connects the signal to the slot.

17. Follow Qt’s naming conventions for signals and slots:

signal: somethingHappened()
slot: doSomething()

In grammatical terms, signal names are usually constructed from a past participle: changed, pressed, etc. They describe an event or change of state that has occurred. Slot names are imperative verbs and describe an action to be done: clear, setDate, etc.

Written by samdutton

3 October, 2008 at 3:07 pm

Posted in Uncategorized

Tagged with , , ,

Worse than slow

with one comment

Computers used to be slow*.

Now they’re unresponsive. 

Computer boffins have a word for it: latency. This is the delay between doing something (clicking the Submit button) and getting a response (’Thanks for your order’).

Latency can interrupt your flow of thought. Did I click the button? Is that link broken or did I just not click it properly?

Latency can wreck your day.  You press the Submit button twice (because it didn’t seem to work the first time) and your comment is posted twice, or you wind up with two sets of tickets to the same event. This can cause real problems for computer engineers: people press Submit buttons again and again and again, each time sending a new request to the website computer, thereby creating a lot more load than anticipated.

Mobile devices are worse, even at the top end: browsing the Web on a Blackberry or Nokia N95 can be soul destroying.

People often complain that their computer is ‘getting slow’. What they mean is that latency is getting worse. Usually this is either because they got viruses from dodgy websites, or they installed one or more virus checkers and ticked lots of options. An excess of anti-virus software can feel a lot like a virus.

This is where software like Firefox 3 and Google Chrome is getting it right. You click on a New Tab icon and a new browser tab appears. Press the Close icon (the X at the top right of the window) and the application window closes. No delay! Not like some browsers…

Best of all will be the ‘instant on’ operating systems like Splashtop, which start up in seconds and have browser software built in. 

The death of latency will make the world a happier place.


* And if you think slow means 56K, spare a thought for how it was in the olden days. In 1974 at Eudunda Area School in rural South Australia, we marked up computer punchcards with a pencil, eight characters per card, put the cards together with a rubber band and gave them to the teacher — who then, hopefully, parcelled up the cards, took the parcel to the post office, and sent it to a computer centre in Adelaide. There the cards would sit until some charitable person granted them processing time. Two weeks later a huge bag of gatefold printout would be returned to the teacher. Then you’d discover you’d marked up the wrong character in one column, or got the order of cards wrong, or — if you were lucky — just made a syntax error. Then the whole process would begin again… Hello World took me three months.

Written by samdutton

6 September, 2008 at 8:42 am

Chrome is quite good

with one comment

Highly scientific tests show Google Chrome to be a bit faster than Firefox and a lot faster than Internet Explorer.

Code mostly from WebKit and Mozilla, but hey…

Eventually I guess Chrome will be built in to ‘instant-on’ operating systems like Splashtop.

Maximised it looks like a desktop, with the blue colouring and tabs-on-top, like Google are expecting us to live there full time. Chrome gives Google a lot more scope to develop web applications and sooner or later I guess they’ll release a Chrome-only application. Assuming Google’s plan for world domination works out, Chrome will then become like a ‘runtime environment’.

Then in five years someone will have the bright idea of standalone applications that don’t need to run in a browser!

…and I love the euphemistically named ‘incognito mode’, presumably aimed at undercover freedom fighters. They’re all at it: IE8 has InPrivate, Safari has Private Browsing, Firefox has some other thing…

Written by samdutton

2 September, 2008 at 11:03 pm

Great Interface Mysteries #1: unresizable dialog boxes

with one comment

Lots of dialog boxes in Windows that should be resizable, aren’t.

This is very annoying and completely unneccesary: it’s simple to write the code so dialogs are resizable.

How can this be so after decades of Windows development?

This is one of the world’s Great Interface Mysteries.

Unresizable Windows dialog

Here’s the dialog box that pops up when you edit environment variables in Windows.

The box isn’t resizable so you can’t see all the text without copying it and pasting it somewhere else.

D’oh!

Below is the same but different.

I’d like to be able to see all the commands containing the word show, but I can’t because the box isn’t resizable.

Double d’oh!

The Options dialog in Visual Studio, with Keyboard selected

 

 

 

 

Written by samdutton

23 May, 2008 at 2:34 pm

Why is Find & Replace so hard?

leave a comment »

The Visual Studio 2005 Find/Replace dialog boxWhat is it about Find & Replace?

Noone seems to get it right.

Visual Studio 2005 is one of the worst culprits.

I guess the main problem is that as with so much Microsoft stuff, they seem caught between catering for beginner and expert – and wind up getting it wrong for both.

1. The box pops up the ‘9 occurrence(s) replaced.’ message in an oversized, separate window – but if you uncheck ‘Always show this message’, the confirmation message is displayed (miles away) on the window frame.

2. Those rather puzzling right-pointing buttons next to the text entry fields are disabled unless you use regular expressions or wildcards – but there’s no way to know that unless you’ve ticked the relevant box, which is hidden.

3. What the hell is ‘Quick Replace’ as opposed to ‘Replace’? Who cares?

4. There are effectively four dialog boxes in total: Quick Find, Quick Replace, Find in Files, Replace in Files. There could easily be just two, or even one.

5. Find & Replace in the HomeSite editor has a wonderful, simple feature: multi-line text fields. You can put line breaks in the find or replace text without scary stuff like regular expressions.

6. Anyway – pop-up boxes are annoying and slow – why not have a simple Find area in the window frame, as in Firefox?

Written by samdutton

23 May, 2008 at 9:39 am

Posted in IDE, Visual Studio

Python is (not) better than C++

leave a comment »

Python is great.

I love it: numbers of arbitrary precision, dictionary keys of any type, easy file reading, stuff like random.sample(xrange(1000), 10)…

Fantastic!

But…   Python is being sold for the wrong reasons.

In particular, Python is (of all the languages in all the towns…) compared to C: the archetypal boring, old fashioned and difficult language.  I have a hunch that most of this comes from Python evangelists who endured a grim semester of C but never went on to use C — or rather C++ — in real life.

In reality, different languages are not as different as some people make out.

 

With Python, you don’t have to worry about memory

Well — sort of. Except that you *do* have to worry about memory, as with any language. Objects take memory. Worry about it.

The difficulties of memory handling in C/C++ are over-rated:
1. Noone uses malloc() and free any more, unless they’re making a mistake or doing something unusual.
2. Most (or many) C/C++ objects are (or should be) allocated on the stack, in the scope of a function — in practice, this is much like garbage collection in other languages.
3. Lots of C++ code is written using toolkits like Qt, which allocate and free memory for objects and their children created on the heap (i.e. with new) without leaks.

 

Dynamically typed languages are easier

Really?

They’re easier because you don’t have to type in those pesky words like int and double.

…but they’re harder if you’re trying to work out what the hell a long and complex method actually returns, or takes as an argument.

So — a little bit yes, a little bit no.

 

Python is flexible

Because typing is dynamic? Since did you need s to be ’spam’ one minute and 42 the next?

 

Python is terse

So what?

Did you ever look at a piece of old code and say ‘This is wonderfully terse!’

Far better to understand code than admire it.

 

Python is fun!

This is sort of true.

You get much more ‘bang for your buck’ in the first five minutes of learning Python than for lower-level languages: open(’myfile’).read() can be pretty exciting if you’re used to file handling in C.

But once you’re up and running, the ‘niceness’ of a language doesn’t really matter. In fact, I sometimes think it doesn’t really matter what language you use: all that matters is how well you know the language and how well you use it.

 

Self is good, self is explicit

To me this is mystifying.

I think, again, it stems from developers trained academically in C, but unused to actually working with C++. Personally, I’d go nuts if I had to type in self every time I coded in C++. The idea that the self keyword removes ambiguity is daft. The C _private idiom is a much better alternative to avoid name clashes — and only very stupid C code has variables at global scope.
To my mind, self is just clutter — and as the first parameter of every method it’s annoying and confusing.
So there.

 

Python has loads of useful built-in types

Bring on the nasty null-terminated C character strings… Yuk. What a pain. Python strings are so easy! But who in their right minds (with some obvious caveats) uses C strings?

It seems that certain Pythonistas have never used the C++ Standard Library, let alone Boost or Qt or any of the other toolkits that are a normal part of C++ coding.

 

Python is instant: no need to compile! 

Well… sort of.

Except that you’ve still got  to wait for source code to be compiled into byte code.

In reality, recompiling a C++ program (if you haven’t changed header files) is not much slower than running the Python interpreter on a Python program.  My Pentium 4 running Visual Studio usually takes 5-30 seconds to recompile and run my (Qt GUI) app in debug mode. Even recompiling the whole program (25,000 lines or so) takes no more than a minute or two.

Bad C/C++ programs have lots of inter-dependencies that make recompilation slow. Good code use class decoupling and techniques like the PIMPL idiom to keep compilation fast, no matter how large the program.

In the end, it comes down to good code design: sensible idioms, pattern usage, and all the rest. Same for Python, C, C++ and every other language.

Written by samdutton

23 May, 2008 at 6:29 am

Posted in Python, c++

Tagged with ,