Friday, 27 November 2015

The Why of the Kilobyte (and data sizes generally)

I am a Computer Science graduate and a developer of ten years. Embarrassingly, it took me until last night to jump down the rabbit hole of the terminology used when describing quantities of data. As usual, I didn't find exactly what I was looking for on the internet, so here are my thoughts:

I like to think I understand binary, in a rudimentary fashion at least. I can explain that it's a base-2 number system, having two symbols to represent its numbers: "0" and "1". I can show you how to count in a base-2 system and show you why it works that way. I can contrast it with a base-4, base-10 or a base-16 system and show how those works. I can perform basic binary addition. Essentially, I'm trying to establish my credentials as someone who isn't a complete binary dullard.

I also understand that one bit (Binary digIT) isn't an awful lot of use on its own. It can be on/off, high/low, true/false - however you choose to describe it - but only in context and combination with other bits does it become interesting and useful. And this is where my journey down the rabbit hole began...

Let me start with good old, recognisable base-10. It has ten symbols to use when representing numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. We - people - have chosen to assign special names to particular, neat representations of quantity in this system:

1 = one = 10^0
10 = ten = 10^1
100 = hundred = 10^2
1000 = thousand = 10^3
1000000 = million = 10^6
1000000000 = billion = 10^9 (old British billion: 1,000,000,000,000 = 10^12)

I haven't worked out quite why we decided those particular representations were worthy of their own name; it feels like an addition chain, especially if you go with the old British billion: 0, 1, 2, 3, 6, 9|12.

With this in mind we approach base-2, where the ground appears to completely shift. We start by giving names to collections of bits, seemingly more interested in the range of numbers a collection of bits can represent than the numbers themselves. So..

0 = bit = 0 to 1
0000 = nibble | nyble = 0 to 15
0000 0000 = byte = 0 to 255

You think "okay, well it's a different world, things area different here... maybe a different pattern is used". Once you get your head round it's collections of bits (ranges of numbers) are given names, rather than numbers themselves, then maybe you can work out the pattern. Maybe 16 bits or 32 bits have a special name? Nope. It's all madness from here on in!

0000 0000 0000 0000 = 2 bytes | 16 bits
0000 0000 0000 0000 0000 0000 0000 0000 = 4 bytes | 32 bits

What appears to have happened is that someone decided bits are no longer interesting and that... wait for it... quantities of bytes are interesting (completely eschewing the lowly bit) and decide either 1000 or 1024 (depending on your stance) is an interesting quantity of these byte things to be concerned about. I can only imagine being interested in ~1000 of these thing is the spectre of base-10 hovering over the decision making.

1024 x byte = kilobyte
1024 x kilobyte = megabyte
1024 x megabyte - gigabyte
etc.

If someone can explain the why behind this thinking I'll be greatly appreciative. I can only imagine that "kilo" and "mega" are impositions from the world of base-10 and that multiples of bytes is interesting because 8 bits can represent a character (as per ASCII or some machine instruction).






Thursday, 5 November 2015

Nomenclature

I agonise over naming things when it comes to coding; names convey intention and purpose and are one of the first things you rub up against when trying to figure a out new concept or someone else's code - or your own from longer than a few days ago.

It's in this spirit I want to rename Closures as Captors (or Captures). When you read into it and discover that the term "closure" is used in reference to "closing over variables", I submit you immediately think "what?" and then "I wonder if them mean capture a variable?".

Thoughts?

http://www.blackwasp.co.uk/CSharpClosures.aspx

Thursday, 1 October 2015

IT Recruitment Agencies

I'm unlikely to say anything original in this post. I'm trying to work out what exactly my opinion of recruitment agencies is and whether not they can be bent so as to be useful.

N.B. I'm a permanent, full-time employee. I always have been. My experiences of recruitment agencies have always been in that context; I've never dealt with recruitment agencies from a contractor's point of view.

The sheer volume of IT recruitment agencies in Brighton (and surrounding areas) is staggering yet completely understandable: they want a piece of the relatively well paid developer's pie. A recruitment agency introduces you to a prospective employer and typically, providing you pass probation, gets a lump sum (~20% of your first year's salary) for doing so.

Traditional free market principles do not seem to apply to IT recruitment agencies, that is, myriad agencies do not appear to have created a survival of the fittest situation in which only the leanest, highly-skilled, astute agencies / agents survive. Rather, there's a roiling mass of incompetence and greed from which no front-runners emerge, presumably because there are non to do so.

I imagine a recruitment agent's job must not feel too dissimilar to that of a 419 scammers: sending innumerable emails off to potential victims (LinkedIn members who wonder was there ever a time giving LinkedIn all your personal work history felt like a good idea...) hoping for that one hit in a thousand to make them rich.

It feels like mine and my potential agent's interests are fundamentally misaligned: I want the right job; the agent wants me to take any job, preferably one I can only stick out for a year before returning to them to try again.

This has merely turned into a rant. What are the benefits or a recruitment agent for a full-time, permanent employee? There must be some...



Friday, 18 September 2015

Creating a SQL Server Managment Studio Add-in

