The one about sources for learning

Today’s post will be short, because I got sick lately so I had other things on my mind.
This is a short list on from where you can learn:

1. StackOverflow
I think the first position is self-explanatory, but I wanted to add something to it. Everyone knows that you can search for an answer to every question that comes to mind and that’s like the coolest thing ever. I think that you can learn a lot not only by searching for answers but by trying to answer questions that doesn’t have answers at the time. You can of course google the answer, but searching for an answer excluding stack overflow you can find gems and improve your research skills.

2. Official Documentation
Of course not every framework/library has any documentation, and most of them has it in pieces, but there are docs, that make my heart skip a beat. Getting to know new framework/library without their documentation is as hard as it gets, so if you are choosing new framework for your project – check documentation first and then make your choice.

3. Blogs
Well, maybe my blog is not a perfect example for it, but some of them are eye-openers. Let me toss you some examples just from the back of my head:
stuffwithstuff (too bad it is not up to date, because it is a great piece of work)
martinfowler PS I’m secretly in love with this guy, this is how smart he is. This one is good for diving into some buzzwords you hear now and then.

4. Books
Well, not the programming language books, because things are changing so fast, that sometimes it can be outdated before it meets the bookstores. But programming concepts aren’t changing that fast.
I didn’t read a lot of computer science books, but I can recommend at least two of them:
Code. The hidden Language of of Computer Hardware and Software. This book goes from explaining electricity to computer program and the journey between is great to read.
Software Craftsmanship It gave me big boost to my motivation, and explained what it is to be good developer.

5. Community
You are working as junior developer, and you want to know more about some specific topic? Have courage to ask and start a discussion at work.
You are unemployed and you have no friends with programming background? Maybe look for a group in your city, dedicated to some language or area of expertise. If there are none, start one. Start small, with e.g. mailing list, then try to meet for a beer/soda. If you are looking for people there is big possibility that other people are looking too.

If you can think of some other source, or you want to recommend me a blog or a book, leave a comment or send me direct message using form on the left side of my site.

The one about development environment

It’s time to do a side project, because my github account has been empty for too long. There is this idea that’s with me for quite some time. I don’t like to eat alone at the restaurant, but there are times when I don’t have a choice if I want to eat out. So I want to make web app, that makes it easy to find company to eat together at some place. I call it “Companeat

My technology stack will be:

  • Sails.js framework, because I want to write back-end in node.js
  • MongoDB database because I like how easy it is to implement with sails.js.
  • Front-end choice is still open for consideration. I am thinking Angular4 or React/Redux. This is new for me, so I am not really sure what are the upsides and downsides of both.
  • Docker, because I like things to be sandboxed and easy to manage.

For now I got my development environment ready for work. You can check how it looks on my github page here. This is how my workflow looked like (I won’t copy content of my files, because you can check them on github):

At first I created a project on github and cloned it. Then, inside project folder I made a Dockerfile with path: ./docker/dev/Dockerfile, and what I wanted to achieve was to have latest node, netcat installed, sails.js framework installed globally. Moreover I wanted default sails.js port to be exposed for other potential services.

At the end I wanted node modules to be installed and sails to be lifted (app to be started) at the end of container creation. This was the first tricky part.

I created shell executable file inside ./docker/dev/ path called with commands for installing node modules, creating log files and lifting the application. I copied the file inside container and executed (from the Dockerfile command), so when the container is ready it runs and it does what we told it to be done.

Now I had to write docker-compose.yml because I like to use docker-compose a lot. To be short: Every service is a stand-alone container, but when they are defined in one docker-compose they are linked to each other in a some sort of virtual network.

First service I named backend, gave it Dockerfile path so it knows the source from where it needs to be built. I made host (my computer) port 7331 to be connected to docker port 1337 (sails.js default port). I defined database volume to be shared between backend and mongo_db containers and gave my containers
-it flags as in docker -it container_name bash.

Second service is my database service. It is built from existing mongo image, that I found on docker hub. As I told I gave it shared volume with backend. The configuration of this service can change as the application progresses, but for now it’s hard to tell how to configure my database.

There will be probably third service with my front-end application side, but for now I will focus mostly on doing the back-end job, just a heads up so you won’t feel confused.

When you try to start a project yourself with nothing but my Dockerfile, and docker-compose.yml files, you carefree type docker-compose up -d to start your containers and DUM-DUM-DUUUM… you will end up with error message, one like this: 

This is because you are trying to lift an application, that hasn’t been created yet. From sails.js documentation you can read that you need to create new project before you try to lift it. This is the second tricky part. You need to go to your container. In my example it would be docker exec -ti backend bash* and from there you need to create your project. With my configuration the easiest way is to go to your root path (while still inside container of course) cd / and override /project folder with sails new project command. Remember that it needs to be empty! (You can see how I did that on the screenshot above). After that you can exit your container and you need to rebuild your container. The easiest way is to docker-compose up -d --build After that you should have your application up and running. You can check it at least both ways. First you can docker logs -f backend so you can see:

or you can go to http://localhost:7331/ and if you see this: 

