The difference between stack and heap

stack

The stack is this chain of suspended function calls, because elements in the stack (function calls) depend on each other.

stack

In a stack of items, items sit one on top of the other in the order they were placed there, and you can only remove the top one (without toppling the whole thing over).

heap

The heap is simply the memory used by programs to store variables. Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.

heap

In a heap, there is no particular order to the way items are placed. You can reach in and remove items in any order because there is no clear ‘top’ item.

source: What and where are the stack and heap? (stackoverflow.com/)

Don Knuth On Programming

I think of a programming language as a tool to convert a programmer’s mental images into precise operations that a machine can perform. The main idea is to match the user’s intuition as well as possible. There are many kinds of users, and many kinds of application areas, so we need many kinds of languages.

I’ve attempted to organize many of the best ideas that have been discovered related to programming, and to explain them effectively, because I believe computer science is a beautiful body of knowledge.

via

THE END

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