This article is aimed at Young Professionals who know about coding and want to become a better developer.

1. Learn to write Clean Code

I know most developers learn from the web, but I can really recommend this book: The Clean Coder by Robert C. Martin. This book learns you to smell bad code and fix it. I worked out some of his concepts below:

Error handling

Use Exceptions rather than return codes. Exceptions are testable and require no if statements around method calls. You can catch the exception on a level that you want. Also don’t return null. It forces you to check for null values and can cause NullReferenceExceptions in production code. Also do not pass null as a parameter into a method, this is even worse than returning null from a method.

Null? Null? Null?

Imagine this PHP code sample:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private function letsFlyAway(Flights $flights)
{
    foreach($flights as $flight)
    {
        $gate = $flight->gate;
       
        if($gate != null)
        {
            $actualGate = $this->allGates->find($gate);
            if($actualGate != null){
                 triggerOnGateEvent($flight->plane);
            }
        }
    }
}

Did you notice the missing null check for the $allGates variable? If you have a catch all on your application, what should it do with a NullReferenceException? It’s easy to say to just fix it by adding the null check, but it’s too many.

Wrapping the API

An other C# example for wrapping an External Lib or API: This code required you to get the latest error from a method, when things went wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class ExternalExtension : External
{
    const string key = "...";
    public void SetHexData(string hexData)
    {
        var result = SetHexData(key, hexData);
        if (!result)
        {
            throw new ExternalException("Unable to set HexData. " + GetLastError());
        }
    }

    public void SetHttpDataFromPayload(string payload)
    {
        var decoderLoaded = SetHttpData(payload);
        if (!decoderLoaded)
        {
            throw new ExternalException("Unable to set HttpData " + GetLastError());
        }
    }
}

Now i can just call the method like the code below and handle errors on any level.

1
api.SetHttpDataFromPayload(payload);

Classes should be written like books/newspapers

The order of a class is important to the readability of the code. Try to keep methods that are private below the public methods. The main functionality on abstract level first, and if you want to dive in deeper you can scroll into the deeper concrete levels of code.

Example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Decoder : IMessageDecoder
{
   public void Decode(string message)
   {
       var inputMessage = ParseMessage(message);
       this.decodedMessage = DecodeMessage(inputMessage);
   }

   private InputMessage ParseMessage(string message){
        ...
   }

   private DecodedMessage DecodeMessage(InputMessage message){
        ...
   }

}

Clean up comments

If you don’t keep your codebase clean, nobody would. Bad code invites to write more bad code. So delete comments that don’t matter, do not leave commented code. Come on seriously we have Git now.

Instead try to tell your story in good naming of your variables and methods. I have an example here:

1
2
3
4
5
6
public Decode(){
    if (_inputMessage.MessageType == "Sensor4")
    {
        ...
    }
}

Who knows what this might be? By refactoring the if statement to a method, code becomes readable in context.

1
2
3
4
5
6
7
8
9
10
11
12
const string HttpSensor = "Sensor4";

public Decode(){
    if (IsHttp())
    {
        ...
    }
}
private bool IsHttp()
{
    return _inputMessage.MessageType == HttpSensor;
}

2. Learn to write Unit Tests

When I first ran into a problem that was too big for me, I got help from a senior colleague. His intend was not to fix my problem, only to get me through the process. He helped me to tackle my problem by writing Unit Tests. Read about this from Wouter here.

To write good Tests you should learn about mocking objects that you put in through dependency injection. A good method for development is Test Driven Development (TDD). It means writing tests before code, and only code when your tests fail. This is an excellent way to get complex problems fixed.

I think tests should clarify what’s wrong, test core features and apply the same codings standards as the feature code. Making tests readable with constants helps a lot.

FIRST testing

A good way to write good Unit Tests is to use FIRST, also from the Clean Code book of Martin. Learn more about FIRST in this article. FIRST stands for:

  • Fast
  • Independent
  • Repeatable
  • Self-validating
  • Timely

Pro tip: Use Unit Tests to test out language features, API’s and such. The Unit Test can feel like a learning process.

AAA testing

No it’s not about testing battery’s. it’s another abbreviation. It stands for: Assign, Act and Assert. It’s a way to organise a single test. See this example below.

1
2
3
4
5
6
7
8
9
10
[TestMethod]
public void testGetBetterAsADeveloper()
{
    var develop = GetDeveloper();
    var articleContent = GetArticleContent();

    developer.read(articleContent);

    Assert.IsTrue(developer.knowsAbout(articleContent));
}

3. Learn to debug

Many starting developers haven’t learned the basics of developing. If you are developing for the web, please tell me you have heard about the Developers Console. Learn your way around, as you can easily debug your web pages.

Learn how to place breakpoints in your code and how to navigate trough your code. Debug.WriteLine or console.log will always be slower.

4. Learn Git

No really, learn Git. Not just some UI tool like SourceTree. Learn to fish, not where to buy the fish. Then buy the fish by the best supplier. I see people that know how to use a tool and be stunned when they switch to a different tool. Every tool extends the Git CLI commands. So once you know your Git CLI commands, all tools become understandable. Go beyond the basics and practice. Practice for example with CodeAcademy.

Git workflows

After getting knowledge how Git really works, learn about some workflows:

At my current job we’re using Feature Branching. For every task on the Scrum board, we create a new branch and make a pull request after we finish the task. The naming convention for a new branch is: [name]/[feature]. So for example: mart/new-feature. Within VSTS we make use of the autocomplete function. The autocomplete simplifies deleting the branch after merge in master, completes the task on the scrum board and can squash your commits in one fine commit.
Learn about a squash merge here.

5. Learn about Scrum / DevOps tooling

I assume you have heard of those terms. If not get familiar with it. Try to keep your learning also Agile. Fail fast, learn fast.

Scrum

I assume you know about the roles in Scrum(Scrum Team, Product Owner and Scrum Master) . Those are really well known. But do not forget the pillars of Scrum:

  • Transparency
  • Inspection
  • Adaption

Keep the pillars in mind when doing Scrum. Check the Scrum Guide here.

Tooling

Microsoft VSTS and Atlassian Jira are both great tools. VSTS is the way to go if you’re in Microsoft development. You can create a project for free. Some links to get you started.

VSTS provides it all: Git repositories, CI/CD, Azure deployments, Automated Tests and Scrum boards. But is not limited to it. You can use different sources like GitHub or Bitbucket. And it’s possible to deploy to different platforms.

Also checkout Microsoft and DevOps and download their guide to DevOps.

6. Learn how Package Managers work

The basic feature Package Managers (PM’s) give you is getting Packages, but there is actually a big difference between Bower and NPM (two JavaScript PM’s). By that I do not mean in contents, but in the way the dependencies work. If you work with those PM’s be sure to know the difference. Bower is flat by default and NPM does nested dependencies. This means that a package you install, requires other packages it also installs.

I collected a list of PM’s in different languages so that you will know what dev’s are talking about:

PM Language
Nuget C#
NPM JavaScript
Bower JavaScript
PEAR JavaScript
Yarn JavaScript
Maven Java
Gradle Java
RubyGems Ruby
Composer PHP
Pip Python

Developers will always learn

With the fast changing market developers must keep learning. You are always a senior to someone, share your knowledge and learn from your seniors. I will try and share my knowledge here.

For Microsoft developers i recommend Pluralsight. There are some great resources out there, if you find some good ones, please let me know.


Leave a Reply

Your email address will not be published.