Writing good code 101

Introduction

A workmate of mine has recently been dusting off his coding skills and using PowerShell to access REST APIs to pull data and graph it in a dashboard. After falling down the never ending rabbit hole for a while, he tweeted the following question:


It’s not really a question that is best answered in a series of separate 140 character responses so I thought I’d write a brief post to try and distil my understanding of what good code is. A full time developer could probably tear this apart and flesh it out with all sorts of deep and meaningful computer science principles but I’m going to take the perspective of a coding hobbyist, with my target audience being the very same, looking for a quick answer.

Pictures are nice

Let’s keep this as simple as possible. Code can be functional and code can be readable. You want your code to be both at the same time. Let’s discuss those requirements a bit more.

Functional

Code that is functional, by my definition, is code that does what it is supposed to do and does it well. Bear in mind that I am talking about code that works well here. I am not talking about functional programming, which is a separate paradigm (you can melt your mind here). Some KPIs to bear in mind:

  • Works predictably. Expected results occur every time
  • As bug free as possible. Good run time error checking and code testing
  • Good validation of all user input. Don’t let humans screw up your hard work
  • Allows additional functionality to be added with relative ease. You don’t want to have to start from scratch every time

Readable

Code that is readable, by my definition, is code that another person who has a basic or even better, no understanding of your language of choice can browse through it and understand what the code does. It also means you can go back to your code in 6 months time and not ask ‘what the hell was I thinking?’. Some KPIs to bear in mind here:

  • Follows the language guidelines e.g. in Python, adheres fairly closely to PEP8, code is ‘Pythonic’
  • Is well documented. Good code is self-documenting i.e. the intention is clear in the code itself. Next best thing is well commented code
  • Not over documented. By this I mean focus on the guidelines and making your code clean. You shouldn’t need a comment for every single line of code. Try to make the intention speak for itself as much as possible
  • Does not have duplicate code. This can make understanding code more difficult as well as being generally inefficient. Learn about functions and classes to help with this

Bringing it all together

To write code that puts you on the right path to Venn diagram overlapage (pronounced o-ver-la-par-jay), you do need to put some effort in though. The key steps are:

  1. Learn some basic computer science skills. Not talking about getting a degree, but if you know some basic algorithms and understand what people are talking about when they reference loops, conditional branching, OOP, etc. you’ll be in a better place to answer the question ‘how can I write code to solve this problem?’
  2. Learn how the language of your choice implements those different features. Read the online documentation, buy a book, write some code!
  3. Collaborate. I’m a bit weak in this area myself as the coding I do is pretty much all specific to my workplace and besides, I have justified imposter syndrome. Work on other people’s code and ask for help on yours. This is a great way to gain experience and also improve productivity
  4. Set out to maintain functionality and readability before you write a single line of code. It’s better to incorporate both these requirements as you go, rather than trying to retrofit them later

Summary

In this post, I took a high level look at what makes good code. In answer to Craig’s initial question on Twitter, I would say code that isn’t functional and readable is not great code and could always be improved. Make functionality and readability requirements of all the code you write.

This post is aimed predominantly at beginners and hobbyist coders. Got any other advice? Post in the comments.

Till the next time.

 

Getting started with coding – Part 7 – Next Steps

Introduction

In part 6, we looked at a number of training options to help take your knowledge and skills to another level.

In this final part of my Getting Started With Coding series, we will review what we’ve covered so far and then try to answer the question that will, at some point, inevitably crop up. “What do I do next?”. Continue reading “Getting started with coding – Part 7 – Next Steps”

Getting started with coding – Part 5 – Version control

Introduction

In part 4, we discussed some additional tools to help your coding. In part 5, we look at version control, which is a way of tracking changes you make to your code (or in a wider sense, documents, information, etc.). As it is such an important topic, I think it warranted its own post, even though technically it is just another tool in your kit. Continue reading “Getting started with coding – Part 5 – Version control”

Getting started with coding – Part 3 – Editors

Introduction

So you want to start following examples you’ve found online or in a book to learn more about your chosen language from part 2. Which editors should you consider to start knocking up some super useful scripts? Part 3 looks at three broad categories, giving some suggestions along the way. Continue reading “Getting started with coding – Part 3 – Editors”

