There are two types of collections: generic and non-generic. A non-generic collection is one which can contain any data type, whereas the generic collection must state the type as a parameter. Generics can be considered safer to use as you have greater control of the data involved. Microsoft themselves recommend the following:

“Be sure to choose your collection class carefully. Using the wrong type can restrict your use of the collection. In general, avoid using the types in the System.Collections namespace unless you are specifically targeting .NET Framework version 1.1. The generic and concurrent versions of the collections are to be preferred because of their greater type safety and other improvements.”

Here is a brief explanation of some of the more commonly used Generic Collections. This is not an extensive list.

 

List<T> 

Generic lists are ideal for storing and retrieving large number of elements. You must specify the data type <T>. As you add entries the size of the list will expand – it is not fixed. 

The data can have nulls and duplicates and supports indexing. Lists are not guaranteed to be in order, so the Sort() method may be necessary.

Dictionary<TKey, TValue> 

A collection of key-value pairs where the data type of each is specified. The key is used to identify and order each pair. It acts as primary key so it must be unique and cannot be null.  The values can be null or duplicates.

 

SortedList<T> 

A SortedList is quite similar to  a Dictionary, although the SortedList uses less memory. 

It is a collection of key-value pairs that are sorted by the key in ascending order. When a new value is inserted, it is automatically placed in the correct order and the indexing adjusts accordingly. The key must be unique and cannot be null; the value can be null or duplicate. You can also have a non-generic SortedList which can take any data type.

 

Stack<T>  

Similarly, a Stack may be generic or non-generic. Stack<T> can be described as a last-in-first-out (LIFO) non-generic collection of objects that are of the same specified type. Use a Stack if you wish to access data in a reverse order.

stack

Queue<T>

A first-in-first-out (FIFO) non-generic collection of objects.  A Queue can be used to access data in the same order as it is entered in. Both Stacks and Queues are useful when you need temporary storage for information; that is, when you might want to discard an element after retrieving its value.

queue

Each collection type has its own strengths and weaknesses, but which to use? It really comes down to what the situation calls for:

  • If you need to access the elements in a certain order, you should choose to use a Queue<T> for FIFO or a Stack<T> for LIFO.
  • A Dictionary<TKey, TValue> or List<T> would be suitable if you needed to access each element by an index.
  • If you need to sort the elements differently from how they were entered, you could you a SortedList<T>. A List<T> also has a Sort() method which could also have the desired effect.

 

Be aware that there are many other types of Generic Collections which may better suit your needs:

  • LinkedList<T>
  • Collection<T>
  • KeyedCollection< TKey,TValue >
  • SortedDictionary<TKey,TValue>

We all make mistakes – it happens. Luckily for most of us, these mistakes may only result in a minor inconvenience. From getting your “There, Their, They’re” mixed up, to forgetting to include punctuation; typos are a fact of life.  In programming a typo can happen as easily as a slip of the finger. Such slips are easily caught thanks to an IDE such as Microsoft Visual Studio.  Even if something slips through, what’s the worst that can happen…

A lot can happen, actually! Spare a thought for the programmers who made the following simple, yet incredibly costly mistakes.

 

Aliens: Colonial Marine

aliens

In 2013, the video game Aliens: Colonial Marine was released to widespread ridicule. Despite high hopes, the game was found to be practically unplayable with noticeably glitchy AI.

In October of 2017, a possible reason for the glitches was discovered – a single misspelt word. A typo was found in the game’s configuration file. A word should have spelt “AttachPawnToTether” but had instead been spelt “AttachPawnToTeather”. This caused the enemy Aliens to have no understanding of where they were in the game. They would randomly appear or not react to the player at all.  Despite strong initial sales, the game ultimately flopped. Poor reviews and online scores saw to this. But for a single letter change, Aliens: Colonial Marine may have had a completely different fate.

 

Mariner 1

mariner1

Launched in 1962, Mariner 1’s mission was to survey the planet Venus. At a cost of approximately £380 million in today’s money, its downfall was partially caused by one of the most expensive typographical errors in history.  Shortly after take-off, Mariner 1 went sharply off course. Alarmed by its trajectory, NASA decided to hit the self-destruct button. Reports at the time stated that a misplaced hyphen caused an error in the guidance system.

While the “most expensive hyphen in history” has been widely reported as the reason behind the failure, NASA have since announced that this was just one of many bugs. Nonetheless, Mariner 1’s 5-minute flight was a serious blow to NASA’s reputation during the Space Race.

 

Ariadne 5

ariadne

