Docker here docker there docker everywhere – Getting started with docker in .NET with F#

If you are in IT world, you surely heard or read about docker. There was / is a huge hype about this technology. It looks like this one might actually survive the initial ‘It’s awesome phase’. I was looking for some info about docker. It was confusing to get to know what docker really is. Too much marketing buzz words everywhere. In this post I will sum up all my notes about how to start with docker in .NET and F#. It will be like learning journey that might end as a simple tutorial on where to start.

Docker ? 

My first encounter with docker was through simple tutorial . It’s a online interactive shell emulation that lets you execute some of the commands and get the basics of docker. Sadly, after finishing it you are left out with more questions than answers.

You can start by reading official site docs. The most important thing to note is that docker is a kind of a runtime that enables you to create images that you can run on top of it.This concept is just like Virtual Machines, there are however differences. Docker is not creating full complete OS instance, instead it is creating lightweight containers that do share the kernel but are still isolated and separated from each other more. This process is more efficient both in time and memory space. It is easier and faster to create smaller containers instead of full VM’s. There are however some cons, you won’t get full isolation but who really needs that ? Other problem is … Windows is currently not supporting those small containers, we can only run Unix beacuse docker is using ‘Linux Containers‘. You can still run docker on Windows, but you can’t create windows images. Microsoft promised to provide this support in new Win version.

Running Docker on Windows

To start using docker on windows go to – https://docs.docker.com/installation/windows/. Boot2Docker is all you need to get started. This tool will install VirtualBox, configure small Unix VM that you will use docker from and there is also a nice utility tool that will connect you to your virtual machine.

Boot2Docker is a little unstable, while testing I encountered one issue with never ending docker loading. It looks like there are some with issues – https://forums.docker.com/t/boot2docker-hangs-then-crashes/401 . I had to reinstall Boot2Docker multiple times to get it working.

F# + docker

I want to create my first simple image that I will be able to use and write some F# code, compile and run it.There are existing images with F# that you can just download and start using, but in order to learn I want to create my own image. In order to do this I will define a docker file with set of instructions that define how to construct an image. Those instructions are stored in DockerFile without extensions or dots. Thankfully Boot2Docker does have vi on board so I can use it to create this file.

1. touch DockerFile – will create me a file

First instruction would be to get me a Unix distro that I will run everything on top off.

2. To build image

Yey it works, behind the scenes it gets the debian DockerFile and goes from instruction to instruction creating a debian runtime. I could possibly write my own ‘debian’ image, but that would involve me learning about how to build Unix distro. Instead of that I can just point to external image and build on top of it. That is one of the beautiful things about docker. You can mix / match different images and build more complex ones using the basic ones.

3. In order to compile F# app i will need mono and fsharp compiler

-y – “Always Yes” so if there is any prompt in ‘apt-get’ installer just say yes
-q – Quiet – makes the log less verbose

4. Building image

I got some errors from apt-get missing packages and the logs says to add – ‘apt-get update’. This is supposed to update the ‘apt-get’ list of packages.

‘sudo docker build’ – and couple minutes later you should have a nice image with debian + mono + fsharp.

5. Switching to more specialized image 

Sadly in my case I got lot of errors while downloading ‘mono-complete’. Instead of building mono on my own, I have decided to change the base image and use some Unix distro with mono on board. Running ‘docker search mono’. Gave me a list of all the potential images, I decided to use ‘mono’.

Notice that I installing vim, I need some basic text editor to create first F# hello world app.

6. What now ? - Starting container
I have base image, there is no container yet. What is a container you may ask ? Container is a running instance of imageTo start interacting with container, you need to start some app on it. Most basic one is interactive shell, that will also enable me to work on top of container

7. Testing out F#

Lets see if fsharp is here fsharpi should start F# interactive.

Yey, it’s here. To exit just type quit#;;

8.  Creating folder + hello world source file

I need folder and hello.fsx file

9. Hello World App

10. Compiling app

11. Running Hello World App

Uff, done. That wasn’t that hard. Now, you might ask so what ? You just compiled Hello World app … I can do this on my local machine, yep but this brief tutorial is just a starting point, I have started exploring docker, because, I want to play with akka.net and F#. In next posts I will post more things about how to use docker to create multiple akka actors and how to write some simple distributed app. That will be fun, cause it is a new world for me. Docker is more complicated than that. It is quite sophisticated and you can create complex images with many dependencies

 