Getting started with coding – Part 2 – Languages

Introduction

In part 1 of this series, we addressed the key concerns people starting to code might have and also set out some key reasons why you should give it a go in spite of those, often unfounded, concerns. In part 2, we cover off how to go about picking one of the languages to learn to code in from the numerous choices. Continue reading “Getting started with coding – Part 2 – Languages”

Getting started with coding – Part 1 – Introduction

Introduction

If you work with computers in any aspect of your life, being able to code can be a very powerful tool. All too often however, I hear people say things like “it’s too difficult” or “I’m not a developer” and they never take more than their first few steps. This post, the first in a series on getting started with coding, addresses both the fears of taking your first steps and the benefits of starting that journey. The remaining posts then give you all the help you need to overcome those perceived obstacles and have some fun along the way. Continue reading “Getting started with coding – Part 1 – Introduction”

Taking the Python Challenge

Introduction

A few months back, I came across a cracking website called Python Challenge, which poses a number of increasingly difficult challenges.

Crazy and fun at the same time

This isn’t a site for complete beginners. It assumes you already know the basics of things like loops, branching logic, various data types, etc. It also assumes you have a specially wired brain so don’t be surprised if you run in to a few brick walls where you will probably have to cheat a little i.e. find a solution on line.

However, the best thing about this site is that each of the 33 challenges (current as of 28/10/16) covers a different skill set and gets you using different Python modules in creative ways e.g.

  • re for regular expressions
  • pickle for (de)serialising Python objects
  • zipfile for working, unsurprisingly, with zip files

I found this approach really useful in forcing me to learn new tools to solve a problem, probably one of the best ways to get familiar with tools that you may need from time to time but don’t want to just plough through some documentation when you need it.

Summary

At some point in your path to learning to code, you’ll probably find yourself stumped as to what to do next. You’ve learnt the basics, you’ve applied them to some problems you’ve had but you aren’t sure how to widen your horizons.

Try out Python Challenge and see how many challenges you can get through before your head explodes.

Till the next time.

Ubuntu on the desktop

Introduction

I’ve tried a couple of times in the last five years or so to make the move to Linux on the desktop. Namely Ubuntu on my work’s laptop. Doing it on my own kit is easy, but as we’ll see, doing it on a corporate machine presents difficulties.

First question, why?

First of all, I like learning new things and having come from a Microsoft and networking background, the beardy ways of Linux were my weak spot. I wanted to force myself to use it in a way that running it in a VM wouldn’t let me.

Secondly, I wanted to see if the Linux desktop experience has matured to the point where migrating is viable.

Thirdly, I wanted to see if I could remove my working dependency on the Microsoft ecosystem, namely the extended Office suite.

Starter for 10

I’ve installed Linux of different flavours many times but regardless, installing Linux really is a piece of cake. The hardware was a Dell Latitude 5570, with 16GB of RAM and a 256GB SSD.

I ran in to some initial hardware compatibility issues with my Dell docking station, which would cause my X-server session to completely reset each time I undocked, causing the laptop to shut all apps and loss of work. A quick look in /var/log/syslog showed the culprit service and a bit of Googling gave me some config to put in a file to resolve the issue.

I installed VMware Workstation 12 Pro so I could install my Windows 10 VM and whilst I found it to be performant most of the time, I did have strange issues with system sounds playing like a wasp farting in a tin can. All other sounds from both the VM and host played OK.

Playing about

The Unity desktop had a few quirks that annoyed me, namely the system tray at the top right appearing on all monitors so it would suddenly appear on top when I was clicking on menu bars in my Windows VM.

I installed a number of other desktop environments e.g. Gnome, KDE, XFCE but the latter in particular caused some strange behaviour and I ended up spending a good couple of hours removing all traces and reverting back to Unity.

I tend to use Python on server editions of Linux or my Windows machine but having it on a Linux desktop added that extra level of simplicity and ease of access.

Smashing Windows

