Tuesday 30 December 2014

Lambda Calculus, Lambda Abstraction

Lambda Abstraction is the way we define an anonymous function in λ calculus. Suppose we have a function like f(x) = 2x which in fact is a function that maps any x to 2x, now from the previous posts we already knew that in λ calculus the expression 2x (which is a term) can be shown as * 2 x, but the way we show this as an anonymous function is like:

λx. * 2 x

See there is no equality sign, here λx is something anonymously like f(x) and the dot after it shows the start of the evaluation formula. So a familiar C or Java-like function like the following:

int doubleIt(int x) {
  return 2 * x
}

Will be something like the following in Lisp-like language for example (which you can use it inline of course):

Sunday 28 December 2014

Lambda Calculus, Expressions

Until now we understood that λ calculus is nothing but a formal system to describe algorithms of computer programs. Although in theory it has mathematical support, but we are not interested in this scientific detail, so let us continue talking about how we can define algorithm and programs with the help of λ calculus.

Lambda calculus introduces an inexpensive way to express a function or an algorithm body. Nothing has all the good things,  λ calculus introduces an inexpensive way to write a function but it is a bit not like what we used to see in non-functional systems, like ordinary programming languages (say java 6 for example).

Suppose you want to multiply 1 and 2, divide 3 by 4 and then add these two results. There are some notation methods of doing this:
  • Infix notation: 1 * 2 + 3 / 4
  • Postfix notation: 1 2 * 3 4 / +
  • Prefix notation: + * 1 2 / 3 4

Almost everybody knows the infix notation this is what usually we do in school math and we expect compilers pars our expressions in programming. But λ calculus expression is in prefix notation and this may bother us at first. 

Friday 26 December 2014

Lambda Calculus, Computable Function

