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.

 

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.

CCIE Routing and Switching v5 Preparation

Introduction

I recently made a full commitment to study towards the CCIE Routing and Switching v5 written exam. The primary reasons for this are to refresh my certifications but far more importantly, to update and build upon my current skill set. It is key to me that I don’t just pass the exam but deep dive in to each and every subject on the blueprint. If I am successful in both these goals, I will then have a decision to make on whether to go for the lab, but that isn’t on the road map at this stage.

CCIE Routing and Switching v5 Preparation

This post isn’t about the exam itself or even the material in the blueprint. Rather it breaks down what came prior to starting the very first ‘official’ study session as I feel that this will have an important impact on my success and general enjoyment of the learning ahead.

Timing

This is critical. Studying for the CCIE requires such a large commitment in terms of time, effort and in many cases money, you need to be ready to take this challenge on. Diving in without giving serious consideration to the things listed below will likely make your journey a difficult one. Some key areas to think about:

  • Certification level. There are no prerequisites to pass your CCIE. To sit the lab, you need to have passed the written exam and that is it. My advice would be to not take that path however. I would recommend that you do both the CCNA and CCNP level certifications for the particular CCIE path you are hoping to achieve. This will serve several functions. Firstly, the studying required to pass each level will build your foundational knowledge up, making the CCIE content less of a shock to the system. Secondly, sitting those exams will get you used to the way Cisco ask questions and the exam process in general. Thirdly, whether deserved or not, many people will be weary of CCIEs that took the direct route, bypassing NA and NP exams
  • Career. There are two key factors here for me. One is experience and is naturally related to my previous bullet point. A CCIE with only two years networking experience will raise a red flag with some people. Not to say that every engineer with 10+ years under their belt is the best thing since sliced bread, but, in addition to lower level certs, a minimum of five years or so experience says to me that you’re more likely to have seen a good range of tech and worked on more networks. Regardless, this isn’t about job interviews, so on a person by person basis, more experience should mean you are better prepared to do the CCIE than when you were less experienced.The second factor is based on whether your current role will allow you to commit to your CCIE studies. If you’ve stepped in to a completely non-technical management role, or it involves a lot of travelling, or you are doing a six month contract pulling 60+ hour weeks, it might not be the best time to start this journey. That’s just me, you might relish the extra challenge, but I think success will be much more likely if you have the time in your week to put the extra studying time in, without burning out. Working in a relevant technical hands on role will help supplement your training. A role that you also enjoy will be far more likely to motivate you to study than a role that does not inspire you in any way
  • Personal life. This is the one I hear takes a lot of people by surprise. You might be lucky in that you can do all the studying you want at work or you might have so much spare time that fitting in 10-20 hours of study a week only impacts your TV watching schedule but most people will have to make some serious compromises. You will certainly need to consider cutting right back on your social life, even giving up going out at all for a period of time. There will also be a toll on those close to you so make sure you have the full support of your family and friends. Especially with family, make sure you explain to them just what lies ahead so that they can adjust too.
    From a health point of view, you probably don’t want to start a CCIE track if you are recovering from a serious illness, or if you have a medical operation due in what would be your study period. You most likely don’t need that kind of extra stress in your life.
  • The same goes for your finances. Make sure you are at a reasonable level of financial stability before you begin the commitment. This will be a relative decision for each of you, but I personally wouldn’t want to have working overtime to pay off debts in the back of my mind, or thinking about where I was going to get all the money to pay for the exams and training materials. Which brings me to my next point

Materials

You need to ensure that you have all the relevant training materials to hand, maybe not at the outset but certainly as you get to the section of your training that requires them! What those materials are will depend on a number of factors including your preferred learning style, budget and current knowledge.  Some people love text books, workbooks, videos, labs, online resources, classroom training or any combination of these.

Whilst it is important to have the right materials, I would be cautious of having too many. You need to review the blueprint for both the written and the lab and work out what materials will give you the best chance of understanding the topics on each and passing the relevant part as comfortably as possible. Reading five multicast books may give you an unprecedented understanding of the subject or it may waste valuable time when you largely read the same topics written in different styles, where one really good book on the topic might suffice.

Read what other people are saying about their materials and if you can, actually speak to people who have gone through this before you.

Plan

Some people like to set a date in their head from the outset e.g. “I will pass the written in three months and sit the lab 12 months later”. For me, I am happy to be a little more relaxed. Remember from my opening comments that I am initially only studying for the written at this time and the primary reason is to renew my knowledge, so I have no specific deadlines. Having said that, I still have a rough plan outlined for getting through each of the six modules, have all the official materials which I will be supplementing with online resources as I tackle them and have set expectations with my family. I am aiming to do between 10 and 15 hours a week.

Summary

I’ve spent a long time thinking about the CCIE. When I first passed my CCNA, it was at the forefront of my mind and remained so for quite some time afterwards. Having moved about in my career since then and gained a wealth of experience in different technologies, I think I’ve done the right thing waiting until now. All the things listed above have come together at the right time. I will review whether I will take a shot at the lab at a later date.

I would love to hear from readers who are either thinking about doing their CCIE, are currently on the path or have already achieved their digits. Leave your comments below, hit me up on Twitter, or send me an email.

Till the next time.

Thetechinterview.com – a new IT career site

Introduction

A new site has recently been set up, the goal of which is to provide career advice and resources to techies. In their own words:

The Tech Interview is a site dedicated to the career aspects of technology.

The list below is a small sampling of the types of articles and resources that will be made available over time.

  • Getting A Job Interview
  • Resume and Interview Skills
  • Landing A First Job in Technology
  • Turning A Job into a Career
  • Staying on an Onward and Upward Track
  • Technology and Education
  • Technical Certifications

The two guys who have set this site up are John Harrington (@networksherpa) and Paul Stewart (@packetu). You have probably already heard of them; they’ve been around the block many times and are most certainly carbon neutral with regards to how much they put back in the community against what they take out.

Show them your support by heading over to The Tech Interview and help it grow in to what will hopefully become a massively valuable resource.

Till the next time.