I've spent the last day or so playing with an idea for a SSMS add-in. It's something I've been thinking about for a while now but will save the details for another post. What I want to document are my experiences so far as well as how convoluted and poorly-resourced the process of producing an add-in to SSMS is. Here are some of the things you should know about before strating on the journey. Hopefully some of this will save you some pain.

General Points:
  • As far as I can tell, Microsoft don't really want you to integrate into SSMS - at least they've no interest in supporting the endeavour.
  • Luckily, due SSMS's similarity to Visual Studio, you can broadly follow the same instructions offered up for extending Visual Studio with add-ins, something MS seem to actively encourage.
  • There appear to be two ways of skinning this cat: Add-ins and VSExtensions. Add-ins, the route I've taken, are the older of the techniques but are where the majority of the resources are.

SSMS Integration:
  • In order to load add-ins SSMS looks in folder locations specified here: HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\11.0_Config\AutomationOptions\LookInFolders for XML files giving details of the add-ins.
  • You can configure things to happen only the first time the add-in is loaded by SSMS or every time the add-in is loaded: ext_ConnectMode.ext_cm_UISetup & ext_ConnectMode.ext_cm_Startup. I've still haven't quite grasped fully how they work.

Menu Generation:
  • A CommandBar can contain a CommandBarPopup which needs to contain a CommandBar which is where you place CommandBarButton objects produced by Command objects.
  • A Command can exist entirely independently of anything else. They don't have to be attached to CommandBarButton objects.
  • A Command hangs around. It doesn't disappear after you close SSMS. To have it do so you need to remove it in the OnDisconnection of the IDTExtensibility2 interface.

Resources:

Thursday, 10 September 2015

Uri.TryCreate C# (Part 2)

It occurred to the other other day that the .NET core is now open-source so I can actually go see the code involved in the Uri.TryCreate method.

It transpires that Uri is a partial class and the meat of the functionality is split over the two following files:

https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/UriExt.cs

https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/Uri.cs

The first thing that stuck me was there's an awful lot of code involved with attempting to create a Uri.

The TryCreate static methods which lives in the UriExt.cs class are deceptively simple. The TryCreate overload I'm interested in is the most simple of those - it really just passes the work off to a CreateHelper method which in turn passes off the work to a ParseScheme method located in the Uri.cs class.

ParseScheme appears to do some basic length checking before deferring to ParseSchemeCheckImplicitFile, which is where the main body of work seems to take place. As far as I can glean the following rules are being observed:
  1. Whitespaces at the start are ignored
  2. A url is valid if it is at least 2 characters, as long as the first of which is not a number, followed by a colon - unless those letters are a scheme you'd recognise (ftp, http, https, etc) at which intuitive validation kicks in.
  3. UNC paths are valid e.g. //foo

Given these rules, the following odd strings pass as valid absolute URIs:

"aa:"
"fo:o"
"        fo:o"
"javascript:void()"

Maybe there are just so many esoteric schemes out there that robust validation is not viable.



Wednesday, 9 September 2015

Licences & Additional Build Agents in TeamCity

We use a combination of TeamCity and Octopus Deploy to automate our deployment and release process at work. We’ve been using the Professional Server Licence (free version) of TeamCity which allows for 20 build configurations (each configuration delineates one logical group of actions. e.g. pull code; build it; run unit tests) and 3 build agents (in our case Windows services which execute build configurations).

We recently bumped up against the 20 configuration limit and the boss dusted off the credit card to purchase a Build Agent Licence (£236 for 10 additional build steps and one additional build agent, at the time of writing). I dutifully entered in the licence key and fairly quickly learned a few things:

  1. What you purchase are build agent slots not build agents.
  2. You need to install build agents into your available build agent slots
  3. The person who set-up our TeamCity build server originally had only installed on build agent (probably due to #4)
  4. Precautions need to be taken when switching from a single build agent to multiple agents

Prior to purchasing the upgrade licence we had only one build agent installed (I assumed that was our limit on the free license) and I expected, rather naively as it turns out, to see another build agent appear when I entered the licence key. What you need to do, in fact, is install additional build agents into your free build agents slots. This is made a little more complicated by the fact you can’t just straightforwardly use the build agent installer (on Windows at least) to install more build agents; each build agent needs some tweaks to be made to its installation configuration files halfway through the installation. It feel like TeamCity have missed a trick here and could make customers’ lives easier by bundling up these config changes as part of the installer.

Excellent article detailing the process here: http://www.diaryofaninja.com/blog/2011/07/26/teamcity--when-1-build-agent-isnrsquot-enough

Tuesday, 25 August 2015

Clean Code

I'm re-reading Clean Code by Robert C. Martin and a few quotes from the intro have really stuck out:

"Quality is the result of a million selfless acts of care - not just of any great method that descends from the heavens".

I like this quote a lot. I'd take the word "selfless" out of it though. When I'm writing code I'm often thinking about Future Me and trying to make his life as easy as possible. Every act of care, or short-cut not taken, makes Future Me's life that bit easier. I want Future Me to not curse Past Me.

The idiom "a bad penny always turns up" is cited too. This one rings true. The amount of times a short-cut taken in a fatigued moment has come back to bite me is unnerving!