A computable function (here function doesn't have the meaning of what we have in calculus) is basically nothing but what we usually do in a body of a function or procedure during programming. It is a mathematical term which widely has been used in "Computability Theory".

Let's describe it in this way, you have a function gets some inputs and based on some algorithm it computes required output. The process you do on these inputs to get the result or the applied algorithm can be simply demonstrated by a computable function. It is a formalized mathematical method of describing intuitive notions of algorithms.

Note that if we want to bring exact definition and reasoning of what computable function is or can be derived, we need to go deep in some advanced mathematics and some information on "μ-recursive functions", "Turing Machine", "Register Machine", ... are also required. So for now, we just try to describe things in more descriptive and tangible ways rather than theoretical ways. So again, we just accept by definition that a computable function accepts inputs and after applying a procedure or an algorithm on the given inputs, it calculates the output. Now let us expand our knowledge on computable functions.

Wednesday 24 December 2014

Lambda calculus, a formal system

Forget about the name "Lambda calculus" which is strange, grand and somehow serious of course,  it is nothing but a well-defined abstraction method in mathematics like what we already learned in school as Euclid's Elements in geometry, Algebra or Calculus and ... These abstraction methods are also called formal systems. A formal system should have a language (symbols and grammar) to be able to express systems with some rules and axioms. In fact, you can assume any programming languages as a formal system which is capable of expressing systems in terms of language statements. As I mentioned a formal system also should have some axioms and rules like what we have in Euclidean geometry, Algebra or Calculus.

Tuesday 23 December 2014

Software Integration - Connection Points

If you have a quick look at the titles of my previous posts, you'll find that one of my interests in software engineering is the things related to software integrations, titles like stability patterns, feedback, and ... Although all of these topics can be get used in both inside single software design and in integration of many subsystems, but using them in software integration is much more important, because:
  • When a team or person writes a software they know about the entire components well enough to adjust them to work well together.
  • When you try to integrate software systems to work together in an ecosystem as a single software solution, you usually don't know how these subsystems behave in a different situation so the integration environment must have some intelligence itself to keep them working. And this is the place where the stability patterns, feedback, ... comes into play.
System integration is the process of gathering several subsystems or components together make them  work together as a single system while making sure the system works well in every condition. Now let us see what in an integration is that makes it difficult to make the whole system stable.

Friday 19 December 2014

Circuit Breaker - 3

Here I will try to describe how easy is to implement a circuit breaker (CB) in your system to have a more stable software environment. First we have to choose the architecture we want to apply the CB on it. What about have it as a separate module either as a single binary or just as a piece of code which works in a binary with other parts.

Sample software circuit breaker.
Look at the diagram, the CB we are going to build is going to be something like it. The component we are going to build has, at least, these parts:

  • Input: An interface module to receive data from one component.
  • Output: An interface module to transmit data to the next component.
  • Control: A central control unit which manages passing or dropping or disconnecting the flow and/or flow path.
Now let us see how we can have this CB to do what we want, suppose we want it to drop more than 1000 data packet per second and we want the CB in a simple single thread mode. The following shows a pseudo code for what we have in mind:

Thursday 18 December 2014

Circuit Breaker - 2

We saw how circuit breakers (CBs) work in electronics and power engineering, and mentioned that there are many more usage examples in other industries too. Now let us see how we can get the benefit of using a CB in software design.

Using circuit breaker in software design
Look at this diagram, at the top we have two components, they can be two software modules in a single binary or two separate binaries in a single machine communicating to each other through shared memory, a pipe, ... or they may even be two separate binaries working in a network. In any of these cases component 1 simply sends some data packets to component 2, they may also have some feedback of how things are going on the other side too.

The idea is of using a CB is exactly like what we have in other industries, separating components if something wrong happens to the flow of data, one of the components or ... Depending on what situations or conditions the CB separates two component, we can simulate the behavior of a fuse, circuit breaker, IDE circuit breaker and ... (in my point of view naming doesn't matter that much) 

Wednesday 17 December 2014

Circuit Breaker - 1

When you see and compare electronics or electrical engineering with
Omron circuit breaker
software engineering, you'll find many ideas which software engineering borrows from them and one of them is using Circuit Breakers. We have both electronic and electrical circuit breakers which have widely used in industry and power distribution. They are used to protect two different circuits from each other to not let them have a negative effect on each other.

Note that circuit breakers are not fuses, they look like them but are different. They detect a fault condition and they separate the circuits they are protecting. They connect the circuits manually or automatically once they detect the fault no more exists, we will see how we can use the same idea to protect two different application in a software ecosystem when one feeds the other.

In electronics, you can build a simple DC circuit breakers with Zener diodes and very advanced ones with many active components to do complicated control over circuits behavior.

Friday 12 December 2014

Longevity

If you check a dictionary for the meaning of the word "longevity" you will see:

longevity:  noun  \län-ˈje-və-tē, lȯn-\ 
the fact of living for many years, the length of life, the length of time that something or someone lasts or continues

Ripped 60-Year-Old Bodybuilder
A familiar story 
After completing the software, doing many tests and giving a final demo to the user, fixing and testing again and again. It comes the time to give the software to the user and have it work in real world. Three important things may makes user unhappy:

  • Finding some bugs
  • Wishing to have some new features or changes
  • Crashing at the first days of working

These things happens and none of them is our concern, you usually fix them in a short period of time. The problem is when software works for long period of time, say months, years without restarting usually some other strange things happens, like:

Wednesday 10 December 2014

Software development is like doing art

I think the culture, the personality and so many other aspects of the people working on a software do have an effect on any parts of the software development cycles. In fact, it is not only a software but any other things human builds or invents or creates somehow has the personality influence and signs  of the builder, inventor or creator.

For example, when you get familiar with the way a famous painter paints, you can guess if a specific painting belongs to him or not because you know they way he/she thinks or works. Or in music you can see the different way of creating master pieces from two different composers in the same era. Compare the Chopin's piano work with Beethoven's in the following the first is one of the Chopin's nocturnes and shows the feelings of this composer at the time of composition:

Monday 8 December 2014

Drawing can help clarifying ambiguities

I was thinking of the way ancient people used to write, using graphical symbols as glyphs. The thing which usually comes in mind is Egyptian hieroglyphics. The difference between our modern language and the Egyptian's is that our alphabets are just symbols for sounding while for them each  symbol has had a meaning. When you see a picture of a man worshipping the sun, you can faster understand what this picture means rather than reading a line that says what this man is doing.

Our mind doesn't like to (or can't) pay attention to the details easily, you have to force it to get focused. This is why we can read words have a typo, especially those had correct start and end, we may even don't understand they have spelling errors. Do you think that the brain is that fast when you pass the streets it scans any people, cars, and ... finds out the shape of them. I don't think so, it has a history of how a human or car looks like, and just by discovering some signs assumes that this is a car and that is a pedestrian. Just think about this example, when you seat in a car, looking out the window how fast you brain should be to process all the things you see in detail?

Sunday 7 December 2014

UI comparison

Couple of days ago I went to a music store for the first time in Canada with one of my friends. I never have been in such a place here. What got my attention was the different look of the following stage pianos from UI perspective. These are two models of Roland and Korg stage pianos, both more or less at same price. See the difference between these two at the pictures.


Korg SV1

If you take a close look to the Korg, the buttons, nubs and ... all looks like vintage electronic devices, super easy to use for everybody. There are no LCD screen or LED and you have all you need to access at the same time in front of yourself. (It somehow reminds me plane dashboards.)

Saturday 6 December 2014

Can we overcome the software ambiguities?

Ambiguities are almost everywhere, sometimes they have no harm at all, sofa, couch, love-seat ... whatever don't harm anyone, sometimes it doesn't harm but makes confusion, like when a girl says to her boyfriend "let's go out and have some special dinner tonight". The poor guy gives her a special 200 dollar dinner as he thinks, but after the dinner she says "It was the worst dinner I ever had!" The problem is "special dinner" doesn't mean same for them. Similar things happen every day in our line of business too, "You have to develop a stunning user interface!" And when we build the user interface it has much ambiguity, rather than not being what the owner has asked for. (We will talk about the UI ambiguities later)

Development cycle adds more ambiguity to a system.
But how human make the ambiguities clear? Suppose you have brought an idea or have built something like a program, or ... The thing with a creature or phenomenon that has evolution path is that every step it goes forward the ambiguity increases.

Either you want to clarify the previous ambiguities or add some new features you make the thing more complex.

For example, there is an ambiguous word in a language and you want to make it clear, you have to add some similar words with minor differences. Do you think all people can learn these and use them in proper ways? The idea for language is much more complicated because people play with language. I always think the people who are responsible for updating dictionaries can do nothing to prevent this, people in the street bring many awkward words in the language and make them public and these poor dictionary guys should find out a way to put them in the dictionary or accept them as part of the language.

Friday 5 December 2014

Ambiguity in languages, sciences, software, ...

Merriam-Webster online dictionary defines ambiguity as "something that does not have a single clear meaning". I don't want to talk about ambiguity itself now, just want to open a discussion around the reason why we human do have ambiguity in anything we develop at all.

Every human speaking language has ambiguity and many obscure words, in English for example (which I'm trying to learn and this is the main reason of this post) check the followings:
  • What the is the difference between "dull" and "pull" that makes pronounce them "dəl" and "po͝ol"!
  • Why "right" & "wright" have similar pronunciation? or "buy" & "by", "cell" & "sell", ... 
  • Or "fine" with different meanings like "very thin" or "best quality", "excellent", ... (these are some of its meanings if we consider it as an adjective)
  • ...
You know better than me how many of these ambiguities and obscures we can find in any human languages, these were just some words there are many more in grammar rules and ... Are these ambiguities only exist in human developed speaking languages? or we face such problems in other developments too?

Thursday 4 December 2014

Do things in the right place and at the right time

Suppose you have just 25% fuel and want to go to a city which you just know it takes an hour or two of driving from your home. You know there is two gas stations on the road, one near your city and the other near the target city. In which one of them are you going to stop and fill up the tank?

You probably go for the nearest gas station then drive calm toward the destination. Even if something unusual happens you still have another gas station in the road. This is what we usually do. But why we don't do the same when we write code, design algorithms or software?

How many times have you experienced the "not enough free disk space", "disk full", ... after a while the operating system starts to copy files! I always wonder why some operating systems don't check the size of the file or files being copied to the target disk and the required free space before starting the copy process.

Wednesday 3 December 2014

Using positive feedback in software

There is something like a positive feedback loop in society panic. Someone says something horrible to a small group of people, they all panic and tell the story to their friends and relatives and each of them does the same ... then suddenly the whole society panics. Another example which seems have positive feedback in its nature is nuclear fusion, they way the sun generates energy or the atomic bomb works which even Einstein had been underestimated it. Big bang itself has had some positive feedback loop in its nature.

The above examples show that positive feedback naturally likes to spread or increase something as fast as possible, does this feature have any usage in software? Sure it does, let us see an example.

Positive feedback example
Have you ever worked with systems which have many connected online users (or any other processes) and because of a software upgrade, power outage, maintenance or ... you need to restart the system. In this situations, we usually can't instantly connect all the users to the system.

Tuesday 2 December 2014

Using negative feedback to stabilize software - 2

OK, now is the time to see how negative feedback makes a system stable. We saw in the previous post that the system doesn't know under how much load is going to be, so there must be some mechanism for increasing or decreasing the calculation power. If we assume the whole system is running as a single binary we can have some worker classes, if the system works as some separate binaries we can have worker binaries or even worker machines. They all need the same feedback mechanism, here we talk generally about this mechanism.

Using feedback loops to make the software ecosystem stable.
Look at the diagram and compare it with the one we had in the previous post. As you see I've tried to clearly show the feedback loop.

Note that we already assumed that the line queue is a thread safe or multi-access queue. The feedback mechanism for read process reads the LQ size in fix intervals and just sends the result to read process, which also has the responsibility of controlling feedback loop. Here the read process gets the LQ size and if it reaches to some critical point it stops reading. This mechanism just prevents the blind reading files and putting lines in the queue. So the code for the sensor and control section of feedback loop can be something like this which must be executed in a separate thread or binary repeatedly like each second.

Using negative feedback to stabilize software - 1

What does software stabilizing mean? We talked about stability patterns in software ecosystem before and saw that both in multi binary software systems integration (ecosystem) or in a complex modular software we need to take care of how different binaries or modules work together. Wrong behavior of one binary or module may lead to a disaster in the whole system. In fact, most of the time we need to consider some negative feedback loop to prevent propagating faults or letting the ecosystem goes to some unknown situation. The loop can be some part of the binaries or it can be an external binary itself talking to other binaries.

I remind you that we need feedback loops in a complex system in which we can't exactly be aware of what components are doing so instead of an exact following of what they are doing we just check and control the system's outputs and try to adjust the components behavior to keep the system up and running.

Monday 1 December 2014

Feedback

Feedback is one of those topics I always enjoy reading or studying about it and, in fact, it helps a system to make a correct decision most of the time. What I mean is we humans can not making any decision before gathering information on what we've already done. Feedback concept is exactly the same, get a sample of output (what you've already done) and bring it to the system as an input and then process it with other inputs and continue this cycle.

Feedback helps a system to adjust its process to get the required results, especially when a system gets complicated enough, the control section can't keep track of the entire internal processes (indexes), at this situation the feedback helps the control section to keep the system up and running.

Feedback concept
In the diagram, you see the process module which operates on input and feedback. So the process module has the input and also an idea of what output currently is. So this process can easily adjust itself to do exactly what it has to do. On the other hand, the feedback module directly senses the output and prepares a signal or required data for the process module and sends it to this module. This loop in which feedback module gets output sample sends it to process module and ... is called "feedback loop".