How to be a better programmer

A friend (a skilled data scientist and researcher) asked: “do you have any pointers on improving my programming skills?” It is getting easier to get started programming, but what does good code look like? How do you become a better programmer? I interview a lot of people for startup software engineer positions at PSL. Here is what I look for.

1. Be competent with data structures and algorithms

When you’re writing software, you need to understand the building blocks (data types) and common strategies (algorithms) for computing things. These are common to all languages.

What is the difference between an array and a linked list? When do you use a hash?

Depending on what language you are using, an array might pre-allocate a lot of contiguous memory. An array is great for accessing things at a predictable location. A linked-list, on the other hand, is better if you need to insert data at random positions, so you don’t have to re-allocate or move the all the data.

How would you sort a list of data items?

Even if you are using built-in language functions to sort, concatenate, or search you have to understand what types of operations are going to be expensive (requiring CPU or memory) of which leads us to…

Big-O Notation

Big-O notation is used in Computer Science to describe the performance or complexity of an algorithm. For example, scanning an array to read all the entries takes n operations, where n is the number of items in the array. This would be called an “O(n)” or “order n” operation. Big-O is concerned with the worst-case scenario. The important thing is that you can think mathematically about how long your algorithm is going to take.

2. Understand application architecture

Server vs. client

Considerations like generating unique IDs, keeping data consistent across clients, deciding where to do validation.

Performance vs. scalability

Performance refers to how fast a program runs; scalability refers to software that is architected to run on multiple systems. If you had an algorithm that is slow and hard to optimize, perhaps it is easier to parallelize it and run it on multiple systems concurrently.

What is a cookie? What is a socket? What is virtual memory?

A certain level of knowledge of the underlying operating system or protocol you are coding on top is required. A cookie is part of the HTTP request, persisted as a file (or in memory) on your local system. A socket represents a port number and IP address for communication between two programs over TCP. Virtual memory is usable space that appears as RAM although it is really on your hard disk, swapped automatically as necessary into the computer’s limited physical memory.

3. Write clear code

Understanding the above concepts goes a long way to making your code clear. Clarity is perhaps the most important aspect

Functional vs. Object Oriented

Functional programming makes functions the primary organizing concept in your code. Functional programming avoids shared state, mutable data, and side-effects. Object oriented programming models functions and data together as class objects. Objects retain their state and can inherit characteristics from other objects.

Separation of concerns

For software to be clear and understandable (and as simple as possible), a developer should decompose it into parts with as little functional overlap as possible. A function or module should be single-focussed. For example, the MVC (Model View Controller) pattern is an established pattern that separates display logic from data manipulation logic.

DRY (Don’t repeat yourself)

Don’t copy and paste your code. Create modules for re-use. DRY reduces repetition using abstraction and data normalization to avoid redundancy.

4. Test driven development

Should I write tests for my code? Absolutely, but don’t worry about it until after you’ve master the basics.¬†Test driven development is where you write tests first, then write code that passes those tests. While tests don’t guarantee that your software is bug-free, a suite of tests allows you to make rapid changes while verifying that you didn’t break any of the existing tests (functional requirements).

5. Be consistent (follow coding standards)

Follow basic style guidelines and be consistent. Adopt the guidelines of a prominent company like Google or Microsoft., or write your own. My style guidelines for javascript.

6. Get feedback

The best way to become a better programmer is just to get started. Attempt to contribute to an open source project, submit a pull request and get feedback.

What is a pull request?

Programmers submit pull requests to contribute to open source projects. Programmers ask for changes to be committed (pulled) to a code repository (like git) by the project owner.

That’s it. What do you think makes a better programmer? Leave a comment below.

Related: 10 Habits of 10x Developers, Ruby interview questions