edit:
You can use vagrant with docker
Docker Misconceptions
Pawel Sawicz just send me a nice link with some anty-hype opinion about docker
Another nice link with some docker problems + a solution 

Fuel your personal growth with feedback

TL;DR; Feedback is crucial for your career. Be proactive, get out of your closet and ask for it!

Last week, I have read Michal Sliwon post “A recipe for a happy software development team”. It’s a great read with some eye opening thoughts. I encourage you to read it.

One of the things that stood out for me, is how Michal and his team use feedback. As chance would have it, 2 weeks ago I asked for a feedback in my Company. It has been a year, since I joined the team. Surely, that’s enough time to tell me if I am a good team player and problem solver. In a year, you can make just enough mistakes, and good stuff too, to show who you are.

Before I started in IT, all the feedback I got were ‘grades’ at University / School. Grades are fine if you need a system for fast evaluation of multiple people but it always felt naive and ‘not enough’. How can you evaluate someone based on simple predefined grade system ? How can you help someone ‘find the way’ using this system ? I always imagined that on Uni, I would have some 1-on-1 meetings with teachers or at-least someone will try to mentor me. Nope, education system is like a factory. You get in, you get out and in the end you enter the dangerous world of grown ups, not knowing the importance of giving and receiving ‘Feedback’. Some people are even expecting similar grade systems in workplace. You know do this and that and you will be there ? There are some companies that are very transparent in their ‘promotion’ system ( Buffer, Fog Creek Software ). That’s just compensation systems, even with it there is still place for proper feedback process. Btw, I am all into transparent workplaces, this is the way to go. Lack of feedback greatly lowers your chances and negatively affects your growth. By growth, I don’t only mean career related things but also your growth as a human being.

In my first company, I was quite keen to receive my first feedback. Being a Junior Dev felt like a little kid in a maze, not knowing really what is happening around you. Feedback was important to me, I was waiting for it. Now, imagine my surprise when I got no feedback at all. And so you work without any guidance, trying to figure out on your own what kind of ‘team-player’ you are. There was one message, company did not fire me so, “hey they have to be happy right” ? Wrong! Approach like that is similar to grading system, it’s not enough. What kind of lesson you can get from just knowing that you are good enough to stay at your company ? Probably none. Back then I was just a ‘kid’, having proactive attitude was something completely alien to me. I was hoping that my first manager, would be my guide in this dangerous world of all these grown-ups and their politics. Sadly it did not happen. I felt betrayed and started managing career on my own. Yeah you can do that to a certain degree, but it’s not the same. You can’t evaluate yourself. Your point of view is flawed. You know ego, ego, ego. There is also impostor syndrome which causes different anomalies and can affect the way you are thinking about the world. So in short you need feedback from someone else. Now, I was lucky, I found mentors in the community, in form of books, blogs, I have talked to people on twitter, facebook, meetups etc. but it would be a lot simpler if I would ask for feedback on my own. What’s the lesson here ? Being pro active is really crucial, no one will manage your career for you. Get out of your closet and ask for Feedback!

Why

So much talking about feedback and there was no why. Here it is.

1. IT is changing really fast, you can’t keep up with all these technologies. Ideally me and you, we would have a lot of time to research and explore various technologies, but yep time is a limited resource and we can’t do everything at once. But hey two heads are better than one. Having someone who could give you some feedback about various techs is really beneficial.

2. Technical expertise. You can’t be an expert in all of the technologies. Having someone, somewhere with experience in certain technology can save your time and money ( and hundreds of ‘F’ words for sure ).

3. To consider yourself as a mature person, you need to ‘nurture’ your personality. Yes, It is a hard, long process, you might not even see the changes. That’s where you need external feedback. Ideally someone close to you. Friend ? Team-mate ? Friend can influence you personal life while team-mate can pinpoint career related stuff. For instance if you are dreaming about becoming senior / tech lead or architect, ideally you would find someone in this position. Hist tips and suggestion will speed up your growth into that position.

4. Life is full of dangers and those dark caves that you don’t want to go in. Having a mentor and guide that could give you some feedback is really beneficial. Imagine how much time and effort you would save if someone would told you that some route in career is a waste of time.

5. Getting feedback is a great way to learn how to give feedback. This can lead to awesome opportunities to meet intelligent people. If you are a person who is pro active in giving feedback, there are people that will greatly appreciate that. In the end you can gain contacts, friends, new opportunities. We are a social creatures and building your personal network is one of the most important things in your career.

