My thoughhts about why Haskell is not popular

Despite Haskell programming language is not young language, it has a really great and helpful community, it has big amount of libraries, unfortunately Haskell is not popular programming language. I'm not against this programming language, opposite, haskell's unpopularity makes me sad. I will not write about haskell popularity in industry, I'll try to explain my thoughts about "Why Haskell is not popular" not as Haskell expert, not as professional Haskell developer (i don't get payment for Haskell programming), but from position of usual developer who started to learn/experiment with Haskell some months ago and already don't afraid monads :). I can't So I will try to explain my opinion about Why Haskell is not popular in this post.

Reader monad understanding

Some time ago I started to learn Haskell. It's not the first time (and event not second) that I started to learn this language. Every time I met different problems with understanding different abstractions like a Monads, Arrows, Monad Transformers and etc... I think that I'm not alone with this :) But, in this time, I decided not to throw up training until I can not say: yes I can write in Haskell without pain. I started (as every time i did it) with the most popular book (for newbies) about Haskell - Learn You a Haskell and stopped at Reader monad. Spending some time I understand it (at least I think that I understand :)) and decided to share my understanding of this monad for the same newbie haskellers as me.



Simple bash script for setting up Golang environment

Some time ago, when i just started to use golang, golang project's structure organizing, this magic $GOPATH and other things was strange for me. No, it wasn't bad, just nothing like i have used before. It's simple to understand with erlang, at least for the start, you must just install erlang, to create project, to add rebar with deps and that's all. Something like this with nodejs project bootstraping. There are clear and intuitive package managers which downloads project's dependencies and puts it to the project dir.

Another case with Golang && go get. They are very cool, but not for the first look. You read it's documentation, execute all instructions and than get something like go can't find `projectname` in $GOPATH and $GOROOT. So i created simple bash script which will help you to set up golang environment from the scratch. It makes 3 simple things:
  • Creates directories for Golang compiler and your future projects
  • Downloads golang compiler and builds it
  • Puts golang/bin/ and directory with your projects to $GOPATH
That's all. Very simple. Of course this script is not for a professional golang developers. It's primarily for two points:
  • For newbie gophers
  • For fast setting up golang environment
Here is the script:


Just run this script and pass directory path where will be golang and projects, and your github username. It will create directories for golang and you project. After it you can start to coding.

That's all. If you will have any questions/suggestions/problems with this script write me a comment.

Happy coding :)

Implementing tcp socket acceptor pool with golang

So, as maybe some of you knows that i have started to use Golang programming language for my pet projects and since to solve "Project Euler" tasks is very useful deal, but very boring in the same time, i decided to create something more closer to real life. I decided to write XMPP server in golang and in this post i will tell about one part of this server - netpool/tcp library. netpool/tcp - is a tcp based socket acceptor pool. The idea is very simple, you will launch TCP listener which will launch many acceptors besides one, in this way you no need to spend time for creating new connection acceptor.

First of all let's create new tcp package and import all libraries which will we need in this project:

Now let's define types which we will need in our acceptor pool:

Let's go by order. First enumeration defines strategies when connection listener handles more connections than we define.

  • RefuseConnection - listener will refuse connections after connections amount overflow;
  • IncreaseConnection - listener will start yet another 50 acceptors.
Next is simpe constant value which defines how many acceptors need to start after connections amount overflow.

Next is ListenerStruct structure. It is a main structure which we will pass to StartListener function for launching new listener. It has following fields:

  • Accnb - number of acceptors;
  • Port - connection port;
  • Handler - function with 2 parameters: input string and conn tcp.Connection. It will calls when client send something to server;
  • Lc - listener channel, it needs for communicating with listener;
  • OverFlowStrategy - It can be 0 || 1, see note about overflow strategies;
  • Ssl - it is a map, we need to use it if we want to use ssl. Just create map with 2 string keys: pam and key. Next if will show how to use it.
Also it has API which consists now only from one function - StopListener without any arguments, you can stop current connection with it.

Next is a Connection structure. We have it every time as second parameter in connection handler function. It has simple API for manipulating with connection:

  • Connection.Close - close current connection;
  • Connection.Send  - send response.
So, now web have all types which we will use in this library. Now proceed to implementation. All API of netpool/tcp consists only from one function:

It's a main function of this library and it launches new tcp listener and some acceptors. Let's see how it implemented.

First of all it defines some variables like: acceptorCounter for count acceptors, checks is it connection over SSL or not and launches listener which depends on this:

Next it creates 2 channels:

  • connectionCounter - channel for communicating between acceptor goroutines and listener. If connection was closed it sends message to listener and listener decrease connection numbers, if new connection was accepted it increase connection number;
  • closeConnection - channel for commuicating between listener and acceptor for closing current connection.
and starts acceptors:

After this listener waits for messages from another goroutines for closing current listener, closing connection, connection removed/created and etc...:

So what about acceptors... It's pretty simple as a listener implementation, it starts from accepting new connection and waits for incoming messages from connected client. If there are any incoming data from client it call handler function and pass input data and  Connection structure to it:

After this it as a listener checks incoming message from other goroutines, to stop connection and etc...

So it's end. As we can saw concurrency is a pretty simple with Golang.

As i said in previous post i'm not a golang super-hacker, if you will have any recommendations for my golang code or you want to take part in XMPP server developing with golang i will be very pleased to hear it, write me in comment or ping me in twitter.. Also i made this library primarily for future extd XMPP server but i tried to make it generic so i think it can be useful not only for me. Links:

Why i like Golang

Some time ago i have started to learn/use GoLang programming language from Google. I'm using it something about one month, maybe little more and i cannot call be a advanced GoLang hacker, but i wrote and continue to write some small projects like:
and thinking about to use it in some more serious projects. Yes one month or something about this not must time, but i have got some opinions about Go for this time and will try to describe some of it in this post and explain why i like this programming language.

Easy to start


Yes, Go is a really easy to start programming language. It doesn't mean that you will create production ready software with it, but you can start to write your "Hello World"-like program through 5-10 minutes. All of you need is only to go through some little stepts:
  1. Go to the official golang site's download page and get golang distributive for your platform
  2. Install it on your workstation
  3. Set up your working environment with $GOPATH
  4. Create working directory with mkdir -p $GOPATH/src/github.com/user and that's all, you can create directory for your first project.
The second Easy-to-Start factor is existence of Golang book, I think it is the best start point for the golang newbies.

Libraries and community


GoLang is young language, appeared in 2009. But despite this it has already big community:
  • golang-nuts - official golang mail listing where you can post your question and get answer. Or just get announces about new versions of golang software;
  • Go+ - Google+ Golang community;
  • @golang - Golang in twitter;
  • #go-nuts at irc.freenode.net - one of my favorite way to talk with gophers;
  • go at stackoverflow - GoLang Q/A.
As i said previously Golang is a really young programming language, but it has big community, yes not so big as java or node.js, but 3K followers for go tag at stackoverflow and 5.3K questsions [Bigger than my favorite erlang :)].

Package management


Golang has a very powerful go command line util and there is my and i think not only my favorite command:
go get ...
This command installs remote packages from version control like Github, BitBucket and etc...

Some recomendations for start to use it:


Concurrency model


Primarily i am erlang developer and it was important to me support of concurent programming in GoLang. And it met my expectations.

go foo();

And that's all, foo function runs concurently.

Defer


I think we are all forget to clean resources in our program :) GoLang provides awesome mechanism to avoid this something like this:

Conclusion


So, it was part of GoLang related thinks which i had glimpsed and liked for the last month. I'm very interesting also how do you using GoLang at work or for yourself, what do you like or don't like in it, write me a comment.

Links