June 19, 2018

What I like about go generate

I like when a project that uses it, compiles and runs before and after go generate. That is a powerful concept, in the example you have constants shown as numbers when they are printed, but after go generate the stringer generated prints the names of that constants.

Go generate is like having make instructions inside your code. Of course you need a lot of imagination to think that a go generate comment is equivalent to  a makefile instruction.

Besides there is not dependency control at all. Like when run depends on build and stuff like that. But it allows you to run commands using the command go generate.

Anything else are just helper functions

Well I am over simplifying here, the fact that go comes with packages to parse, modified and write updated code is very nice but that part could be done with any other tools( like antlr or lex and yacc).

In the last project

It was decided to have a config to describe what to take from a HTTP request (get something from query, header or cookie), then we describe functions that receive that data and returns other data and finally we specified which data need to be stored and how.

The POC

So the first implementation was a Proof of concept in which show how to do all the process using a config file. In the past a new service was created to do the same work and there was 4 or 8 of them in production. So the POC shows that it would be easier to port them to this new service just by adding some simple configurations.

The first implementation

The first implementation was though to cover any case possible. It will be super generic code. The idea was just implement what is needed but left all the indirections in place so it would be easy to just implement other parts. 

This didn't finish good, because time bugdet issues. We finish with a room with foundations of a cathedral that had space for the future buttress that maybe would not be required. There was a communication problem because there was time.

The second implementation

So it starts as a POC but it was so simple that it stays and now is running in production. Basically now that the config was well specified, A generator was created to output http.Handlers base on configurations.

The service runs without go generate (not handlers registered). But after it runs, it register the handlers.

All the indirections were removed. Thanks that I received an advice from someone that I respect, he recommend just make something that works and test it, refine and test it and so on.

My life were never more easy I was preparing a service for the future but the future is uncertain.  The only thing we can do is fail fast (Implement and receive feedback as soon as possible.). 

Which is now my new motto.

June 8, 2018

How I became a golang programmer

Tldr: by casualty

Well that's it, I was programming in python for 4 years, in a great team when there was a project to try to port one of our services in go. A friend and I started the port effort.

In parallel there was other team doing the same but in Scala. And it was kind of a competition.

The mistakes

I wanted to port all the functionality. For a POC I think is not good to implement all the features. Because you have like a month to finish your port, and you are trying to implement 5 years changes.

Worse I took function by function and I tried to implement them in go. Today I know that I should focus only in produce a  "minimum viable product". Then extend it when needed.

The struggle

 It's difficult to switch your mind from a dynamic typed language like Python to other that is strong typed. The project was programmed in the language, which means that was using a lot of specific features it.

My approach to learn

I didn't really dedicate time to learn the language, I thought that I would just program and ask google how to do stuff but in go. Go by example was very cool resource but incomplete (now I think is complete, but at that time not)

That was a bad idea. Because my mind was so oriented to Python, that I didn't realize like in a spoken language sometimes there is not a direct translation.

The balance

After some time, I started to forget Python and my mind just switch to solutions with the tools that go have. I improved my fluidity. (I did the advent of code 2017 in go, that helped a lot). In other words the old advice is true. There is nothing better than practice, practice and practice.

And then when you kind of start to be intermediate in go, your old experience "kick in" and you start to think "hey I can do that in go with this" That experience was amazing.

Like a fractal

For me golang is like a fractal that looks very simple when you look it from far away. But oh boy! each time I have an interest I can dig in and I can't see the bottom. It is like a fractal each time you zoom in there is more content.

The past week I was interested to learn templates and go generates and wow, is just very cool what you can do with that. And I felt that I only saw the tip of the iceberg.

Go won

Well that was relative at the end, the go project was finished in a fraction of the time of the Scala team. (They were using play framework and during the time of the project a new version appears that change everything, the team wanted to jump in to the new changes. Sometimes the features stability of go is underestimated).

But

Scala was faster due the implementation of couchbase lib, I think with more time we could improve the performance. But the experiment end there.

The team continue working in python and I moved to other company as a go developer.