Project 365 – week 4

This is now the fourth week of programming 365. I have spent a large amount of time so far on Python and I’m starting to fall a little out of love with it. Although that is quite unfair, I think it would be fairer to say that I am falling out of love with the python challenges. Initially, they were about the right size for a Github post. This week (no doubt due to my lack of knowledge in the area), I have started to find them a little obscure. My main complaint is that they seem to slanted more towards riddles than towards coding. It’s not so much a Python challenge as it is a “let’s decipher what this is trying to get us to do”. This is of course a perfectly valid approach, but feels quite frustrating if you have a daily coding deadline. (either you have an inspiration or you don’t in which case you are kind of stuck). So now – going forward – I will instead focus a little on recapping some of the books I have been reading and using this as an opportunity to actively code my way through some of them…

Day 22

What? Python imaging library as preparation for Python challenge

What did I learn? A little bit PIL – how to open pictures, print information on them, save them in a different format.

Day 23

What? Python imaging library – a little more work

What did I learn? How to rotate images, manipulate individual channels, crop images, filter them

Day 24

What? Python challenge – level 7 (labelled 8 in github)

What did I learn? Application of PIL in the Python challenge

Day 25

What? Python challenge – level 8 (…)

What did I learn? How to use bz2, decompress

Day 26

What? More PIL – contrast, anti-aliassing

What did I learn? …

Day 27

What? More PIL – blur and contours

What did I learn? …

Day 28

What? Started to re-read C++ concurrency in action. Added some sample code from the book.


Project 365 – Week 3

Third week of programming 365, third post on it – same procedure as usual. This week I have spent almost exclusively on python challenges. It’s been pretty good fun and each level is a nice small, self-contained amount of work. Beyond that, I also wrote up some code about C++ unit testing (in particular the use of std::function). Let’s see what the next week brings: Man, I looked at the “to-do list” from last week’s post and pretty much all of that is still to be done! Maybe this week – who knows?

PS: On the upside, Lynn is starting to get used to the project (the number of threats to break up over it have gone from something than can only be stored in an unsigned 64-bit int to something that can be stored in the signed part of a short).
PPS: On the downside, a lot of the python challenge code is quite rough and could definitely do with a tidy. At some point the focus just became to get through the challenges rather than code them well (booo!)

Day 15

What? Python tutorial – standard library part 2

What did I learn? Some more standard library. I learnt a little about python threads and logging. Not quite as cool as the content of standard library part one, but still pretty useful.

Day 16

What? Python challenge – levels 0 to 2 (labelled 1 to 3 in github)

What did I learn? How to use string translation with translation table and how to filter strings for rare characters.

Day 17

What? Python challenge – level 3 (labelled 4 in github)

What did I learn? Some basic regular expressions. Which is great because I am a total noob at them!

Day 18

What? Python challenge – level 4 (…)

What did I learn? How to make a series of web requests and read the responses

Day 19

What? C++ std::function and unit testing code samples

What did I learn? Wrote an illustration of a technique that I came across earlier in the work to enable unit testing with mininmal refactoring in code bases ruled by C/C++ functions. See earlier post on the blog

Day 20

What? Python challenge – level 5 (…)

What did I learn? Pickling as a way of serializing/deserializing python objects

Day 21

What? Python challenge – level 6 (…)

What did I learn? How to work with zip files in Python

Project 365 – Week 2

I am now in the second week of the programming 365 thingy . This week I have put a lot less effort into the project. There just simply has not been the time to do any real “work”! Still, even though the week has been a lot slower, I have really appreciated how the project has forced me into doing at least a little bit of extra learning (20 minutes or half an hour) every day.

The theme of the week has been to finish the Python tutorial that I started last week. I am now almost there. (This shows how slowly the week went. Normally, I would maybe have done this kind of stuff in a day or day and a half.) Next week, I hope to make use of some of the stuff I learnt: maybe interact with Quantlib, maybe try out some NumPy and some of the json/http libraries and give the Python challenge a go too.

PS: I also need to spend a little bit of time to finish off / refactor some of the C++ code I did as well as clean the “Hello Python” solution.

Day 8

What? The Python tutorial – modules part

What did I learn? I learnt all about modules and how to import other python files and make use of functions defined in those files.

Day 9

What? Python tutorial – input and output

What did I learn? How to format strings and use keyword arguments in string formatting (useful way of organising arguments!). As well as file reading and writing (has really nice iteration facilities!)

Day 10

What? Python tutorial – exceptions

What did I learn? All about exceptions. How to raise and catch them. Inbuilt-ones. How to derive new ones. The try, else and finally statements (like else and finally – they are quite neat!)

Day 11

What? Python tutorial – classes

What did I learn? Really this was all about scope rules. Nested functions. What kind of variables you have access to where and how variables change when you modify them (Local vs non-local vs global)

Day 12

What? Python tutorial – classes

What did I learn? Class syntax. Writing a constructor, add methods & attributes. Instantiate objects, call member functions

Day 13

What? Python tutorial – classes

What did I learn? How member functions are bound to particular objects (or not as the case may be). Adding data members dynamically. Attributes are always public. Functions always “virtual”. How inheritance works. How classes really make use of nested scope in achieving what they achieve!

Day 14

What? Python tutorial – standard library – part 1

What did I learn? Some pretty standard stuff (files, path, os things and regexes) and some quite neat stuff. Http requests & responses. Deserializing json into python objects. Really neat acceptance testing. Some unit testing.

Project 365 – Week 1

This is just a quick more humanly readable update of what I have been up to in the programming 365 thingy this week. For a more code based version, have a look at the github repo.

