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!