Clean Code by Robert Cecil Martin – Review

Clean Code is an excellent book that all programmers should read. However its not for complete beginners. First chapters are covering basic: naming conventions, comments, functions… later it goes through good coding practices and rules that apply to all programming languages.

Clean Code: A Handbook of Agile Software Craftsmanship by Robert Cecil Martin

Clean Code Bookcover

Clean Code is an excellent book that all programmers should read. However its not for complete beginners. First chapters are covering basic: naming conventions, comments, functions…  later it goes through good coding practices and rules that apply to all programming languages. Code is written in Java what makes more of a “Clean Java Code” It uses Java for all of the examples and some of the chapters are dedicated to Java-specific issues. This can be a limitation to the users.

The writing style of the book. Its simple, clean, and well crafted. This book’s biggest strength is that it includes tons of code examples, including some fairly long and in depth ones. Instead of just listing rules or principles of clean code. There are a number of lengthy examples in the book, demonstrating code before and after cleaning with a detailed description of the rationale for each small change.

The Agile origins of the book are seen with the strong emphasis on testing, and Test Driven Development (JUnit framework).  Author emphasises the importance of witting clean code that will last for a long time, over iterations and between programmers.

CONCLUSION

This book is perfect for Java developer but it can be very helpful for junior developer who want to take coding practices to next level. I recommend this book to everyone who wants to post their code problem on the programming forum 😀 Stay Awesome!

 

 

Jekyll in action

Jekyll is a free, open source, static site generator written in Ruby by Tom Preston-Werner, GitHub’s co-founder. Website created in Jekyll can be hosted on platforms like GitHub or Google Firebase. It’s commonly used by bloggers with experience in programming.

 

WTF is Jekyll?

3083652Jekyll is a free, open source, static site generator written in Ruby by Tom Preston-Werner, GitHub’s co-founder.  Website created in Jekyll can be hosted on platforms like GitHub or Google Firebase.  It’s commonly used by bloggers with experience in programming.

Jekyll is different than Content Management Systems like WordPress. It doesn’t have build in graphical interface, but it can be implemented(more about this later).

Instead of using databases, Jekyll takes the content, renders Markdown or Textile and Liquid templates, and produces a complete, static website ready to be served. Writing page from scratch can be challenging, but Jekyll have countless themes available online:

If you want you can buy themes on Market.envato.com.

Advantages of Jekyll

Jekyll is fast. Faster than any WordPress site. Static website once is generated it can not change. It doesn’t require connection to a Database what makes it super fast. Loading speed can be effected by things like large images, this is factor to look out for.

Jekyll is Simple. Jekyll doesn’t add any bloat to the website or blog you are working on. Many of the Jekyll Themes are very minimal and content oriented. take a look at Netflix website powered by Jekyll.

Jekyll is secure. Static websites will not have any database to manipulate. So Jekyll a 100 times safer than WordPress. But nothing is un-hackable. Not having database makes it easier to use for people with no experience in Back-end development.

Installation

Installation is one of the trickiest things in Jekyll. Jekyll is based on Ruby  and it require few things to run:

  • Ruby (including development headers, v1.9.3 or above for Jekyll 2 and v2 or above for Jekyll 3)
  • RubyGems
  • Linux, Unix, or macOS
  • NodeJS, or another JavaScript runtime (Jekyll 2 and earlier, for CoffeeScript support).
  • Python 2.7 (for Jekyll 2 and earlier)

After meeting all the requirements you can install it like any other Ruby Gem:

$ gem install jekyll

Installation process was greatly explained in many articles in the past, more information about the installation process you can find on official documentation:

This works only if you are Mac/Linux user. If you are Windows user it’s little more complicated…

 

Hosting

octojekyllGitHub gives option to host static websites for Free including domain based on the account name. GitHub Pages are public web pages for users, organisations, and repositories. GitHub Pages are powered by Jekyll behind the scenes, so in addition to supporting regular HTML content, they’re also a great way to host your Jekyll-powered website for free.

Tutorial explaining this process can be found on GitHubSupport page

Jekyll comes with plugin for importing content from WordPress.com.

CMS

Creating posts in Text Editor with Markup language and generating new website with each update can be frustrating. Companies like CloudCannon.com offer solution to this problem. Using CMS gives you or your client direct access to the server and option of editing the page and adding new content really easy without and technical knowledge. However basic account costs 25$/month.

Alternative option is provided by SiteLeaf. Another option for personal use is free Prose.io

Conclusion

This post is a beginning of new series of articles about web development. If you are looking for more unique way of blogging this can be option for you. However it requires a knowledge of  front end development and it can be too complicated for people not familiar with web development. This can be simplified with CMS’s for small monthly fee. I hope this article was helpful and now you have new tool under you belt.

Here is example of my Portfolio website built with Jekyll.

 

 

Update

Blog Update

 

Edit: I’m back to blogging on WordPress


I’m moving my blog into (GitHub , click). I’ll separate the future content into two blogs. For subjects related to Games Development I will continue to  use WordPress-this blog. And the second blog for more advanced software development topics like low level languages(CIL, MSIL, Assembly, ), algorithms and discrete mathematics.

Work in progress…

C# Decorator Design Pattern

C# Decorator Design Pattern tutorial

Link to Source code

In this article You will learn how to implement decorator pattern in C#. Decorator pattern allows to modify an object dynamically it simplifies the code by adding new functionality at runtime. Adding new functionality to the object doesn’t effect the initial class structure.

In my example I’ll simulate the process of enchanting an item in RPG game.

UML Diagram:

l11

Component

This interface will be used as base for decorator and concrete items. It contains methods that will return properties of an item.

public interface IItem
{
    string GetName();
    int GetValue();
}

Base Items like armor or Sword will implement this interface and return fixed values.

class Sword : IItem
{
    public string GetName()
    {
        return "Iron Sword";
    }

    public int GetValue()
    {
        return 20;
    }
}

Decorator

This is the key part of the pattern, it maintains a reference to a Component object and defines an interface that conforms to Component’s interface. In my example this will be represented as an Enchantment of the item. Decorator will have form of abstract class and will have protected constructor

A protected member is accessible within its class and by derived class instances.

abstract class Enchantment : IItem
{
  IItem _item = null;

  protected int _Value = 0;

  protected Enchantment(IItem baseItem)
  {
    _item = baseItem;
  }

  public string GetName()
  {
    return (_item.GetName() +" +1 ");
  }

  public int GetValue()
  {
    return (_item.GetValue() + _Value);
  }
}

Class that extends the Decorator can change the protected values in parent to eventually change the return values.

class Magic : Enchantment
{
  public Magic(IItem baseComponent): base(baseComponent)
  {
    this._Value = 30;
  }
}

Client

Last part of an application. Here the instance of an item is created and modified. In this example you can see how the values changed after adding decorator.

class Program
{
  static void Main(string[] args)
  {
    IItem newItem = new Sword();
    Console.WriteLine(newItem.GetName() + " Value: " + newItem.GetValue().ToString());

    newItem = new Magic(newItem);
    Console.WriteLine(newItem.GetName() + " Value: " + newItem.GetValue().ToString());

    Console.ReadLine();
  }
}

To conclude, Decorator can attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for extending functionality. I hope that this was understandable and it will help you with your projects. This was probably the last design pattern to cover on my blog, last in this month at least. Stay Awesome!