In June 1996, it was the turn of the European Space Agency (ESA) to rue software errors. The ESA were planning on launching a group of spacecrafts called Cluster, using the brand-new Ariadne 5 rocket. On its maiden flight, a catastrophic system failure lead to the self-destruction of the rocket and its payload.

Ariadne 5 had been designed to use much of the Ariadne 4 computer systems. However, the faster engines exploited a previously unknown error. They had failed to protect against integer overflow. The system had tried to force a 64-bit integer into a 16-bit space. This overflow caused a complete system shut down and lead to an expensive blot in the ESA’s copybook. A software handler that could have dealt with the problem had been disabled, and so there was no levee to dam the cascade of system failures that led to the destruction of the thankfully unmanned spacecraft.

 

Let these events serve as a reminder for the importance of proof-reading. Now go and review that code you’re working on before you publish it!

Prior to working in software development, I was a primary school teacher specialising in Computing. While not the traditional route into programming, I did gain some valuable experience in the classroom. In recent years, the market for computing and programming products in education has steadily increased. With Apple, Microsoft and Google muscling their way into British classrooms. It seems that everyone wants in on the action.

However, there are some fantastic (and free!) educational resources that are already available for the young coder. Both the BBC Micro Bit and Scratch are great introductions to computing with resources freely available online.  

Scratch

MIT’s block-based coding system, Scratch, was one of the pioneers in child-friendly code when it first appeared in 2002. Through numerous iterations Scratch has developed into an outstanding educational tool. The system eliminates most syntax errors as only certain blocks fit together.

image-1

Scratch can introduce concepts such as conditional operators, loops, events and even lists and variables. The program is entirely free and can be run through your browser. The Scratch website also features a vibrant community with literally thousands of projects uploaded and shared. There is a low-ceiling, high-threshold approach to Scratch. It is simple enough for a 7-year-old child to use; it can still be seen in introductions to Computer Science courses.

image-2

Above:  Shark Attack Remastered!

BBC Micro:Bit

Another route into computing is the BBC Micro Bit. The older programmers among us may remember the original BBC Micro, released in the 1980s, which was used in schools to teach about computing. The latest release, only a mere 33 years later, is the BBC Micro Bit. An initial batch of 1 million devices were given out to Year 7 students for free with the hope of encouraging a new generation of tech-savvy learners.

image-3

Consisting of a 5 x 5 array of LEDs, an accelerometer, a magnetometer, and two pubuttons, the Micro Bit is perfect for physical computing projects. The 23-pin edge connector allows for electronics projects. Below is an example of one of the projects you’ll find on the Micro Bit website. The block code creates a Rock, Paper, Scissors game, taking advantage of the accelerometer.  

image-4

It is even possible to use a Micro Bit in conjunction with Scratch! As your knowledge with coding increases, you can move away from block-based coding and use JavaScript.

For those unable to get their hands on a Micro Bit , the BBC have provided a digital simulator so that you can still practice coding and see the output.  If you are looking for a way to introduce young people (or teachers!) to coding, Scratch and the BBC Micro Bit  would be a great way to begin. If you have a coding itch that needs a Scratch, or if you have the Bit between your teeth, have a look at some of the following resources and get coding!

 

Scratch 

BBC Micro Bit 

Life is a highway … or a roller coaster … or is it like a box of chocolates? In software development, metaphors can be very useful when trying to understand a new concept. I have been reading the excellent Code Complete 2 by Steve McConnell. In Chapter 2, he states the following: 

A software metaphor is more like a searchlight than a road map. It doesn’t tell you where to find the answer; it tells you how to look for it. ” 

 

I have had my first experience of the Model-View-Controller (MVC) recently and, having worked mainly with Windows Forms, I have found the shift in thinking to be challenging. Despite an excellent lesson from our in-house teacher, Andy, I found that MVC wasn’t as straight-forward as I’d hoped. Knowing the value of a good metaphor, I found a great post DEV.to that put MVC in terms that I might understand. “Explain MVC like I’m Five“. The title spoke to me.  

I found a series of great comments in this thread, but some jumped out at me more than others. This lead me to search online for other metaphors for MVC – the simpler the better. Below, I have shared some of my favourites.

  1. Imagine a shop with three workers. One is responsible for taking the customers’ requests, one is responsible for getting the item the customer wants, and the third one wraps the item in nice packaging and presents it to the customer.
  2. You walk in a McDonald and you order at the big interactive touchscreen. You place your order at the screen – this is the View. Your order is passed on to the worker who will go and fetch your order – this is the Controller. Finally, the type of order that you have placed is the responsibility of the Model.
  3. Mark understands the toys in the toy box.
    Vicky knows how to set out toys for certain games.
    Charlie tells Mark to get the toys for a certain game and tells Vicky to set them out. Vicky tells Charlie what new game the user would like to do.
    This continues for the entirety of play time.

