Archive for the 'Code' Category



21
Jan
13

Strategy Pattern

The strategy pattern is a behavioural design pattern. This means that it is a common communication method between objects and not concerned with how those objects are created or structured.

The Purpose

The idea behind the strategy pattern is to encapsulate the implementation details of an algorithm and make them interchangeable. This gives more flexibility in how an object can be used and enables each algorithm to be tested independently of the calling object.
Continue reading ‘Strategy Pattern’

Advertisement
07
Jan
13

Facade Pattern

This is the first of actual posts in my series on design patterns in python.

This will be about the Facade pattern which is a structural pattern.

The Purpose

The facade pattern is used to make one object with a simple interface represent a complicated system. The problem often occurs in programming where you have a series of interconnected classes where the functions must be called in a certain order or have complicated interdependencies.

This pattern is to give a standard interface to such a system, so you don’t have to rely on reading how you call the system in one of the files or look at example usage.
Continue reading ‘Facade Pattern’

07
Jan
13

Design Patterns in Python

This post is 2 things;

  1. A statement of intent
  2. An apology for inaction

Recently this blog has not been nearly as active as I would like it to be. This is due to many things but mostly me simply being very busy.

So that’s the apology done, now for the statement of intent!

I have intended to write a short e-book about design patterns using the python programming language. This is inspired by the aptly titled Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides who are collectively known as the Gang of Four (GOF).
Continue reading ‘Design Patterns in Python’

30
Oct
12

Auto

I don’t think this is widely known but auto was already a keyword in C++ and also C. Prior to it’s removal in C++09 it was used as a storage duration indicator. What this means is that it tells the compiler how long the storage for the variable needs to last for. The auto keyword is the default and means that the storage is available until the end of the block in which the variable is created. The fact that this is the default behaviour for C++ and it’s infrequent use lead to it being removed from the standard. As Bjarne Stroustrup writes

Several committee members trawled through millions of lines of code finding only a handful of uses — and most of those were in test suites or appeared to be bugs

So onto the new auto. Continue reading ‘Auto’

26
Oct
12

Mutable and Data Caching

This blog post is going to be about the c++ keyword mutable, it is also going to go into using mutable for data caching. To motivate this I am going to give an example from python. If I have a class with a property which is expensive to compute I want to cache it and only recalculate it when necessary. Continue reading ‘Mutable and Data Caching’

16
Jul
12

Finding Primes: Part II – A Python Implementation

As it is easy to get started I first wrote a prime finding algorithm in Python. I used a very basic algorithm for this. I store a list of prime numbers, and I check the numbers less than the square root of the possible prime, if any are a factor of the number I’m checking then it’s a composite otherwise I append it to the list of prime numbers.

The code for this is on my Box account here. Continue reading ‘Finding Primes: Part II – A Python Implementation’




Call Me
Endorse davidcorne on Coderwall

Categories

Copyright


© 2013 by David Corne.

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.