you can start building your web application.

My article may be a little chaotic, I am still making my first steps in the blogosphere, so any feedback will be appreciated. Please comment, and if in any doubt or you need help with your programming struggles PM me. We can struggle together so you’ll feel less lonely 😉


*-i, –interactive=false Keep STDIN open even if not attached
-t, –tty=false Allocate a pseudo-TTY

The one about queue

Lately I’ve been messing around with RabbitMQ quite a lot. Basically it is a tool, that can make messaging between services reliable. Key word in the latter is “can”, because it doesn’t have to. As default you probably have transient messages on non-durable queue. Well, it’s allright if you only use it to make consuming those messages “neat”, but most of the time you want to use queue to make your messages persistent. But it’s not as easy as I thought it would be.

Firstly, you need to change all the settings for your queues in all the services that are using it. You can’t just make it durable from within rabbitmq itself, because it would throw an error, that incoming message is for non-durable queue and this particular message belongs to durable one with the same name.

Secondly, durable queue is not the only thing that is needed for messages to be persistent. You have to set them to be persistent, because by default they are transient and if queue service gets to be restarted, transient messages won’t be recovered.

Third and in my opinion toughest thing to be dealt with:
Let’s say that you remembered about making your queue durable and all your messages persistent. What will happen if some corrupted message gets sent to consumer? It will make an infinite loop of errors, because every time restart happens it won’t make the problem disappear. So you need to make sure you have a handler for messages that can’t be acknowledged by consumer.

That’s how I got to know about “Dead letter queue”. After you implement it basically the problem boils down to make your queue aware of this mischievous situation, so it can send corrupted message to the dead letter queue, that exists (afaik) only for debugging purposes. That way your queue gets “unlocked”, and your consumer services are working as a charm. So, if somehow my past self gets to read this blog, just google this one, when you will be thinking about how to make it all working after queue restarts 😉

The one with the frameworks

I was thinking a lot about frameworks in general lately. Framework is this set of tools, that helps programmer to just focus on business logic instead of language. What is the difference between framework and library then? I heard on one polish podcast (listen) a nice quote that I’ll paraphrase – “Framework is what calls you, You are the one, who calls a library”. Given this definition one can conclude that often you have to give up your flexibility to speed up programming your application when you choose to pick up framework. There are people much smarter than me, that are arguing about when to use frameworks so I want to focus on the other problem – junior level one. From beginners perspective, when you are learning a programming language it’s really hard to tell when you should start to learn a framework.

Let me give you an example from my recent experience.

Because of one microservice that I had to add functionality into, I had to dive into Ruby language, because it was written in Ruby on Rails (RoR) framework. With only a glimpse of knowledge about the language itself and no prior experience with RoR I had to use websockets (that I knew nothing about) for my feature, so three solutions came to my mind:

– find websockets gem with good documentation and just use it at the same time making my already huge application even bigger

– create websocket functionality with vanilla ruby. To do it I would need to be reeeaaally comfortable with Ruby language (minuses: it will take a long time to make it work and I would go against the rule to not reinvent the wheel)

– use a tool that is inside the framework that the application is already in (Active Cable).

I was asking myself questions. How to dive into it? Should I start with basics of language just to know what I’m looking at and to see the difference between language and its framework, or should I just pick up RoR first and guess language syntax from the usage?

The best approach for me was to just do what you have to do to achieve a goal in a fastest possible way. I researched and planned what I need to code, to make it work, so rather than doing language tutorial or going through full documentation on framework, I just googled how others implemented what I’m trying to do in ruby. Most people used Active Cable, so why I shouldn’t? But hey – It’s not that I didn’t have to learn vanilla Ruby at all, while going through all those framework built-in methods.

I found out that diving into a language with a framework from day one has one big merit – you will do a lot of things the way it is done in commercial projects and as a side effect you will slowly gain confidence in language you’re using, because after all you need to fill the framework with business logic to make application whole.


The one with how should I start

Note to myself from the past: Don’t let yourself sink in all those threads about which programming language is best to start. It’s a dead end. Just grab one and stick to it for few months at least.

I lost a great amount of time back when I was teenager, because I was doing all kinds of tutorials that brought me to the worst spot. I was thinking “so, with those if statements and for loops you can build a whole application or a game? How? I must have missed something”. So I tried another tutorial with hope that it will bring me closer to reveal the mystery how to build something big with those tiny little bricks.

Now – if I could go back in time I would just pick something I want to make. Let’s say I want to build an audio player. I would open text editor, make a step by step plan and just google everything, but one step at a time. For example:

  1. how to create a window in X language
  2. how to make buttons in window in X language
  3. file picker in X language
  4. how to link buttons with file picker in X language
  5. how to play music with X language

and so on. Of course sometimes you need to rephrase questions multiple times before you find an answer on Stack Overflow or some blog, but you will get there. Just be patient, because you will read a lot more than you write at the beginning. At least that’s what I do most of the time.

And yeah – making each step working is hell of a lot satisfaction and joy. Don’t make errors let you down. Make yourself enjoy it.