I use Microsoft Office a lot. Outlook is not only my mail client but my main time management tool. I’ve not found a Linux client that comes even close, but Outlook Web Access gave me most of the functionality I was after. The same thing applies to OneNote, another tool I use extensively but can be accessed via OneDrive online.

Word and Excel proved more difficult, especially when people like creating fancy macros that aren’t compatible with OpenOffice or LibreOffice.

The biggest sticking point however is Lync, or Skype For Business as it’s now known. The sound quality was questionable but the worst point for me was that the mic would just stop working at random intervals. Reconnecting the USB headset would get it working again, only to disconnect within the next couple of minutes.

I got the Empathy IM client up and running with my work’s SFB server, but it wouldn’t show contacts and voice/video wouldn’t work. In short, a show stopper.

Summary

Ubuntu has come a long way since the last time I tried this experiment. My home laptop has Kali installed and will continue to do so, but due to the dependencies on Windows and drop in productivity, I could only put up with it for two weeks before reinstalling Windows again.

At the end of the day though, I can’t completely ditch Windows simply because of how entrenched it is in my organisation.

In terms of my goals for the experiment, I certainly used Linux a lot more, especially on the CLI, so am confident I’ll be using my Ubuntu server VM more than perhaps I have done in the past.

Till the next time.

The cost of self improvement

Introduction

In my earlier career, I measured my knowledge by how many exams I had passed and how much frowning I did throughout the day. I’ve lost the exam bug over recent years, mostly because the 700 page study tomes contain perhaps 100 pages relevant to either my role at the time or my future goals and with the pace of IT these days, I honestly have better things to be doing with my time.

That’s why I try to focus my learning goals myself, rather than be told by somebody who doesn’t know me is what I should be learning.

The Training Trap

The cycle of continuous training contains many pitfalls. First of all is the cost. Training courses, books, ,other materials, exams. The whole refresh cycle means that once you are committed to remaining certified, you are on a one way journey to Emptywalletville. Unless you are lucky enough to have a sponsor that will pay your way.

The vendors love telling us how marketable these certifications make us too and we seem to eat it up by the bucketful. What annoys me the most is how these vendors lock businesses and individuals in to the training trap by insisting you need so many MCSx/CCNx/etc. people to maintain certain partner level accreditations. Just another set of hoops to jump through, another maze to remain locked within.

Same shit, different day

Every time I go to the supermarket or newsagents, I always have a browse of the magazines. Over the years, I’ve even subscribed to several of these covering Film, IT, photography and gaming, but none have lasted more than a couple of years.

With the ever expanding catalogue of available publications, it is easier than ever to see that a large percentage of these publications are simply regurgitating the same material in a cyclone of confusion and trickery.

The worst offenders seem to be the IT and Health sector magazines. The same top 10 lists, learn how to do this or that, absolute beginner’s guide to blah, blah, blah. Even within the same month, on display you can see magazines that have similar content to attract your hard earned money.

Another sector that is guilty as sin for this is the self-help book brigade with the same information commonly being thrown at us time and time again. Sadly, the target audience for these are often the most susceptible to the need to buy.

Suckers for or victims of punishment

One thing that is for sure, these publishers would not remain in business for long if they didn’t have a steady revenue stream. The way out is easy enough in this scenario and is covered below.

The more difficult scenario to disentangle oneself from is the vendor partnership scheme. For these, you need to ensure that the benefits you receive from participating outweigh the associated effort and cost, but you often have little leeway in this regard.

I’ve yet to find a magazine in the supermarket that contains information that is not easily and freely available on the Internet, within minutes from anywhere in the world where I can connect, or to download for later offline reading. The fact that I can dive deeper in to those articles by ‘going down the rabbit hole’ at no extra cost and end up with a much fuller understanding is another free benefit. Despite the electrical usage, I’m also a little greener by saving the trees.

For those people who argue ‘I like to feel the paper in my fingers’, my advice would be to count the bundles of cash you will save instead.

Summary

The wider field of self improvement, no matter which topic we are talking about has created a business sector which is growing year on year, with no signs of slowing down. For some reason, we buy in to their marketing as if we’ve briefly forgotten what a connected world we live in, just for those moments between the shelf and the checkout.