In next post, how and where to get feedback ?

Little fix. In next post, I will write about how to get feedback and where to look for it.

From 2014 into 2015 – tech plans

A lot has happened in the last year 2014.

  • I moved to London which was not that easy task. Moving abroad proofed more difficult than, I thought and those estate agents … I don’t want to start.
  • Started working for an awesome company JustGiving. I am glad and happy that, I can work with so many awesome people on projects that have an impact. It is really good to work for Tech4Good company.
  • Finally, I invested heavily into learning about functional programming.
  • Spent a lot of time organizing my TDD knowledge, couple of books + one nice workshop with Roy Osherove.
  • I did some talks in Polish / English dev groups.
  • Organized dotnetconf.pl with Pawel and Jakub.

What I want to do in 2015 ?

  • Again, functional programming all the way. This is the ‘thing’, I want to go for now and see what happens. It was really refreshing to learn about it and use it in some practical projects.
  • DDD, I need to gain more knowledge about it. It was always there, I have read blue book by EE but I think, I wasn’t mature enough to really grasp it. I have heard good things about Implementing DDD by VV, probably will start with this book.
  • Speaking activities, I need to do more speaking to learn from my mistakes and get better.
  • Artificial Intelligence, AI will be a great source of problems complex enough so that, I can use functional programming with it. I always wanted to start learning about AI, it is something that really interests me, apart from history and sci-fi. Will see what happens, I have already started last year by refreshing my knowledge from uni and gaining little ‘foothold’ in this broad and complex subject. You will see some posts about AI for sure.

F# and Nancy – beyond Hello World

I have been trying to find some examples on how to create a web app using F# with Nancy. Most of the tutorials on the web cover simple “Hello World!” app, only the basics. In this post, I want to go beyond “Hello World” and show real life examples.

F# and Nancy – Where to start ?

Most basic app “Hello World”, is simple.

Nancy will automatically load up the App class. To those familiar with Nancy on C# it looks almost the same. The only noticeable difference is the lambda function declaration, plus different syntax for inheritance. Also there is this weird smile face ‘:>’ at the end. This is just a up-casting operator. For some reason Get function has to return object. In F# you also use different syntax for list / array indexing. Instead of Get["/"], you need to use Get.["/"]

GET Examples

POST

To extract the parameters I had to cast the input param, which is of obj type, to Nancy.DynamicDictonary. It doesn’t look great but there is other way.

How to achieve syntax like that – parameters?name ?

This part of code is creating new “let-bound operator”. It hides the casting logic and makes the code look cleaner.

Error Codes

Views

Syntax is simple and looks basically the same as in C#. There is only one little detail. By default Nancy looks for views in /Views folder. Currently in VS F# project there is no way to create folders from within VS. In order to do this I had to manually, create folder, add file and edit *.fsproj file. Hopefully this will be fixed in the future.

More details

ModelBinding

In C# syntax, you would normally use the base method Bind to perform the binding. This method is an extension method and in order to have an access to it, I had to include ModelBinding.

The type to bind

And the code to bind to the model.

Unfortunately, it won’t work like that. My “TestModel” type is missing default parameter-less constructor and Nancy is throwing “No parameter less constructor defined for this object” Exception.

There is a constructor, no Exception, but the value is not bound and is always empty. To fix this, I had to go and look through Nancy code. By default Nancy is binding to property. My val declaration is not a property.

Syntax for properties is a little different, but nothing serious here. I need to make my value mutable so I can modify the state.

The Application OnError pipeline

To modify the Pipeline I had to add include Nancy.Bootstrapper it has IApplicationStartup interface which can be used to hook into OnError pipeline

Nancy will automatically pick-up this class. The syntax for interface implementation is different, a lot. There is no += operator when working with Events and I had to use ADD method. With this example I got an exception “unable to resolve type AppStartup”. It was a problem of missing parameter less constructor.

The End

Those examples are not really showing the power of F#. This power lays in domain-business logic, not in simple endpoint declaration. It is also the OOP approach with F# syntax. There are other web frameworks that have more functional approach. You can check Fancy which is a nice wrapper around Nancy. In a future, I might do a comparison with some purely functional web framework.

dotnetconf.pl 2014

I feel empowered and motivated, dotnetconf.pl and also Software Architects conf gave me a huge energy boost. Thank you everyone for being with us on dotnetconf.pl. For those of you who don’t know, dotnetconf.pl is an online conference, from Polish speakers to Polish developers. You can watch presentations here.

