Jamie's Blog

The ramblings of a programmer with a little too much time on his hands

Tag: Software Development (Page 1 of 2)

Cropped code image

Mono, Xamarin and Gtk#

Over the past few weeks I’ve been playing with cross platform development tools. With Microsoft’s announcement of the Visual Studio Code preview [LINK], the latest version of Mono (version 4.0, built against the C# 6.0 spec) [LINK] and Microsoft open sourcing their entire Core CLR for .NET [LINK], now is the time to be developing in C# (if not before).

If you can’t tell already, this will end up being a post about programming.

One of the many great things about Microsoft open sourcing the Core CLR is that many years of research and development over at Microsoft has just become available to us developers, for free. We’re talking things like garbage collection [LINK], cryptography [LINK] and a whole host of other features.

Also, since the Core CLR is so ingrained into the Windows kernel (there haven’t been any major “scrap it and rewrite it from the ground up” kernels in Windows since NT first came out) that Microsoft are basically ensuring that any code written using the Core CLR is going to run, without major issues on all versions of Windows to come.

Not just the desktop and tablet ones, but the mobile and gaming platforms too.

It also means that code written for the Core CLR can be ported to non-Windows platforms extremely easily. As long as the C++ that it’s written in will compile for the target system, then it’ll be available for it (and the code for the CLR is really well written).

Mono

So Mono is an open source version of the Core CLR (the project had begun several years before Microsoft open source their Core CLR), amongst other things. It’s been written with cross platform development in mind, which means that there are precompiled binaries for Linux, Mac OS and Windows.

The Mono development team haven’t shied away from using any of the recently open sourced Microsoft code in their version of the C# compiler, too [LINK]. Mostly, they’re using the code as either source material for implementing their own versions of some of the C# features that have been buggy or not fully implemented in the past.

Xamarin

Xamarin are the company who own the intellectual property rights for the Mono project. There’s a long story behind it, but the short version is:

  • Mono is developed in mid 2000 as a way of getting the .NET CLR on Linux by Ximian
  • Novel bought Ximian in 2003
  • Attachmate then bought Novell in 2011
  • Attachmate lays off hundreds of layoff at Novell (including Mono staff)
  • Xamarin are granted full licence to work on all Mono products

Xamarin then went on to make Mono Develop, which was cross platform IDE for Mono. In early 2013, Xamarin announced Xamarin Studio which is based on Mono Develop, but with many advanced features.

Xamarin Studio is able to read and work with Visual Studio projects and create iOS, Android, OSX and Windows applications. It also has most of the features available for Visual Studio (code completion, advanced debugger, UI designer, etc.)

What’s All This Got To Do With Me?

Well, since I’ve been playing around with Mono and Xamarin Studio, I thought I’d write a little about it. I’ve been using Xamarin Studio on my laptop (mid 2010 Mac Pro) for developing some applications and writing some throwaway code.

Why use the Mac?

Mainly because it’s small, fast to boot up and I can take it with me places.

Seriously, if I’m travelling anywhere (say I have a long journey ahead of me) then I can pull down my latest code and do some work while I’m sat around waiting to get where I’m going. It works too – I get quite a lot done on those long journeys (I used to watch a film or something, but now I’m way more productive).

The code view is very similar to most IDE’s (it feels like it is modelled after Visual Studio).

Xamarin Studio Code View

Some filenames have been censored due to the nature of the code being worked on

The designer uses GTK# (a wrapper for the GTK+ library) version 3 for GTK enabled projects.

Xamarin Studio Designer View

Some filenames have been censored due to the nature of the code being worked on

What Do You Think of Xamarin Studio?

It’s really quite nice,  and very similar to Eclipse and Visual Studio. I really do feel that users of both of those two IDEs will get on well with Xamarin Studio.

However, and I’m not sure whether this is specifically my laptop or not, I’ve noticed a few crashes on opening Solution files. This tends to happen when I’ve got the GitHub GUI open at the same time as Xamarin Studio, so perhaps there’s a file lock issue?

I’ve noticed a similar issue with the GitHub GUI when I’ve got Xamarin Studio open: opening the GitHub GUI after making edits with Xamarin Studio (but having not closed Xamrin Studio), I’m told that I’ve made no edits to any files in the repository.

Plain Sailing?

Not really. I had a bit of a massive issue with compiling and running some Mono code using Xamarin.

When developing on Windows using .NET and C#, Windows does some smart things when creating an instance of the compiled program for execution. One of these is to figure out which system DLLs need to be loaded for the program to run. On non-Windows environments, using Mono this is slightly broken.

What’s meant to happen is that all of the Windows DLLs are mapped to Mono binaries that are compiled for the target OS (OS X Yosemite, in my case). However, this isn’t done automatically, which leads to a lot of instances of errors like this one:

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for Gtk.Container ---> System.DllNotFoundException: gtksharpglue-2
at (wrapper managed-to-native) Gtk.Container:gtksharp_gtk_container_get_focus_child_offset ()
at Gtk.Container..cctor () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gtk/generated/Container.cs:79
--- End of inner exception stack trace ---
at Gtk.Bin..ctor (IntPtr raw) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gtk/generated/Bin.cs:15

After a LOT of Googling and a LOT of reading about how Mono handles DLL mapping, I found a really good and concise answer on StackOverFlow (one of my favourite websites, ever – seriously, there’s a Stack Exchange for every possible subject):

http://stackoverflow.com/a/15655635

The extremely short version is that there needs to be a shell script in the binaries folder which will call the mono runtime with the compiled program as an argument, but also ensuring that the correct Mono library is loaded into /usr/lib before running it. The shell script needs to be run for the compiled binaries to run correctly.

In case the answer is ever removed, or the  link doesn’t work for some reason, here is a copy of the shell script that needs to be written:

[sharp]!/bin/sh
export DYLD_FALLBACK_LIBRARY_PATH="/Library/Frameworks/Mono.framework/Versions/Current/lib:$DYLD_FALLBACK_LIBRARY_PATH:/usr/lib"
exec /Library/Frameworks/Mono.framework/Versions/Current/bin/mono ./binaryNameHere.exe

Swapping out [sharp] for an # and binaryNameHere for the name of the binary to run, obviously.

Platypus can also be used to wrap all of that up into a native .app file, too. So that’s cool.

Anything Else?

You’re quite right, I’ve rambled on for long enough as it is.

Oh, one last thing before I go: I’ve been thinking about getting one of the CODE keyboards [LINK], because I keep hearing great things about mechanical keyboards. Although I have used them in the past (all of my early computer experiences include mechanical keyboards), I’ve not had the chance to try one properly as an adult.

Anyway, I’ll leave it at that I think. We’re getting close to 1300 words, which won’t be fun for you to read I guess.

Until next time, have fun!

Previously on Jamie’s Life:

Software Development

In the past few weeks, I signed up for a thing called GitHub. For those who don’t know, GitHub is one of the many channels through which to share Open Source code – most of the code I write in my personal time is Open Source. It also has a really good version control system, so as soon as I (or anyone who wants to collaborate with me on something) make a change, the original file is backed up, and the changes are saved alongside it. For those who want to know, my GitHub page can be found here [LINK]. I’ve only added a single project so far, but I’m going to be adding more and more projects as I get more used to using it.

Santa Who?

This weekend, seeing as it was a public holiday and all, I travelled down to Milton Keynes to see a close friend of mine.

Lee: Rome wasn’t built in a day, you know. Tim: Nah, that was Milton Keynes.

While I was down there – and aside from catching up with my good friend, Lee – I took in an afternoon at Santa Pod, saw Act of Valor (you should, totally see this movie), saw Kelly’s Heroesfor the first time, and went Go Karting in the rain.

 To a New Yorker like you, a “Hero” is some type of weird sandwich, not some nut who takes on three Tigers [tanks]!

Santa Pod is, basically, a drag racing strip. We went there on the promise of drifting. What we got was drag racing, a monster truck that killed itself on a selection of pre-flattened cars and a view of some awesome cars. …Oh, and one awesome pilot showing his stunt skills. I’m not going to harp on about Act of Valor. Except to say that if you like any kind of action or war movies, you should see this one.

Go Karting in the rain, you say?

That’s right. We were booked in to do some mid-morning karting on the Monday, and we didn’t let the rain stop us. We went out there and… and… slid about, mostly. We paid for 30 minutes out on the track, and we had loads of fun. I would really recommend outdoor Go Karting to anyone. I don’t even drive, and I can do it. Lee had attached his action camera to the side of his helmet, but it doesn’t seem to have taken any footage; which is a shame because I managed to pull off – by all accounts – an amazing spin.

All in all

So, all in all, a great weekend was had.

It’s such a shame that the GPS on my phone let me down… 4 times on the way to the Go Karting. Felt like a bloody fool having to ring for direction several times, I did.

I think that I may have been bitten by the slightly-more-extreme-than-sitting-around-doing-bugger-all-sports bug. As I’m quite excited at the prospect of going Canyoning in July, too.

I got back home, just over 2 hours ago and I have to be up at 6. So, I’m not going to bother going to bed – I wouldn’t get enough in the way of full REM cycles, anyway.

Oh, well. Until next time. Stay frosty,

J

Astounding Times

A friend of mine shared a link on Google+ today, that set me thinking.

It a (condensed) life story of an 86 year old man. A man who adopted to different technologies as and when they where invented, whereas his children didn’t. I’d go and give it a read, here is a link. I’d highly recommend reading it. You’ll have to zoom in, though, as it’s a massive file.

Not only is it an exceptional story, but it’ll help put this post into context

I’ll give you a few minutes to read through the one-shot web-comic that I’ve just linked. Go on, I’ll still be here when you come back.

Truly Astonishing Times

After I’d read that web-comic, I was speechless. When I found my voice again (read: “recovered from the message in the web-comic”), I felt compelled to write this comment on the Google+ post:

All those things. Can you imagine going through the birth, adoption and abandonment of different technologies and ideologies? I sure can’t.

I mean, I can remember not having a mobile phone or an email address. But I can’t really remember what it was like in the late 80’s/early 90’s (born in the mid 80’s).

I remember watching the footage of the “liberation of Iraq” or “occupation of Iraq” or whatever it was that they called it [from a few years back], but I don’t think I could imagine being told that the whole world is at war.

I have fond memories of playing on my Nes, Mega Drive, N64, Playstation, Dreamcast, Xbox and such; but I don’t think I’ll ever experience what it’s like to realise that you can play a game (one that would take a very long time to set up otherwise) on your TV, in seconds.

I remember my first mp3 player, but I can’t imagine what it was like being told that you could get a whole LP record (both sides) onto a single compact disc. THEN being told that you can fit your entire music library on a tiny device that fits in your pocket. AND that you can have more music in your library in seconds.

We live in exceptionally astounding times, but I don’t think we ever take the time to sit back and realise what we have.

Mulling This Over

To be honest, being a computer programmer, I suppose that I have a great opportunity and an excellent position from which to view this all happening. But my problem is that I understand how most of it works  on a technical level.

Maybe not completely at first, but a little bit of digging and a whole lot of intuition/past experience helps

Less:

Push “play”

Listen to music

More:

User pushes “play”

Program sends message to Operating System

Operating System forwards message to program that is running

Program sends message to Operating System requesting permission for file from storage

Operating System sends file permission details back to program

Program hooks into codec database and intuits the type of file

Program de-compresses the file and sends packets of data to the Operating System, routed for the sound system

Sound system sends converts these data packets and sends them down the cable to the loud speaker/headphones

Whilst I don’t have the knowledge of a techo-voodoo-wizard, I can figure out most things and have the experience required to even figure out where the ideas came from or even design one of my own.

The Layman

I see the opposite end of my view point, almost daily.

Most of the people who come through the place where I work (at the minute) are from the Middle East and – readers are kindly asked to eschew politics and any preconceived ideas for a moment – a lot of them have never used “modern technology” before.

By “modern technology” I mean… well, I’ll provide you with an example:

I deliver IT classes to a bunch of such people. And one day I was giving a class on E-Mail and The Internet. It only considered simple stuff from a simple perspective. I remember saying things like “The Internet is a way of connecting all of the computers in the world, that way we can share things easier.”

Anyway, at one point I was walking around the group helping them to set up a free web based E-Mail account. I came across a guy who was staring at a blank screen. “What’s wrong?” I asked.

“How do I turn this on?”

This guy was 23 years old, and had spent the last 4 years of his life in the UK. Yet, he’d never encountered a Laptop before.

That might sound stupid, but I come across it every day: people, both young and old, who have never had access to things that we consider “essential” technology in their lives.

 How many people do you know who can’t leave the house without taking their mobile phone with them?

Thinking About It

I’ve typed all of this in less than half an hour (including formatting, shoving links in, providing tagging and categories and location data), on a computer that is performing the following tasks at the same time:

  • Ripping (copying) a 10 CD album to a (mathematically) lossless, compressed format
  • Playing music located on a server (a type of computer) on the other side of planet
  • Running a script (small set of commands) that checks my 3 email inboxes ever few minutes
  • Providing me with intimate details about my CPU and network usage
  • Running 3 copies of [email protected] (helping to provide mathematical information on the process of protein folding)
  • Providing me with up-to-the-minute information about the weather in my home town
  • Synchronising (copying music, movies, pictures and such to) my iPod touch
  • De-fragmenting (moving the individual parts of files closer together) an entire 500Gb hard drive
  • Running an modern Operating System
  • Downloading a few episodes of a web-based TV show

Along with that, I’m using a mouse and keyboard that have no cables or wires. I have, at my feet, a laser printer (high quality, expensive to set up, cheap to run) that is able to churn out printed pages faster than most ink-jet printers (medium-to-low quality, cheap to set up, ridiculously expensive to run) that I almost never use.

I was, earlier on today, watching several hours of video footage that was produced on the other side of the world and provided to me for free.

Meditating On It For A While

Seriously guys, we really do live in astounding times: I can press a button and have a TV signal streamed to my computer screen from Japan in seconds. You have to admit, that’s astounding.

And if not, then what is?

  • Storing an entire, and continually growing music library on a device that isn’t much bigger than a pocket notebook?
  • Chatting with friends in different time zones, while having a VoIP conversation (think “Skype”) with someone on the continent?
  • Buying Christmas shopping without having to leave the chair in front of my computer (except to get my credit card)?
  • Helping (albeit in a tiny way) to understand the spread of disease, terminal illness and genetic disorders WITHOUT HAVING TO DO A THING?
  • Using wireless devices to type commands and manipulate software from the other side of a room?
  • Touch screen devices that fit in your hand?
  • Reading your E-Mail on the train/at a bar/while waiting to see a doctor?
  • The ability to contact ANYONE at ANY TIME of the day or night?
  • A whole community of people coming together to help a small, or sometimes very large amount of people out?
  • E-Mailing/Personal Messaging/Whatever-ing a celebrity/musician/artist/band instantly AND RECEIVING A PERSONAL RESPONSE in a very short amount of time?

That reminds me that I should E-Mail Choke Sleeper again, some time

Any of these ring any bells with you? Imagine trying to perform these tasks 10 years ago. Hell, 5 years ago.

Something to think about, the next time you have some kind of technical trouble with your computer/smartphone/media player.

Until next time,

J

Random Quotes Generator Screenshot

Random Quote Generator

Edit (18/01/2013)

I have edited this post on the above date. However, the only change that I have made is that I am now hosting the source code (found at the end of this post) on GitHub. This means, that if I need to make a change to the code, I do not have to edit this post again – as it will pull the latest version of it from the relevant page on GitHub whenever it is accessed by a reader.

So, I was looking through some of my old hobby code today and happened on an old quote generator. It’s a neat little (the executable weighs in at 24Kb) C# program that provides the user with a random quote from some of my favourite TV shows.

Random Quotes Generator Screenshot

A screen-grab of my Random Quote generator showing a picture of Professor Ueda Jiro and a quote from the TV show Firefly

The Algorithm

  1. Find a text file called “Quotes.txt”
  2. Load each line in the text file into an element in an array
  3. Display a standard Windows form with a picture and a text box.
  4. When the user pressed the “Generate Quote” button, ‘randomly’ pick one and display it in the text box.

The Code

The code itself is pretty simple. It compiles on .NET 2.0.50727 and will only run with a text file called “Quotes.txt” located in the same folder as the executable.
[gist https://gist.github.com/4569288 /]

For those wanting to compile this code, you’ll need to provide Visual Studio with a JPEG image. In the original solution, I called this image “Dontokoi!” (as this is the catchphrase of the character in the image). Without this image, I doubt that the program will execute correctly.

Post Mortem

Aside from the above comment about the image being required for compilation, I did notice another potential problem with the program.

For some reason, apostrophes (‘) aren’t rendered correctly when the accompanying text file is encoded in anything but UTF-8. Since I know very little about text file encoding and the default way that the .NET libraries import text into a string array and the way that .NET draws this text into a text box, I can only assume that the problem is related to the formatting of the text file (saved, using Notepad++).

Either that, or it’s related to one of the settings within the Visual Studio IDE itself. I do remember that, around this time, I was attempting to compile all of my code with direct support for Unicode, so maybe that’s it.

I’m not sure, to be honest. But I am planning on opening the solution file (at some point) and having a good look around. The reason I haven’t opened the solution file at the minute is because I don’t own a copy of Visual Studio; which makes opening a Visual Studio file quite difficult.

Here’s a link to a zip of the entire solution, in case you wanted to take a look (The executable is in Bin/Release along with an old Quotes text file) [LINK]

Until next time,

J

Problem Six – In C

EDIT (18/01/2013)

I have edited this post on the above date. However, the only change that I have made is that I am now hosting the source code (found at the end of this post) on GitHub. This means, that if I need to make a change to the code, I do not have to edit this post again – as it will pull the latest version of it from the relevant page on GitHub whenever it is accessed by a reader.

 

Reading a comment on my most recent post, I felt that I could optimise my code for Project Euler’s Problem Six. So, I went away and read up on the information provided by Kristan (in the comments section), and decided that I’d give it a go… in C.

There were a few reasons for switching to C, the biggest was that I only have a C compiler installed on this machine (a minimal install of MingW), another being that I’m a little more informed about the optimisation options (which I didn’t use for this project) that gcc provides.

Anyway, on with the code.

Firstly

This is a solution to problem 6 on Project Euler. I’ve not posted it up here to gloat, or to provide answers for cheats. I’ve posted it, so that you can see how I solve this kind of problem.

The original problem reads like this:

The sum of the squares of the first ten natural numbers is,

12 + 22 + … + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + … + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 – 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

The Algorithm

Based on my code from the previous version of this project, and the knowledge provided by Kristan and The Internet at large, I’ve used a slightly different algorithm this time around. I’ve covered the algorithm in the comments section for my code, though. So, I guess you should just scroll down and read that.

I’m not a massive fan of providing information twice, in the same format. That and redundancy. That and redundancy

The Code

I’m not going to spend time explaining the code, since it contains enough information in the comments (within the code itself) and in the description of the algorithm above.

So, without further ado, here is the finished code:

By the way, I compiled this code with the following command:

gcc “Problem_Six_In_C.c” -o “Problem_Six_In_C.exe” -Wall

A simple problem with an extremely simple, now optimised,  solution.

Here’s a link to the c file: LINK

Until next time,

J

Sums and Squares – Or: How I Solved Project Euler Problem 6

Edit (18/01/2013)

I have edited this post on the above date. However, the only change that I have made is that I am now hosting the source code (found at the end of this post) on GitHub. This means, that if I need to make a change to the code, I do not have to edit this post again – as it will pull the latest version of it from the relevant page on GitHub whenever it is accessed by a reader.

Firstly

This is a solution to problem 6 on Project Euler. I’ve not posted it up here to gloat, or to provide answers for cheats. I’ve posted it, so that you can see how I solve this kind of problem.

The original problem reads like this:

The sum of the squares of the first ten natural numbers is,

12 + 22 + … + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + … + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 – 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

The Algorithm

There’s only one way to solve this problem.

This one is real simple – dependant on your understanding of Mathematics – assuming you can understand Square Numbers.

It’s a two step approach:

  1. Sum (add up) all of the squares of the numbers between 1 and 100
  2. Sum all of the numbers between 1 and 100, then square the answer
  3. Then find the difference between them (subtract one from the other)

There’s a slight problem with this method, though. Skipping ahead – and, hopefully teaching you all a little about speed-of-light Maths – we get:

There is a well known story about Karl Friedrich Gauss when he was in elementary school. His teacher got mad at the class and told them to add the numbers 1 to 100 and give him the answer by the end of the class. About 30 seconds later Gauss gave him the answer.
The other kids were adding the numbers like this:
1 + 2 + 3 + . . . . + 99 + 100 = ?
But Gauss rearranged the numbers to add them like this:
(1 + 100) + (2 + 99) + (3 + 98) + . . . . + (50 + 51) = ?
If you notice every pair of numbers adds up to 101. There are 50 pairs of numbers, so the answer is 50*101 = 5050.  Of course Gauss came up with the answer about 20 times faster than the other kids.

That version of the story comes, courtesy of Dr. Math. The actual story has been around for… well, since the days of Karl Friedrich Gauss

Anyway, skipping to the end, we find that the sum of all the numbers from 1 to 100 comes out at 5050. A quick calculation tells us that 5050 squared (5050 * 5050) is 25,502,500. Quite a big number, wouldn’t you say?

That’s fine, but logic tells me that the other number I’m working out (the sum of the squares) will be huge, compared to this one. So, and int just wont do it.

Dependant on your system, an int can store a value between +2,147,483,647 and – 2,147,483,646 (32 bit)

So because of this, potentially, massive answer, I decided to code this by using an unsigned long long (sometimes called a long int) type.

Again, dependant on your system, an unsigned long long can store a value between 0 and +4,294,967,295 (32bit)

Of course, I’m running 62 bit, so the maximum values that these two variable types can hold are doubled. But that’s not the point.

The Code

I’m not going to spend time explaining the code, since it contains enough information in the comments (within the code itself) and in the description of the algorithm above.

So, without further ado, here is the finished code:


A simple problem with a simple solution.

Here’s a link to the cpp file: LINK

Until next time,

J

Pining For Primes – Or: How I Solved Project Euler Problem 5

Edit (18/01/2013)

I have edited this post on the above date. However, the only change that I have made is that I am now hosting the source code (found at the end of this post) on GitHub. This means, that if I need to make a change to the code, I do not have to edit this post again – as it will pull the latest version of it from the relevant page on GitHub whenever it is accessed by a reader.

Firstly

This is a solution to problem 5 on Project Euler. I’ve not posted it up here to gloat, or to provide answers for cheats. I’ve posted it, so that you can see how I solve this kind of problem.

The original problem reads like this:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

The Algorithm

Firstly, there are two ways to solve this problem. One involves brute force, and one requires a little savvy.

Technically, there are a whole bunch of ways to solve this problem – dependant on your understanding of Mathematics. Hopefully, both of these methods will be simple enough to follow – assuming you can understand Prime Numbers.

The brute force check goes like this:

  1. Start at n, check this against all numbers in m
  2. If n divides evenly (i.e there is no remainder) by all the numbers in m, stop. This is the answer
  3. If not, add 1 to n and start again.

“n” starts at 1 (this is the smallest positive number that will divide by all the numbers from 1 to 20)

“m” starts at 1 and goes only as far as 20 (this is the series of numbers that “n” has to divide by)

That’s it.

The smarter algorithm goes like this:

  1. Start with n at 2520
  2. If n divides evenly (i.e there is no remainder) by all the numbers in m, stop. This is the answer
  3. If not, add 2520 to n and start again.

This method assumes that you recognise a few things from the problem statement. Let’s take another look:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Since the numbers between 1 and 20 contain all the numbers between 1 and 10 (1, 2, 3, 4, 5, 6, 7, 8, 9 & 10), some of the work is done for us. We can assume that, since 2520 is evenly divisible by all numbers between 1 and 10, that it must be evenly divisible by all the numbers between 1 and 20.

This algorithm speeds up execution exponentially. Instead of going through every positive integer between 1 and he final answer, we can jump in steps of 2520.

The Code

I’m not going to spend time explaining the code, since it contains enough information in the comments (within the code itself) and in the description of the algorithm above.

So, without further ado, here is the finished code:

And there you have it, another problem solved (and optimised) in minutes.

Until next time,

J

UK Tech Days – Day 2 (Windows 7 Phone)

The publishing of this post as postponed by three days because of problems with Jamie’s connection

Today was the second day of Microsoft’s UK Tech Days conference on the Windows 7 Phone format. It took place at the Fulham Broadway Vue and covered the topics involved in developing and deploying software ‘apps’ for the Windows 7 Phones.

The Start screen of Windows Phone 7

Image via Wikipedia

Content

Today’s content was focused on data loading and types. Whereas most of yesterday was based on loading the data into memory and manipulating it, today’s focus was on getting the data to the device in the most efficient way.

A user wont use your app if they notice that their [phone bill’s] data rates go through the roof

That goes hand in hand with the key point of the Windows Phone 7 presentations:

Reducing app installation regret; we don’t want users to install an app, then have regret about using it for any reason. This can be accomplished by having great quality code on these devices alongside quality data loading

The keynote for today was going to be Brandon Watson going through some of the key information in Microsoft’s press release from last night, but his voice wasn’t up to scratch. Instead, he took us through some key ideas and features that Windows Phone 7 devices have in place of the iDevices and the Android phones.

It says a lot about a device when the best selling app is an app killer. Windows Phone 7 has the best garbage collection service out there…

I’ve been told that the Android devices are better because they have dual cores, but a dual core takes more power, and more power means less run time…

The amount of software libraries that we [Microsoft] provide to developers is ridiculous…

Hardware Limitations?

All phones have compasses built into them, but very few of them have pre-built API’s to access it – something that the Windows Phone 7 SDK has. One thing to remember, though, is that some Windows Phone 7 devices don’t have gyro’s in them.

If a gyro isn’t present, then motion detection and the augmented reality API will be buggy

Software for Developers

Along with Visual Studio – current version is 2010, but there is a new version out soon (2011) – there are a plethora of different tools available for Windows Phone 7 developers.

There are the Mango development tools; which will enable developers to get a handle on the new features coming to version 7.1 (or 7.5, or “Mango”) of the OS FOR FREE

There are design tools; for instance Expression Blend, which allows designers and developers alike to quickly program the UX (User eXperience) with the standard code by dragging and dropping items onto a design area.

There’s obviously Silverlight; which looks like it powers the entire device. Also, it’s NOT a replacement for flash (as most people seem to be saying).

The No 1 Thing to take From the Conference?

The importance of design, rule #1: DON’T GET A MULLET

Mullet’s look out of place more than most hair styles, and so do “dodgy” controls and UI items. If they’re not meant to be there, don’t use them.

UK Tech Days – Day 1 (Windows 7 Phone)

Today was the first day of Microsoft’s UK Tech Days conference on the Windows 7 Phone format. It took place at the Fulham Broadway Vue and covered the topics involved in developing and deploying software ‘apps’ for the Windows 7 Phones.

Windows Phone 7 Review

Image by clintonjeff via Flickr

Content

Most of the content was made up of developers who have created some truly amazing apps, discussing their apps and showing off the code.

That’s one of the things about Software Development that doesn’t make sense. With all the NDA’s (Non Disclosure Agreements), patents and copyrights placed on Software, it almost doesn’t make sense that these guys would be showing off their code with such pride. But, that’s just it: they’re proud of the code that they’ve produced.

The keynote speech was provided by Brandon Watson, one of the many geniuses working over at Mircosoft, trying to make the Windows 7 Phone format as good as it can be. He seems like an awesome guy, and he had plenty of time for questions after his keynote.

He even took the time to answer my, probably zanny questions.

Code Examples

Most of the code discussions and examples revolved around data structures and performance – which is pretty cool. I mean, mobile phones only have a finite amount of CPU power and memory.  Some of the information given makes a lot of sense now that I think about it, again. I mean:

  • When a timeout occurs, or the screen locks, the program that is currently running is terminated. The program will restart from where it left off, when the screen is unlocked
  • De-Serialise (or load) data from storage into memory using a background thread, not the UI thread. Doing it that way works out as a better experience for the user, because you can keep animating your progress bar
  • As long as your program has a splash screen and a progress bar (for loading), most users will wait patiently for the program to load
  • Always assume that the network the phone is connected to is quite flimsy, and could cut out at any time. That way, you force yourself to use it sparingly
  • Target audiences always want simplification when it comes to mobile apps. They don’t need to know how the app works, just that it works

Excellent Quotes

Brandon started the whole day off with the best piece of pseudo-code I’ve ever seen. When a manager is asking you to provide some information about return on investment, just show him this:

[sourcecode language=”cpp”]
if (Developers.Happy())
return OnInvestment;
[/sourcecode]

Then there was this amazing gem of code. It’s C#, but will show up as C++:

[sourcecode language=”cpp”]
SomeFunction myFunction = new SomeFunction();
myFunction.SomeMethod += (s, a) => {
//code in here to catch an exception
};
[/sourcecode]

That code block is a short hand form of the standard way to catch a thrown exception. The only problem is, I’me not sure if it’ll only work on a W7P project, or whether it’ll work in a C# listing. Since I’m not at home, I can’t test it out.

That’s all for now, but I’ll make sure to post about what happens tomorrow (including some of the information about a press release that Microsoft are giving out tomorrow)

J

Ten Days!?

That’s right folks, it’s been 10 days since my last post. So I thought, ‘Why not bring the Blog-o-Sphere up to date with what I’m up to?

The answer? Not that much.

The Horizons

I’m travelling down to London on Friday. I’m doing this for two reasons:

  1. To see my awesome friends in Essex (I’m sure that certain networks have just blocked this site because of their crappy network security heuristics)
  2. I’m attending a Software Developer conference hosted by Microsoft, called UK Tech Days 2011

I’m quite excited at the prospect of going to a Software Developer conference, as I’ve never been to one before.

Yes I AM fully aware of how geeky/nerdy that may makes me sound

The truth of the matter is this, I’ve been unsuccessful at getting a job doing ANY kind of software development after graduating (and I’m not in the minority of my graduating class. Class of ’08, if you’re interested) So I’m hoping to make some contacts and put a few “business cards” about.

Also, I’m hoping that I can gain some insider tips and tricks about Windows 7 Phone development (which is what the conference is about), that way I can pass the details on to my friends over at Bottled Games.

You should check them out, by the way. They’re a small groups of Uni of Hull students (most are studying Games Development) who have started a small Indie dev team and have released a few games for the Windows 7 Phone platform already.

I’m also excited at the prospect of visiting my friends Alex and Spooky, down in Essex. It’s always fun when I go to visit them, and they’re really cool people. Apparently, we’re going on a photo shoot on Saturday.

I say “we”, they’re the one’s being photographed, I’m going to be “sandwich bitch”

Also, I’m taking them to Wagamama”s at some point during the week. All in all, it should be a fun week.

Recent News?

The only recent news to report is that my computer chair broke in half, yesterday. The seat portion is still in one piece, as is the swively-wheel type contraption that makes up the bottom half. This has left me with 4 things:

  1. A dented self image
  2. Worry about my weight
  3. No chair to sit on (I’m, currently sat on the floor typing this)
  4. Extreme guilt (it was my brother’s chair, and he was the one sat on it when it finally collapsed)

Also, my brother has been suffering with shooting pains in his arm for the past few months. He’s been to see several specialists, had a tonne of tests done, and has been on very powerful meds for ages. Last week he was diagnosed with having an aggravated nerve in his neck. He was given some exercises to do (every hour or so), and within 2 days he was feeling much better.

I’m hoping that this is the last of it. Poor guy hasn’t been able to sleep properly for months, and has been in pain pretty much constantly. I wouldn’t wish any of that on my worst enemy (of which, I don’t have one)

Ah, well. That’s all folks.

J

Page 1 of 2