When You should Not use node.js?

Node.js is very hot now. But just as Ruoyu Sun said, node.js has its own niche.

“Node.js was create to make writing concurrent web applications easier… It also chooses a coding style that is common in JavaScript – event driven and callback style, which is not a good way to organise complex logic. Luckily, the logic of most web apps are not that complicated. “

Only in some specific occations, node.js suits your needs best.

“When you start a new real time web app with not-so-complicated logic, try it.”

In other occations, you should think twice.

“If you are developing an online game, you might want to deal with concurrency more seriously – coroutines might suit you better. If you start a content-centric or CRUD web app, you don’t need Node.js. If you write it with Rails or Django, you can develop much faster and you don’t need to deal with callbacks mess on top of your logic. The thing is, for these apps, you don’t have lots of concurrent requests. And for a single request, most of the time is spent on network transfer and perhaps database query – Node.js does not solve the essential problem here. So instead of squeezing a few milliseconds out of perhaps a hundred, you are way better off getting a SSD or a better bandwidth.”

The suggestion is:

“So only use Node.js when you actually need it. Don’t just use it because it is cool / it is popular/ I heard it’s fast / I want to learn something new.”

THE END

Difference Between Currying And Partial Application

Partial application is the conversion of a polyadic function into a function taking fewer arguments by providing one or more arguments in advance. It means to fix some of the function’s parameters, and get a new function.

from functools import partial

def foo(a,b,c):
   return a + b + c

foo23 = partial(foo, b=23)

foo23(a = 1, c = 3)  # => 27

Currying is the decomposition of a polyadic function into a chain of nested unary functions. Thus decomposed, you can partially apply one or more arguments, although the curry operation itself does not apply any arguments to the function. It means currying is a way of using anonymous single-parameter functions to implement multi-parameter functions.

bar is a multi-parameter function.

var bar = function(a, b) {
  return a * a + b * b;
}

foo is its currying function.

var foo = function(a) {
  return function(b) {
   return a * a + b * b;
 }
}

(foo(3))(4)

// or

foo(3)(4)

“Currying offers a very natural way to implement certain partial applications. If I want to partially apply foo by fixing its first parameter to 5, all I need to do is var foo5 = foo(5). There – done. foo5 is our partially applied foo.”

via

THE END

GPL vs BSD: Which license gives you more freedom?

First,There are differences between these two licenses.

GPL license give you the four freedoms:

  • to run the software
  • to have the source code
  • to distribute the software
  • to distribute your modifications to the software

The only constraint is, if you give the software to next person, you have to ensure he/she also have these four freedoms.

BSD license is different. You can use the software to do anything, and have no obligation to ensure the next person having the same freedoms. The only constraint is that you can’t remove the name of the software’s author.

Which license gives you more freedom?

You may say the answer is BSD License. Because it gives you the right to decide what rights to bundle with the software. That is much closer to the absolute meaning of “freedom” than the GPL.

What the GPL terms “freedom” is actually fairly subversive, because it forces you to do certain things. Most people who are forced to do something call that a “restriction” rather than a “freedom”.

But…

The another side is, If you use the BSD license, you have no way to ensure the people after you have the same freedoms as you. Only the GPL license can ensure that. It means the GPL model is sustainable.

So if we think about the sum of all people’s freedom, GPL license gives you much much more than BSD.

via

THE END

Rules Of Coding

1. DRY – Don’t Repeat Yourself

It means that the same code should appear once and only once.

Wikipeida: http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

2. YAGNI – You ain’t gonna need it

It means that always implement things when you actually need them, never when you just foresee that you need them.

The philosophy is doing the simplest thing that could possibly work.

Wikipedia: http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It

3. Rule of three

It means that the code can be copied once, but that when the same code is used three times, it should be extracted into a new procedure.

wikipeida: http://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)

THE END