Initially, I was going to write a big post once a week and explain what I had done, learnt, how the mood was for the day, how it contributed to the overall project… To do that, I started keeping some notes every day about the key points of the day. Having gotten a bit lazy (can’t try and find time to figure out the big picture), I will just post these notes instead. I don’t think the stand-alone-blog-post format is ultimately the right format for this. Maybe a separate page for it with some categories etc.? In the spirit of Agile, I’ll implement the content now and refactor it later. So without further ado here are the first week’s p365 notes.

Day 1

What did I do? Implemented a semaphore class. Semaphore class supports indeterminate, filo and fifo release. Wrote some sample code to show the semaphore behaviour.

How did the day go? Pretty successful day. Worked quite hard on different semaphores. Then pulled them together into one class with various impls.

What did I learn? How neatly one can work with condition variables. Overhead required for filo (notify_all) and fifo classes (notify_all and memory footprint).

Day 2

What? Unit test for the semaphore class. Check that a semaphore does not block when it shouldn’t. Tried out a new unit testing framework – catch. In particular liked the BDD style test facility.

How did it go? Okish – didn’t spend enough time in the morning / during lunch. Had a talk in the evening. So it was grab a couple of minutes whenever possible.

What did I learn? How to add catch to a project. How catch behaves with sections (multiple executions). How much better documented our unit tests would be with BDD. How catch compiles (slowly in the one compilation unit that has the main defined). How catch doesn’t like funky destructor behaviour (like e.g. the thread class has).

Day 3

Topic: Migrated tests to google. Added tests about blocked behaviour and filo ordering

Mood: Didn’t feel like much progress. A lot of familiar technologies, but learnt some stuff about futures.

What did I learn? Mutex undefined behaviour when it’s locked when it’s being destroyed (urgh). How to write “an infinite loop” type test in Google: Set off a thread and use the future status “status_not_ready”.

Had my first near miss: My sync failed and only my local commit worked. Luckily committing later on still seemed to work and the local commit set the time stamp for the github commit!

Day 4

Topic: Implemented some topics from chapter three of the Little Book of Semaphores by Downey.

Mood: Mixed – didn’t really learn much, but it felt good to revise the concepts from the book and find that I’m pretty comfortable with them.

What did I learn? That writing a rubbish implementation first is definitely something I do a fair amount of. Today I didn’t get round to nice-fying my implementation so that will have to be done tomorrow. Maybe TDD can help with that?

Day 5

Topic: Re-organised existing code into three separate projects. Much closer to the structure I want to eventually have.

Mood: Pretty good: I realised that I wouldn’t be able to do that much today (busy day otherwise) so I’m feeling happy with some tidy up even though I didn’t learn or do that much.

What did I learn? Am fairly happy with setting projects and solutions up. Learnt a little more about the “needs to have dll interface” warning. Also learnt that I still need to refer to Joshi’s book to write a self registering factory (argh!).

Day 6

Topic: Did a complete topic switch to learn a little bit of python.

Mood: Felt fairly ill (too much waiting in an empty, cold house) so decided to treat myself with working through (some of) the python tutorial.

What did I learn? PTVS is an awesome ide for python. How to install python on windows. Lots of basic stuff like variable assignments, control statements, imports, python interactive etc etc.

Day 7

Topic: Got a little bit further with the python tutorial

Mood: Took it fairly easy today. Running only through a little bit of the python tutorial. Starting to feel a little like this running through a tutorial has done all it can for now. Maybe another day of this and then I’ll try to actually write a little program with python?

What did I learn? Python has got some really neat features. Keyword arguments, arbitrary argument lists and arbitrary list of keyword arguments. Also had some really nice features for working lists and tuples.

Programming 365

In 2012, I spent a year taking a picture every day. I was cajoled, sweet-talked and tortured into this by one of my brothers. Around the web, this is commonly known as a project 365 (see mine here, but there are loads of truly stunning ones out there – including my brother’s).

In 2014, I want to do a different P-365 – programming 365. The idea is to write some code every day and make it available publicly. I’ll be committing mine to my github account. For an explanation of what github is, please click here.

The “rules” are simple:

  • Write some code every day
  • Make it available publicly

For the photography project I found that the project forced me to explore lots of different subjects, as well as experiment with techniques. It also really helped me master (or at least understand) the DSLR I had bought at the start of that year. I am hoping for something similar with “programming 365”.

So…. what kind of code am I going to write?

The honest answer is that I haven’t got a clue. It’s going to range from exploration (new languages, compilers, development environments, mobile/embedded, databases etc.) to techniques (TDD, BDD, pair programming). The individual days may well be completely stand-alone (“hello world in ruby”) or part of a theme (e.g. “Python” or “NoSQL databases”). I might even have a stab at a larger application. After all, a year is a long time…

What if I don’t have access to a computer?

Hopefully this won’t be too much of a problem with the amazing all-round development toolkit that is the surface. However, for days when I don’t have a computer I’m going to hand-write code (or at least pseudo-code) on paper and transfer it into machine form later on. I’ll also post the original handwritten stuff online for a laugh.

Have a go too

Part of what has made the project so much fun in the past is to do it together with other people. See what they do, comment on it and learn from it. “Enjoy the journey together” (for lack of a less cheesy phrase). If you want to have a go at this slightly weird experiment, please let me know. I’ll be starting on the 6/1/2014 and will be posting weekly updates on what I coded here (as well as the uploads over on github). Of course, you don’t need to begin at exactly the same time: Join whenever you fancy some fun programming! :o)