Last Saturday we have organized 2nd edition of this event and it looks like there will be another one. We don’t know when, I know that ideally, you the viewers, would like it to be sooner than later. As of now the plan is to do them yearly, but we might consider a conference on a 6 month basis plus smaller events per 3 months. It all depends on the demand and the audience. Pawel has also an idea to start audio cast, something like hanselminutes, with speakers discussing various topics from our dev world.

While, I was writing this post someone else was also thinking about audio cast idea and … today Maciej Aniserowicz has started his podcast ( Check it out it’s great ). Due to this we might pursue a different idea, maybe something like pair programming on stream, twitch, we might try it on 15th November doing game of life in Haskell / F# for Global Code Retreat. Would there be any interest in something like that ?

The conference chat was full of discussions. That’s great, really great and there is this small idea, proposed by one of the attendees, to start a conference a week before a live event like DevDay. With such a date, all the topics started online, could be followed in real life. Wouldn’t that be great ? The soo called “Hallway Track” doesn’t fit to the online format. However if you have any ideas on how to do something like that, then PM me :)

Unfortunately you weren’t able to watch Basia’s talk, we had issues with google hangout. We have been testing everything twice and it was ok and the suddenly it stopped being ok. Basia’s talk is going to be recorder and sent to all of you, soon be patient :)

Overall conference was great, I hope that you also enjoyed it. Still there are things that we can change / improve.

  • backup speakers, ready to step up if there is a problem
  • backup option for streaming, that might be hard, any suggestions ?
  • missed opportunities to attract bigger audience
  • Q/A system, some semi automated script
  • implement a way to quickly notify everyone that there are issues
  • some script to notify all the channels that new stream is starting
  • because of SignalR and static pages we weren’t able to update the agenda
  • simple voting system on the site

We might do more, we are open for suggestions. Feel free to send us a message with anything. Even comment that my thumbs ups and down on camera are childish, is a helpful one :)

Thank you for all the feedback. You are the best :)
Feel free to comment here and discuss some of the things that i just mentioned.

Game programming with F#, C# and SFML – GameLoop

I am a F# apprentice. The best way to learn new language is to do some project. That’s why I have started to code one game idea that was following me for some time.

Core concept:

  • sci-fi setting
  • roguelike
  • inspired by:
    • dwarf fortress
    • prison architect
    • cataclysm dda

Because I don’t care about the graphics but the game-play, the graphic I am going to use will be an ASCII styles tile set. You know symbols, characters, letters and some simple graphic, just like in old MUD games.

For graphic layer, I am going to use SFML and it’s .NET wrapper. It’s quite good and I know a bit about it. In the past I have been using SDL wrapper which was also fine. At the beginning I am mostly going to focus on 2D tile rendering and some ray casting to calculate field of view. I really like the way it’s done in Cataclysm DDA, so I ll try to emulate it.

Apart from coding the game and its logic, the most difficult part will be to use F#. I am a little worried about its stateless world. I have heard about monads and how you can manage state with them, but still its going to be difficult for apprentice like me.

To start with something, I have decided to do my first simple game loop and render window.

Couple of interesting things in this code.

“:?>” operator

If I have some class that inherits the System.Object ( Default behavior in .NET ).

“:?>” downcast – it will cast Object to Something. This operation is performed on run time.

The “:?>” operator performs a dynamic cast, which means that the success of the cast is determined at run time. A cast that uses the “:?>” operator is not checked at compile time; but at run time, an attempt is made to cast to the specified type.

“:>” upcast – it will cast Something to Object. This operation is performed on compile time.

The “:>” operator performs a static cast, which means that the success of the cast is determined at compile time. If a cast that uses “:>” compiles successfully, it is a valid cast and has no chance of failure at run time.

More about casting in F# world