As I gain greater understanding of MVC, I hope that I will be able to create my own metaphor that works best for me.

Over the past few weeks, I have been working with WordPress to create a new website for a client. As you may know, WordPress is an open-source Content Management System used to create and manage websites. Having a little experience with HTML and CSS, I was looking forward to getting my hands on the website.

One of the most attractive features of WordPress is the expansive library of plugins that are available to users. By using plugins, users can add impressive features to their website without having to write intensive code. In my short time working with WordPress, I have found a few plugins to be particularly helpful.

quaytech-systems-blog-shameless-plugin-2

Most websites will need to have simple contact forms at a minimum. When you add in memberships and donations, you can find yourself creating many forms. Luckily the popular Contact Form 7 came to the rescue. I was able to create a number of contact forms which could then be customised and placed on various pages. In conjunction with the Conditional Fields for Contact Form 7 plugin, I was able to add conditional fields to my forms. For example, a few fields would appear only if the contact was from a business.

 

quaytech-systems-blog-shameless-plugin-3

Slider Revolution allowed me to add a snazzy carousel to the home page. However, the plugin can also add sliders and hero pages, all by dragging and dropping images. Slider Revolution helped to create an eye-catching experience for visitors to the website without much effort. To create such an effect with my current web design knowledge would have been a stretch to say the least.

 

quaytech-systems-blog-shameless-plugin-4

As someone who wouldn’t consider themselves to be much of a writer, Yoast offers help when writing posts such as this. Yoast offers guidance for Search Engine Optimisation, i.e. how to improve the visibility of your posts on search engines. You may need to use more complex sentences, or you may need to stop repeating yourself! Yoast offers clear help on how to make your posts more attractive to search engine results. This post is over the recommended minimum word count of 300, but not by much!

 

quaytech-systems-blog-shameless-plugin-5

Default Featured Image is an excellent example of how a plugin can solve a specific problem that you need to solve. I had been asked to add a default image for every post that did not have an accompanying image. Without having to write code, I found the above plugin which did exactly that. While it may not offer many features, it does exactly what I need it to do.

 

quaytech-systems-blog-shameless-plugin-1

As helpful as all of the previous plugins have been, they did not offer a level of control that was necessary to meet our client’s specification. WP Add Custom CSS has been invaluable in creating the website. It allows users to add custom CSS across the entire site from one place. You can still use your CSS knowledge to create a consistent and responsive website.

With over 50,000 plugins out there, I’m looking forward to seeing what new feature I add use next.

 

 

A lot has happened with Totally Unclutchable since my last blog entry. After weeks of work, I thought that I had created a fairly robust application. How naive I was.

Our resident testing expert, Andy, was let loose on the app and proceeded to break it at every turn. I realised that I hadn’t done enough to control the data being input into the system.  Andy entered strings where there should be integers. He entered characters designed to break my SQL queries. He found errors with the sequencing of steps when adding Cars. He was relentless. This was my introduction to validation. I clearly had a lot of work left to do to remove the Garbage data I was allowing to be used in my application.

 

What is Validation?

Validating data is when an application makes sure the data being input is of the correct type and is useful. There are several types of validation, but I concentrated on a few areas in particular:

  • Presence Check
  • Range Check
  • Format Check
  • Type Check

 

Presence Check

In order to add a new Car to the database, every field must be filled. For example, I needed to ensure that every car had a Daily Hire rate. I used the Validating and Validated events of a textbox to do this. I wrote the following method to check if the textbox wasn’t empty as well as checking if the content was a positive number. The user is unable to move onto the next textbox until an entry is made.

quaytech-systems-blog-totally-unclutchable-part-2-01

quaytech-systems-blog-totally-unclutchable-part-2-02

 

Range Check

It is often necessary to only accept values in a certain range. For example, ages must be between 18 and 75 to be accepted. This can be done by setting an upper and lower limit or by using comparative operators to make the checks. I have also gained some experience recently with ASP.NET Web Forms. The built-in validation tools make such a check much easier.  RangeValidator simply checks if the input is in between two fixed values.

 

Format Check 

Totally Unclutchable asks users for email addresses, phone numbers and postcodes. I found it quite complicated to create checks that allowed the correct formats. However, once I was introduced to Regular Expressions (Regex) it made the process much more accurate. Regex allows the programmer to decide which characters can be used and the format they can be used in. As an apprentice developer, I found it daunting to have to write my only expressions. Fortunately, Regular Expressions can easily be found online for the most common formats.

quaytech-systems-blog-totally-unclutchable-part-2-03

Type Check