From a certification point of view, I’ll mostly only be recertifying and proving my knowledge via other means.

I like to think I’ve seen the light. At the very least, I’ve got a few more pennies in my pocket and a lot more time to enjoy the more meaningful things in life.

Till the next time.

The difference between inspiration and motivation

Introduction

I’ve heard people use these words in the wrong context before and it got me to wondering, are people looking in the wrong place to get things done? This brief post covers the difference between motivation and inspiration.

Inspiration

Inspiration happens from the outside in. That is, an external force triggers a reaction in you that causes you to behave in some way. Inspiration infers a positive force causing a positive reaction, at least for sane people with a love of life.

The reaction might be a smile, or pleasant thoughts or it could be something more active like going to the gym, doing some DIY and getting down to some studying. It could also be something more selfless, such as making a charity donation. Regardless, without the external force, the inspiration simply doesn’t happen.

Motivation

Therein lies the rub for me. Why wait for something external to have an impact before I decide to get something done? Motivation happens from the inside out. That is, an internal force triggers a reaction in you that causes you to behave in some way. You aren’t relying on external forces, just yourself. Shia Labeouf would love this post, I’m sure.

Let’s face it. Motivation is effectively self-inspiration. You need to inspire yourself to get something done and quite often for that, you will need a strong will and a very good imagination. But what you won’t need is to wait for any external stimuli.

Summary

Essentially, in this post I called people who rely on being inspired to get things done lazy and unimaginative. Own the trigger and just do it.

Till the next time.

Respect your future self

Introduction

Day in, day out, life is full of decisions from the mediocre, ‘which socks should I wear today?’, to the more life changing, ‘do I accept the job offer?’. Many of these decisions are made almost automatically whilst others, we pore over for what can seem like an eternity.

Having given this process some deep thought recently, I came to the conclusion that most people use a complicated set of factors and brain algorithms to arrive at the final decision, but that for the most part that decision is what is deemed best at that moment in time. People might use historical data to help drive the overall decision but we are very much in the moment when we make our choices. You only have to look at how late most people start seriously saving for retirement to see what I mean.

Meet your future self

For the smaller decisions, that probably isn’t a big issue but if you sit and think about what your top five life priorities are, set goals for each of those and think how each decision you make helps you get closer to achieving those goals, even if it hurts a little in the short term, I believe you’ll make better long term decisions, especially the important ones.

For example, your top priorities might be health, family, career, travelling, music. To make it less abstract (some people struggle to see in to next week, let alone 10 years away), try to imagine yourself having a conversation with your future self. How would you justify your decision? How do you think your future self would react? If you see them shaking their head in disbelief or disappointment, you might want to rethink before you proceed. If your future self feeds back that you have looked after their goals well, then you are on the right track.

Don’t cave in to the temptations of the present with the ‘I can sort this all out at later time’ attitude.

Summary

Just to clarify, I’m not condoning being a boring fart that has no fun. I’m only talking about the important decisions that affect your top life priorities. Map those out now and consider how you will look back on these big decisions in the future before you dive in head first.

When you get older, you’ll be talking to yourself all the time anyway so why not get some practice in now?

Till the next time.

End of year review 2015

Introduction

What a crazy and busy 12 months. I’ve just noticed that five months have gone by since my last blog post and I honestly can’t think of when I had a spare slot to write a blog post in that period. The goals I set myself at the beginning of the year have been tweaked, dropped and completely changed along the way. With that in mind, I thought I’d review what I actually got up to.

So what got done?

I’ve been managing the network team at my current company for a couple of years now but I was keen to try and get back to my hands on roots this year to prevent those skills from evaporating.

The opening of our brand new data centre in Aberdeen gave me the perfect opportunity to do just that, running with the project from the design and planning phases, through procurement, implementation, testing and finally live operations as of October. Introducing new technology in to our portfolio and the importance of the project made this a very rewarding experience.

I’ve also dived in to a number of long lasting customer projects in the last 12 months, most notably taking the lead on a migration from another data centre in to our new one. The best two things about this project were brushing up and learning some new skills and collaborating with the customer team. I really enjoy having discussions with customers about how they can get the best out of technology.