Pattern matching ( F# switch )

From my understating it’s something like a switch but with more powerful options and possibilities. My example is a simple true, false switch.

() is an empty method just to do nothing and stop recurrence.

|> is a pipe lining operator, concept i know from the unix world, ignore is just information that i want to ignore the value that mainLoop() is returning.

More about pattern matching

Recurrent loop – rec keyword

The Game Loop has to be infinite. In functional approach you don’t use loops, like while(true), instead you have to use recurrence. In C# you can just call function from within the function. In F# you can do the same, however you need to mark function with rec keyword ? Why ? The answer is complex and if you want to know it check this link and this one

Get out of your comfort zone – Vim the social connector

I am a .Net developer, mostly. Sure, I am exploring Python, node.js and other technologies, still my work is mostly related to C# and recently I am having fun with F#. I can say that as of now I am tied to one platform and I mostly attending meetups and conferences slightly related to it.

comfort zone

Recently I have gone to one of the meetups and I had opportunity to chat with awesome PHP programmers. Boy that was fun. MS technology stack for them is considered as an evil one, with evil solutions and evil approach to opensource. Just like my image of PHP is full of ‘script kids’ lack of software engineering etc. Of course that image is far from reality.

I was really surprised how .Net developers are perceived :

  • we don’t know framework details because intelisense is doing everything for us
  • editor is doing everything for us, we are just drag n dropping controlsa
  • MS stack is an evil panda
  • we are using TFS because that’s a technology from MS
  • we are not trying other tools that the MS approved ones

As you can see the gap is huge. Now the problem is how to find a connection with someone from the other platform ? There is always a topic about domain,or other technologically independent stuff like DDD, TDD, BDD. But what about other stuff like tools ? Well we have Visual Studio and I have heard that PHPStorm from JetBrains is quite popular. Ahh there is git, yes git is fun and could be a source of endless discussion. What else … VIM, ha I am using Vim. It is so unusual that a .Net dev is a Vim fanatic that it might be this little cherry on top of the cake. They were really surprised. Even better I used emacs extensively on my university so legendary emacs vs vim discussion started. We shared our thought on vim, emacs tooling, I told them why i prefer Vim than Visual Studio.

What I learned. Hmm, I have to get out of my comfort zone more. One platform approach is a dead end. There are soo many people using different technologies that i might miss them or i wont be able to find a topic to talk to them. I have been also trying to follow rule, “Always say yes!” :) this one is hard to follow.

So whats next ?

  • Swift – I would need a mac … but finally i would have a nice topic to talk with @mihcall
  • Rails and Ruby – this would give me a basis to talk to @andrzejkrzywda and @mpraglowski

A lot of choices, a lot people. In the end no matter what you choose there will always be someone interesting to talk to. So get up and learn some new technology, move out of your comfort zone.
As a follow up to this topic, watch Martin Mazur talk from dev day 2012.

F# where to start

I have started learning F# again, thanks to @isaac_abraham and his great presentation in my company. This time hopefully, I will move past the “WTF”, barrier and move to “AHA” moment. I am ready to finally start serious F# learning with couple of milestones like: project euler, tool, web-app, complex project. I will try to document whole process on the blog.

I want to force myself and learn new functional paradigm. Hopefully it will give me a new way to look at problems and solutions for them. To this day I have spent most of the time in OO world, meh, it gets boring, really. I might also get a chance to do something cool with F# for my company. Me and 3 of my coworkers, we are trying to explore together DDD with F# and find a better way to model our code/

To start somewhere, I was given a link to a great site with a list of advices http://fsharpforfunandprofit.com/learning-fsharp/ Do’s and Don’ts section is very helpful. You can consider this as “House rules” constraining you with a form of “force yourself to think differently”.

Project Eueler 1

As usual, when I don’t know where to start with new language I go to Project Euler site. I am thinking about doing 10 problems just to get a hold on the syntax and features.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

The first problem it’s not that hard. You can do it by a brute force loop. there is also a better solutions that has lower complexity. My solution is just a loop.

I like the syntax, it looks really nice.

1st : I am declaring new function ‘ismultiplier’.
2nd : I am creating a sequence with filter in form of if. From my understating sequence is similar concept to a loop over some elements but its being lazy loaded. The data is created on the fly, while code iterates through it.
3rd : I am using Seq method to sum up the yielded values.

This is a simple algorithm, it won’t be enough to learn F# properly. That’s when some practical project will come in. It’s still planned, I have couple of ideas. It has to be something useful and complex enough project so can I learn how to structure code properly and how to use OOP inside F# world.

Twitter

    @ScottWlaschin – his great presentation convinced me even more that F# is the language I WANT to learn.
    @isaac_abraham – F# MVP, Issac’s presentation create first ripple that forced me to consider F# again.
    @eulerfx

Blogs

Talks

Last Minute

@ScottWlaschin created a nice list of all the talks from NDC Oslo 2014 that are touching the functional programming paradigm. Thanks Scott
NDC Fp Track

Questions

- Have you tried any functional language before ? What do you think about them ?
- I need some advice’s on how to approach this language and paradigm, any tips ?