Why inheritance is bad?

It’s been a while ago, when I first study programming in college. I remember the moment when professor introduce us object oriented programming by the classic dog and cat example:

Dog is an animal, Cat is an animal, therefore, they can both share the behaviors of an animal.

Read More...

Good engineer, bad engineer

This an article inspired by the book “Hard things about hard things”, the “good product manager, bad product manager” section. Which is a really good way to explain what is the good quality of a position and what is the opposite behavior of that.

Read More...

Ruby Concurrent Programming

This is a talk that I presented in Case Common learning lunch:

Concurrent programming in Ruby is hard.
Before we start implement things with ‘Thread.new’, we should know the difference between Thread and Process, how to write thread safe code and what framework to use.

Read More...

Bash like a marshall

Bash is a programming language design for interact with user. Which have a very flexible syntax to take command from user.
But in the bottom, it’s just a programming language like any others, it provides variable, function and flow control.

Read More...

Build dropdown list with RxJS

Dropdown list is one of the most common web UI component, but yet one of the most difficult to implement. Recently I was working on a navigation dropdown list with animation. But this time, I implemented it with RxJS, wh

Read More...

Let's build react.js

Recently React is growing to become the de facto standard for web components. And it is also pretty straight forward to learn and use React.

I recommand to start with the official website for documentations, also some examples on github and Todomvc

However, for people already know how to write React, they might still wondering why React is built in a certain way, like React DOM, state, how React update and manipulate the DOM elements.

For those who are curious, this article is going to rebuild React from scratch and create a workable basic React-like framework, by going through the logics in React source code. I hope you can understand how React works after reading this post.

Read More...

Rails abstraction showcase

Abstraction showcase

Maintaining large application is always a pain for rails developer.
Because the MVC scructure encourage developer to write business logics in controller and model.
Therefore when application become bigger, usually it will result in Fat controller or All mighty model that have lots of business logics crumble all over the places.
Extract those logic to another place is one of the solution, but how do we extract and where to extract is another problem.

Read More...

Rails circular dependency

Circular dependency

Recently, I encountered a circular dependency problem that happened in rails,
When the parent model is dependent on child model, it returns Runtime Error for Circular dependency.
However, there is 2 child model that have circular dependency on parent model, but only one will fail on loading:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# ./app/models/alpha_product
class AlphaProduct < BaseProduct
end

# ./app/models/base_product.rb
class BaseProduct
PRODUCTS = [AlphaProduct, Product]
# this works
# PRODUCTS = [Product]
end

# ./app/models/product.rb
class Product < BaseProduct
end

# test file:
require 'spec_helper'

it 'does something' do
AlphaProduct.do_things # RuntimeError: Circular dependency detected while autoloading constant AlphaProduct
end

But when we remove the dependency on AlphaProduct, the application works fine. Why is that?

Read More...

Dig into the rails errors

Errors

Rails errors is handling by ActiveModel::Errors, which generate error messages with attribute name and error type.
Recently I am working on some feature related to rails error messages, so it is a good time to go over how the rails errors works.

It’s just a hash

ActiveModel::Errors actually is a wrapper for error messages hash, which include the attribute names and error messages for attributes.

Read More...

Source code odyssey: angular.js injector

Angular.js

Angular.js is a fasnating framework that including a lots of interesting features.
One of the unique feature in Angular.js is dependency injection,
instead of requiring and injecting the dependencies, Angular.js creates a special component to find the dependencies according to parameter names and pass it through the function:

1
2
3
4
5
6
7
8

var injector = angular.injector();

injector.invoke(function($http) {
//get http service from service providers
$http.ping('http://angularjs.org');
});

Read More...