Summary

With 2015 drawing to a close, I could look back at the goals I set at the start of the year and feel a sense of disappointment. After all, most of them were not achieved. However, I think being flexible in what you hope to achieve and finding yourself at the end of the year largely happy with what you did achieve is what the overall goal should be for anybody.

For 2016, I really want to carry on with my sleeves rolled up, working with great technology and people. I also want to try and be a bit more frequent with my blog posts!

Have a great festive period everybody and hope to see you all next year.

Till the next time.

The human OSI stack

Introduction

Earlier this year, I attended a growing InfoSec event hosted at Abertay University in Dundee, Scotland called Securi-Tay. One of the talks was about carving a career out in InfoSec, presented by the talented Javvad Malik during which he showed the well known OSI model as mapped to humans.

I’d had something like this in mind for a while so, with Javvad’s kind permission to partly rip off his concept and his subliminal motivation, here is my take on how to make sure your human OSI stack is compliant with any current or potential employer’s.

Human OSI stack

  1. Physical. As shallow as it may seem, first impressions do indeed last. How you dress, your personal hygiene, your haircut, what type of glasses you may wear, the colour of your nails, whether you make eye contact or look at the floor. All these things, rightly or wrongly, form an impression. Try and be as smart and professional as you can be, whilst maintaining a certain degree of individuality. As with all layers of the OSI model, you can get a good idea of how best to be ‘compliant’ by looking at other successful people
  2. Data-link. Beyond first impressions, the way you actually communicate is going to make or break you. The importance of knowing how to talk to people at all levels cannot be overstated. Don’t think that emails, IM or social media are exempt from this rule. It covers all form of communications. You can spend a long time carefully building a professional persona and bring it crashing down in a single exchange. As one of my colleagues at a previous company used to say, ‘you are always just one click away from being fired’.
  3. Network. OK, so you’ve managed to get this far but you are only known for your abilities within your own team or maybe your company. It is more important today than ever that you get out and about and make a name for yourself. You need to extend your network of people beyond the walls of the building you work in. At worst, people will hear about the good things you are achieving, at best you will have a large pool of resources you can rely on for the rest of your career. Get to know key people in other businesses, especially your customers, competitors and vendors.
  4. Transport. Driving a nice car might draw more attention than taking the bus but I want to discuss the transport of work through your part of the business. Have you ever even considered the concept of work in progress, even just in your team but more generally through your business? Do you sit and complain about how there is never enough time in the day or do you look for the pinch points and what can be done to remove them? Defining what the manual process is will always be the first step. Write it down, step by step. Then look at how that process can be improved and made more efficient. Then start automating the different steps, with the aim being a completely automated workflow. Now you have more free time to work on other tasks and keeping the work in progress down to a streamlined minimum. Time well spent.
  5. Session. Not sure about the rest of the world, but in the UK, going on a session means having a few drinks. For the purpose of this bullet point, I’m talking about taking regular time outs. Don’t burn yourself out with work all the time. Find the things in life that make you relax, sit back and smell the roses/coffee/whatever. It might be having a social drink with friends and family. Or taking your kids geocaching. Or hitting the gym. The important point is…don’t lose sight of this. It is critical to achieving a work/life balance and you’ll not regret the long hours and hard work you put in.
  6. Presentation. Not so much about your own presentation, covered in the Physical layer but more about your presentation skills. Whether standing up in front of a group of people or publishing a book or a blog, you should be able to adjust your message based on audience to get it across in an entertaining and professional manner
  7. Application. How you apply yourself to your role is critical. Are you a 9-5 type person who comes in, works through their ‘in tray’ and signs out again? Or do you rip up the role and responsibilities sheet and look for new and different ways to offer value to your employer? The latter approach will almost certainly accelerate your career but at the very least expand your knowledge

Summary

This was a slightly tongue in cheek look at how to use the OSI model to help guide you in your career but the truth is that using a simple set of guidelines like this should prove more useful than just winging it or worse still, being a passenger.

Till the next time.