As mentioned in Totally Unclutchable – Part 1, I designed the tables in my database to accept certain data types. For example, the Minimum Age for a Car is an integer; the Daily Hire Rate is a decimal. If my program fails to pass in valid data, it will crash. Therefore, checks for data types need to be done before calling to the database. I found that I needed to convert the text from textboxes to integers, decimals or valid dates. As you can see below, the DateRegistered required a timestamp to be appended for SQL to accept it.

quaytech-systems-blog-totally-unclutchable-part-2-04

Stopping the problem at its source

As I learned more of the properties of each control, I was able to be more sophisticated with my design. For example, in the Add Booking section, a user needs to select the start and end date of their car rental. I limited the dates available by using the MinDate and MaxDate properties of a DateTimePicker. I had prevented incorrect data from being input through improved design. If possible, it’s worth eliminating the need for validation checks.

quaytech-systems-blog-totally-unclutchable-part-2-05

The best way to learn to code is to actually code. I have read this in many places in recent months and now, over two months into my apprenticeship, it is making more and more sense. Until recently, I had  written mainly to the console. It was time to try something new. Introducing Totally Unclutchable, a fictional car rental company with an interesting name. This is my first experience of windows forms.  

quaytech-apprenticeship-totaly-unclutchable-part-one-main-menu

  • Specifications

To begin, I was given very clear specifications for the windows form. In brief, it needed to have a Cars Module, a Customers Module and a Booking Module. A user can add, edit and delete cars and customers. The Bookings Module allows the user to assign available cars to customers in order to create a booking. At this stage of my apprenticeship, I require a lot of scaffolding with the instructions. In time, I will to design a program more independently.

quaytech-apprenticeship-totaly-unclutchable-part-one-cars-list

  • Steps involved

To get the ball rolling, I learned about how to connect my windows app to a SQL database of customers, cars and bookings. To do so, I needed to use a connection string and make use of the SqlConnection class. It is good practice to close any connections before proceeding.  Over the course of the project, I needed to make various calls to the database. I learned a great deal about the format of a query. I learned the hard way that SQL and C# have different formats for dates. This was important in the AddCar and AddCustomer forms, where I needed to validate the information that is input by the user.

Using Object-Orientated Design has been a challenge for me in this project. I’ve had to understand the how classes and objects can interact with each other. Prior to beginning, I had a shaky understanding of constructors and methods, but I feel that I have made progress in these areas. I recognise the importance in planning the design and layout of a program in advance. Totally Unclutchable features a series of forms and manager classes.

quaytech-apprenticeship-totaly-unclutchable-part-one-visual-studio-project

I had no idea how much time I would spend on debugging when I started Totally Unclutchable. Debugging has helped me to find syntax errors, to correct data types, and to correct SQL queries. As I progress as a developer, I am aware that I will spend more and more time debugging.

 

  • What I’ve learned so far

While initially daunting, this project has helped me better understand Object Orientated Design. I had done quite a bit of reading, but nothing beats actually writing code. I have found it quite rewarding to work with windows forms as there is something to show for my efforts; there will be a working product by the end of the project. I have gained experience in using Visual Studio. Its tools for debugging have been particularly helpful.

 

  • Next steps

The Bookings module of my program remains. I will have to calculate whether a car is available, assign customers to available cars and check that they qualify for the rental. I have a great deal of work left to do. Join me next time to see if I can get Totally Unclutchable on the road!

Friends is back on Netflix and what better way to celebrate than to start a blog on being an Apprentice, and complete one of my first IT exercises to create a database of the friends characters and write some queries!

This past month, I have begun my apprenticeship with Quaytech Systems. Over the next year or so, I will be learning about Object Orientated Programming with the long-term aim of becoming a software developer.

Here at Quaytech, we are all big fans of Friends so, as an introduction to database management, I it made sense to create a database for the characters with SQL. This was a great way to introduce me to relational database management. I spent a few days creating tables of employees, managers, departments and salaries while making links between them using foreign keys. Once everything was set up, I started experimenting with writing queries. For example, I was able to write a query to find out which employees were in the finance sector (hint: it was Chandler).

Sub-queries were an early stumbling block but with a plethora of online resources to help (as well as very helpful co-workers, ) I was able to further my understanding of SQL.  All of this practice came in handy, as I recently wrote my first query which was implemented to answer a support ticket; the first of many, I am sure.

The next step was to access my Friends database through C#. I was introduced to Connection Strings and SqlCommand. I found this difficult at first; however, after a bit of debugging, I successfully accessed the SQL database through C# and even wrote some methods.

In my short time at Quaytech, I have already learned so much. I am looking forward to continuing my learning journey.