Solution - 'gem install mysql2' Fails

Today I spent some good hours to debug the issues while installing 'mysql2' gem. It was failing again and again stating that 'libmysql' not found (even after applying the solution I mentioned in previous blog). To share, I am mentioning all the steps from previous blog with today findings.

  1. Install 'MySQL' on your machine. Choose the installation depending upon your machine architecture i.e. 32 or 64 bits
  2. Have devkit installed on your machine. It can be download from 'http://rubyinstaller.org/downloads/'
    1. Download right installer for your machine i.e. 32 or 64 bits
  3. Install devkit by following instructions at 'https://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
  4. Go to <MySQL installation dir>/lib and copy the 'libmysql.dll' to <ruby installation dir>/bin
  5. Try running gem install mysql or mysql2
  6. It should install now. However, if you still face problem, follow steps given below
  7. Try specifying the --with-mysql-lib and --with-mysql-include options with gem command by specifying the mysql installation respective directories
  8. If it still fails to load the 'libmysql', ensure that you don't have space in the path of MySQL installation directory. 
  9. Simple solution could be to copy the lib and include folders to a simple path like C:/mysql and specify the path of include and lib folder with gem command using --with-mysql-lib and -include options
  10. Hopefully it should resolve the issue
Hope it will help. 

What is Functional Programming

Today we shall discuss about Functional Programming in brief. Functional Programming is a different paradigm than Imperative style programming. Imperative programming includes change in states with functions, however, Functional programming advocates functions without any side effect, i.e. no effect on any of the state. This is a big difference in programming approach with many other implementation level differences.

Let us understand bit in detail, what is Functional Programming and how is that different than Imperative Programming.

For development using Java like language, we mostly follow Imperative style programming. Where a Class like data structure contains some state or represents state. Functions are implemented to work on this state. Functions make changes in states based on current state or passed parameters. End result is, once functions are executed, the shared states may be changed.

Functional Programming supports the concept of Pure functions. It states that function implementation should not have any side effects. It means that functions will not modify any state. These will only act on the parameters and will return the result. No state will be changed anywhere else. This also means that does not matter, how many times, you call these functions; if parameters are same then result will always be same.  This is one of the biggest difference in approach.

Let us discuss, how does this difference matter. With above understanding for Imperative style programming, if we want to support concurrent execution, we can apply concurrent programming concepts using threads and locks to safeguard the simultaneous update of states by multiple threads. We use different kind of locks, synchronized blocks etc to support the concurrent programming. Although with mature API support like java.util.concurrent, concurrent programming is getting much simpler now; but still it needs lot of care and knowledge to implement a perfect program. Moreover, we understand many scenarios only when program actually runs on multiple processors and scenarios changed with number of concurrent streams. So testing the concurrent programs is hard.

However, what if there is no shared state to modify through functions like in 'Functional Programming'. Then there is nothing to safeguard in concurrent or parallel processing. There is no overhead of locks and hence the concurrent scenarios testing. Results will always be same from a function irrespective of whether it is being executed by one or multiple threads by multiple processors. Functions just act on the passed parameters and return the result. Isn't that a big relief. Certainly, it can make parallel programming a lot more easier. Programmers can focus on business logic implementation instead of managing the concurrent programming scenarios. Further, it is entirely feasible and easy to process different functions in parallel on parallel processing units. Different implementation functions can be submitted to different processors. As there is no shared state to access or modify, so there is nothing for the processors to compete for. These can work parallel in harmony. So with proper designing, results can be utilized later from different processing units to form the final result.

From above discussion, it would be becoming clearer that Functional Programming is having edge when it comes to parallel processing and make it comparatively very easy to manage. This is one of the major difference in programming style and the benefits. That is why Functional Programming languages like Scala are getting popular. Why not, demand is for parallel processing after all.

There are many other differences also. Like, Functional Programming supports the concept of 'First Class' and 'Higher Order functions'. 'First Class' functions are, which can be presented in a program anywhere like any other first class member can present, for example anywhere like a Number type member, or as parameter or return value of a function. High order functions are, which can take other functions as parameter or can return these as return value.

We shall discuss  more for these implementation level differences and other concepts with coming articles.