Few things quite simple but need to keep remember

Vincent Nguyen 3 June 2017
programming

Yo! I came back after 2 months. This post is my note after read a news from CodeShip.

From wiki:

Code refactoring is the process of restructuring existing computer code without changing its external behavior.

Why Refactor Your Code

I still think, in the first 2 working years, refactoring is something that I will start to refactor after finish a project. And of course, after finished the project, I forgot my promise - always.

Until a day, when I faced to senior developers from a different country, they came to Vietnam to work with my team. I felt very bad, I can't work with them. I saw a big wall, I need to get out of comfortable zone to survive.

I started to re-learn everything about programming, up to now, I still learning .. haha … Learning is never stop.

Alright! Back to the topic.

Anyone can write code that computer can understand. And only good programmer can write code that human can understand

Refactoring will help the code more readable, performance improvements. Refactoring code doesn't change behavior or output.

In programming, there is a software development process called TDD: requirements are turned into very specific test cases, then the software is improved to pass new tests, only. There are three phases in TDD:

In general, code that doesn't get refactored as a system works by hopes. Pray to system work.

There are specific and general guidelines for refactoring and for creating clean code that all developers must to know.

So where that guidelines? How can I improve my code?

Where?

Before start to learning anything either new language or new framework, let's start to learn a process of how to think through problems. Don't only good for learning but none of the good coding practices.

There are design patterns that help decouple and remove most of the heavy query method usage, such as Tell Don’t Ask, Eastward Oriented Code, and Monads.

NOTE: I will write blog posts about three this concepts soon!

Learning to apply patterns such as these will help relieve you of many of the headaches you experienced as a new programmer.

Rails

By design, Rails has a way to organize data and behavior into specific areas to help maintanability and functionality.

The Rails's code may be implemented something like:

Here, Model and View are both doing more than they should - They are not following the SRP (Single Responsibility Principle). The model should not be reponsible data for presentation and the view should not contain conditional logic for how it's rendered.

So, the new way should like: