Stuff that occurs to me

All of my 'how to' posts are tagged here. The most popular posts are about blocking and private accounts on Twitter, also the science communication jobs list. None of the science or medical information I might post to this blog should be taken as medical advice (I'm not medically trained).

Think of this blog as a sort of nursery for my half-baked ideas hence 'stuff that occurs to me'.

Contact: @JoBrodie Email: jo DOT brodie AT gmail DOT com

Science in London: The 2018/19 scientific society talks in London blog post

Showing posts with label computers. Show all posts
Showing posts with label computers. Show all posts

Friday, 26 August 2022

Thoughts on starting to learn Python - I am rather new to it

While my colleague was away on his hols recently I thought I'd surprise him by having a go at learning Python so signed up myself for a week-long course (at a different institution). Every year he and other colleagues teach hundreds of undergraduates how to program in Python and Java (subject knowledge), but he also teaches lots of schoolteachers how to teach programming too (pedagogy). 

I expect we're moving in the direction of undergraduates being taught how to teach programming as well, because one of the skills they'll probably need in the workplace is to be able to teach new colleagues how to use new task-specific software. Anyway...

 

Gosh I was right to have avoided learning Python for this long, it's like Very Hard Sums ;) Much harder than I was expecting. I don't seem to be much of a computational thinker alas (learning to program not only teaches the obvious 'how to program', but also 'how to think a bit more logically about things', but sadly I may be a lost cause). Also, I have no particular impetus for learning programming (beyond annoying myself and amusing my colleague) as I genuinely can't see to what use I'd ever put it (and this has generally discouraged me from taking it up in the past).

That said, I've always been 'good at computers' and gravitated towards the nerds wherever I've worked - it's a constant surprise to me that I don't already know how to program or that I'm not a SysAdmin. Doing the course felt a bit like 'retconning' a missing patch from earlier in my life that probably should have been installed during or shortly after I left university. Ironically I do actually have a university qualification in Computer Science because I studied it for one year on my modular course (Biology, Psychology and Computing). I remember spending my holiday in a library in Harrow reading newspaper articles about IBM and Token Rings. We learned to program in SQL and had to make a thing that would calculate how quickly a bath would fill and empty, ostensibly for a property management company. 

Anyway I enjoyed the recent short course but it was a bit fast for me (or perhaps I'm a bit slow for it) and I found that if I wrote anything down there was a risk I'd miss something, which I would later have to rely on, so I mostly just tried to keep up.  

I didn't find the concepts of variables or types or int (integer) / float (numbers with decimal points) or string hard though - the thing I found hardest was actually parsing the English instructions for the exercises. I always felt I was missing something and asked a LOT of questions. The tutor and other students were very helpful and didn't make me feel too much like a lame duck.


It reminded me of doing AO maths (an alternative O level that's slightly more advanced, but not much). There was lots of lovely mechanics involved and trajectories, using formula like s = ut + ½at² where 'u' is the initial velocity. People smarter than me will immediately realise that the starting speed of a ball about to be thrown is obviously zero, but I have to admit that I once asked for help with that as the instruction had 'missed' it out. I seemed to lack the cognitive wherewithal to work that out for myself - oh dear! It looks like I am not very good at extracting, or abstracting, information from a paragraph of text and really need bullet points.

So this was pretty much where I found myself with trying to work out what I was supposed to be doing, let alone trying to convert it into a program. It was interesting to see under the bonnet of my own cognition - to see exactly where the limits are of my own capacity for understanding.

I did learn a lot by taking the solution and testing permutations, basically to see what happens when I tweak different bits of it, but I would not say that I have the sort of brain that finds it easy. I'm clever enough and reasonably logical, but possibly not quite clever or logical enough for Python. Also I'm 52 so possibly this would have been easier 30 years ago. Now i just want an easy life ;)

One exercise involved using the remainder / modulo function which I couldn't get my head around at all. I spent at least half an hour that day being absolutely baffled that anyone would ever want to know what was left over after a division. Surely if you divide 236 by 17 the only answer you want is 13.88 and not '13' or '88'. It featured in an exercise about leap years that I didn't really manage to get to grips with.

Later I was doing some work for our Charlton and Woolwich Free Film Festival and had a flash of inspiration about film times and the mystery modulo. 

If I want to express the time, in hours and minutes, of a film lasting 138 minutes then I don't want to say that it's 138/60 = 2.3 hours, I want to say that it's 2 hours and however many minutes. Aha! AHA!!

I actually managed to create a program that worked and told me the answer!!

138 / 60 means "what is 138 ÷ 60", and gives the answer of 2.3.

138 // 60 means "what is the whole number that results from dividing 138 by 60?", and the answer is 2.

138 % 60 means "what's left over once you've finished dividing by (really, subtracting from) 60?", and it's 18.

So a 138min film = 2hr 18min.

This is my 4-line program (text version at the end)

film_length = int(input("Enter the length of the film in minutes, e.g. 123: "))
hours = film_length // 60
mins = film_length % 60
print("The film is this long:",hours,"hr",mins,"min")
Which results in being asked for the length of the film and, when a number entered, gives the result. Pleasing.

Enter the length of the film in minutes, e.g. 123: 138
The film is this long: 2 hr 18 min

Process finished with exit code 0 <-- this is good by the way

I was pretty pleased to have worked it out for myself and for it to work exactly as expected. Going to see if I can try and write a program to do it in reverse, so you enter 2hr 18min and it gives you 138 mins....

 

Further reading
I'm enjoying reading (very slowly) and comparing these two books / PDFs, published 18 years apart:

How to Think Like a Computer Scientist: Learning with Python 3 Documentation (Release 3rd Edition) by Peter Wentworth, Jeffrey Elkner, Allen B Downey and Chris Meyers (17 April 2020)

and the first edition 'How to Think Like a Computer Scientist: Learning with Python' by Allen Downey, Jeffrey Elkner, and Chris Meyers (2002) (there's also an interactive version).

Text of the program, which I called jo_first_program_31_july_film_length.py

film_length = int(input("Entere the length of the film in minutes, e.g. 123: "))
hours = film_length // 60
mins = film_length % 60
print("The film is this long:",hours,"hr",mins,"min")





Saturday, 27 January 2018

Lovely things about graphic design which I enjoyed reading



Thanks to spotting a tweet from @simon_frantz I have just caught up with a brilliant article @stevesilberman wrote in 2012 celebrating the design work of Susan Kare. She was called in to work with Apple to create the icons and images that would help users find their way around a Mac's graphical user interface (GUI). She bought herself a pad of plain gridded paper and drew some images - each square a pixel - creating literally iconic designs that embedded themselves into our consciousness. Mouse pointers (hands), dustbins ('trash'), smiling Macs. I read the article with little gasps of delight, and recognition.

This also made me think about another lovely article on graphic design written by Dean Vipond a couple of years ago. He's a graphic designer who had to tweak a presentation he was giving to primary school children when he discovered they were reception class age (4-5) rather than 9/10. His beautiful essay "Explaining graphic design to four year olds" on how he distilled his work as a graphic designer into a talk that is wholly relatable to small children is wonderful and elicited the same gasps of delight and enthusiastic Twitter sharing as Steve's article will - when more people are awake tomorrow today and I can share it with them :)








It also reminded me of a tweet from @Pmarber (Patrick) I remember seeing in passing and making a note of so that I could go to the exhibition at the Jewish Museum (which is on until April 2018). It highlights the work of émigré designers one of whom is his cousin, Romek Marber, who created the layout for Penguin books according to the 'Marber grid'. Coincidentally the day of writing this blog post is also the Holocaust Memorial Day and on Googling Romek Marber I discovered that he had written a book about his own escape from the Nazis: "No Return: Journeys in the Holocaust". On further searching I found a really interesting archived review of his book from the Eye magazine (whose tweets about another unrelated event are below).




And, slightly different, but also a fun read / view - graphic designers take their most useless client feedback and turn it into these fantastic posters. This series of posters was exhibited in a café in Ireland and A3 copies were sold, raising money for a local hospital.








A lovely evening out with my friend Scott at St Bride's was for one of their TypeTuesdays, celebrating typefaces and all things font. This particular one was on trains 'Trains and fonts and double arrows' and it was GREAT. Or fontastic, sorry. See more tweets about this below to give a flavour.



Bonus inexplicable design
I remember the original Foyles bookshop on Charing Cross Road. They had a peculiar system in place that must have made sense to someone, though not to shoppers. Foyles "retained the extraordinary Moscow-style triple queueing system: customers had to line up to receive a chit, then again to pay at an Edwardian-style till, then once more to collect the book from where they had started." (quote from FT). They also had single-width escalators which I loved.

Vapiano is a German chain of restaurants which serves delicious Italian food. You queue to get your food which is prepared in front of you, then sit and eat it. This system does not work well if you are with one other friend and you want to secure a table. One of you has to stay and stop your stuff getting pinched while the other queues, then swap - the result is that you both have a delicious meal about 10 minutes apart. If I ever go there again (the food was nice) I'll either go by myself and take pot luck or gather together a posse of chums to offset the delayed serving times. Reviews of the restaurant (while praising the excellent food) tend to use the word 'weird' a lot.

Trains and fonts and double arrows - St Bride's Foundation, 22 Nov 2016
























Friday, 14 July 2017

Saved by a fax machine: the most ridiculous error I ever made with a computer

tl;dr version: I stuffed up a computer by mucking about with the regedit or .bat file and it wouldn't start. This was in the early 90s and the only way the company could help was by faxing me instructions to type into a new text file to save on a floppy disk from which I could then boot up. 
Fortunately it worked :)

In the early 1990s I used a computer system which controlled a chromatography pump*, for science.

At some point something went a bit wrong with the system and my boss suggested that I be a bit braver than I had been about fixing it myself so I read the manual and asked people in the computer department. I learned that I had to do something to the registry file, which underpinned the whole functioning. So I did.

After I'd done what I thought I was supposed to do the computer wouldn't switch on (well it wouldn't boot up and I couldn't interact with it), so I was now in a worse position. By now my boss agreed with me that I probably should have called in an expert and I was a bit worried that I'd seriously stuffed up the computer and rang the manufacturer to ask for help.

The company said that I'd need to boot the computer from a disk (which I didn't have) so they said they'd fax me a set of instructions - I don't think they had email at that time, though I'm fairly sure that I did (was working in a university), so a fax it was. The fax turned up and the program was pretty short - I went to another computer, opened up a .txt file in notepad, typed in the code and saved it with the appropriate file ending onto a floppy disk, put it in the moribund computer and switched it on. It worked perfectly ;)

I am just recording this small curiosity in the history of me killing computers...

*The pump gently delivered a stream of solvent, at a defined rate, through a long thin chromatography column which I used to separate components in my samples, for lipid chemistry purposes. The column contained a substance that slowed down - at different rates - all of the components in my samples as they passed through. This meant they came out the other end ('eluted') at different times and the amount of them could be measured individually. The separation was based on a relative attraction to either the solvent or the column's retarding material (also a little bit based on their size and other physico-chemical properties). This resulted in a complex mixture going in one end and individual components 'eluting' (it's a good word!) from the other end, for me to collect and see 'how much'. The computer provided a reading of the output based on the refractive index of the eluted solution (eluent), transferring this to an on-screen graph.