Skip to content

Instantly share code, notes, and snippets.

@erebe
Last active June 22, 2024 06:05
Show Gist options
  • Save erebe/a8b0ffd1a27133bcf3b640b64e35f2fb to your computer and use it in GitHub Desktop.
Save erebe/a8b0ffd1a27133bcf3b640b64e35f2fb to your computer and use it in GitHub Desktop.

A Journey into Haskell and Open Source

I want to write something to celebrate the latest and I hope the last release of wstunnel, a TCP/UDP tunneling websocket tool, and share with you at the same time my story with Haskell and OpenSource projects.

A venture into Haskell

This open source project is not my only one, but is found to my hearth because it brought me joy, despair, proud, shame and further reach that I wasn't even expecting at first. If you have not noticed, the program is written in Haskell. I started learning it, well 8 years ago now..., when I was studying abroad in South Korea. At the time I was struggling with the feeling that I was not enough, I already knew C++ and Java, but was feeling like stagnating while there was so much more that I wasn't knowing. I wanted to be more and thus I needed to dedicate myself to learn more in order to be better. This fear of stagnation is still present in me even today, and if you are working as a programmer, I think you cannot get rid of it totally. Even senior programmers are afraid of getting out of touch somewhere in the back of their mind and while this feeling is still present, at the cost of a relationship, it is not consuming me like it used to be.

If you are reading this and starting your career, I want to give you those advices. Find some hobby outside programming and there is nothing wrong feeling that you are not learning something new all the time. Coding is a lonely time sucking activity where 4 hours can pass by the blink of an eye, and yet still feel like it is so little. Going down this path is a rabbit hole where your 8 hours of work will feel like are not enough and you will end up finding you don't have time for anything else. Some activities like going for a run, cycling, dancing, taking theater class, ... can be done in 1 hour and be much more rewarding of your time and for your relationships. This is especially true after leaving school, when the how to progress will become more blurry and without the guidance of a teacher/mentor you will find yourself wasting a lot more energy just to make you a path.

I remember clearly why I chose Haskell. I was debating between it and learning D, mostly due to Andrei Alexandrescu a big name in the C++ world, who wrote the excellent book "The D Programming Language" where he highlights a lot of trade-offs about language design. I gazed for a month or so into both language community, willing to not repeat the mistake a friend made into choosing to learn Perl instead of Python, silly him... And after writing an IRC bot in D while having fun with mixins, I chose Haskell, not because of functional programming or strong typing, but because it was supposedly hard to learn, and ho boy, it was !

If I was struggling with a not enough syndrome at the time, Haskell was setting it on fire, providing my soul with a never ending source of struggle, a sea without depth where my thirst of knowledge was able to dive into. Everything about it was hard, the language by itself was challenging. Recursion ? Yeah, I know it. What are those tears, are you crying for a for-loop. Types ? Sure I can do some template meta-programming in C++. Welcome category theory a whole new world dedicated to types and their relationship. Don't expect to be proficient in Haskell If you don't know a minimum about it. Want to use a library ? Yes, hum wait, why the documentation for it is linking a research paper. Want to grok some code from other people ? Hey everything is a funny operator or written with this strange DSL. My most memorable experience with the language is maybe this one, spending 4 months writing a generic API with dependent types that generate itself just by declaring external modules/plugins. I spent those 4 months going back and forth, telling myself it was not possible to do it that way, asking around, giving up, but still believing it should be possible and ending up coming back to it. After literally spending 4 months of thought on less than 100 lines of code, liked it did with pointers, it clicked and I succeeded to build it.

Even if the language is challenging, the rest of the ecosystem was hard on me too. It is less nowadays as some aspect improved a lot but it was my first time meeting a so diverse community where you can find some academics, some hobbyists like me and some professionals mixed together. This rich community is very enlightening as it brings you a lot of different perspectives but can feel sometime clunky and less than practical. Arguing by mail instead of github/bitbucket with an academic maintaining a library regarding very poor performance, and seeing patches being refused because it was making the code less "pretty", that performance was not an issue, just demonstration of feasibility was. A lot of libraries are rotten code by now or with issues or coded in a not common code style, as written in one shot by some hobbyist wiling to try something and not maintained anymore. Standard practices in the industry like tests, documentation, reproducible build was not common at all, to the point where re-cloning your project a week later was a dreadful thing to do, as you were pretty sure it was going to break your build (it is not the case anymore). And a lot of other small things like having stack traces, good debugger/profiler in order to spot this nasty lazy evaluation that is making your code memory leak, code completion, were making your life harder and was contributing to making Haskell a notorious hard language to learn.

Haskell is hard to learn yes, not because Functional programming is harder than OOP, but because it is a very old language with a lot of quirks and is at the same time a sandbox for researchers, a playground for hobbyists, a tool for some businesses, and all those constraints make the language full of rough edges and contradictions. Maybe it is some kind of Stockholm syndrome, but even with all that said and while I am not writing a lot of Haskell anymore, if someone asks me if he should learn it, I would say yes without a doubt. It definitively made me a better programmer by forcing me to try new approach and by making me understand the trade-offs of each of them. Category theory force you to take a step back and to think/design the relation of your code ahead, and sticking around the community will make you watch interesting discussions about research topic among knowledgeable people. So go ahead learn it, it's fun :)

A venture into Open Source

I started wstunnel while working as a junior developer at a Big Corp, a position I got after reading Machine Learning in Haskell and spent some time fiddling with Spark to detect when is the best time to buy some products. While I was doing some map-reduce jobs on Hadoop, I was finding myself most of the time stuck by some kind of proxies put in place for security, but to such extreme that investigating an issue was taking ages just to get the necessary accesses. Even more infuriating, I was not able to connect to my personal server while working...

The project I was working on was taking a slow down, and while I was not thinking that I was already spending too much time in front of a screen, I wanted a new pet project to get again the feeling of learning something new. After spending a month struggling to find something to work on, it is impressive how much energy you can waste when you want something but don't know how to reach it. That's only after reading Parallel and Concurrent Programming in Haskell, a book that I whole heartily recommend even if you're not doing any Haskell, that I thought of coding wstunnel. I've always been found of networking for some reasons, a topic most people don't like, and it was the perfect opportunity for me as I was regretting not learning enough from C++ boost.asio during my first job. A job I ended-up quitting too early, mostly due to being too arrogant, a hard but worthwhile lesson in my career.

Wstunnel started to be used only by me and soon after by some interested colleagues. It was one of them that was thinking wstunnel should get more attention and motivated me to spend some time to make it stand out. So did I, I took time creating a logo, perfecting the command line, writing a documentation, made it the most easy to use as possible, and advertising it a bit around internet. And that's where the 4 years journey began.

I thought it would take me a bit of time to get a finished product, after getting some feedbacks and improving some area, like 1 month, maybe 2 at max. Well let me tell you that, even with modestly successful open source project like wstunnel, it is an endless stream of work for its maintainer. This fact have been verified for every project/library I maintain for work or personally. Even while you think some library is dead, that nobody is using it anymore, one day you receive an issue/mail regarding a bug/new wanted feature/question about its usage and you are lost wondering how in hell people found it and what are they doing with it.

Be prepared to say no and to think what is best for the project and the usage case you want to cover, because every decision you take will be at some point challenged by someone. Some people will have a nearly the same use case and found out that extending the project a bit would allow to cover it. By accepting just to please, you discover soon after, that you are now the owner of new bugs, documentation to keep up to date, feature to not break, long after the original requester is gone. Corollary be prepared that every corner you cut during development, like hard coding some timeouts or buffer size, somebody will find out and point it out forcing you to come back at it.

The cost of maintaining a project will increase with time, and this point has been especially true with wstunnel. When you start a project you are at ease with everything, you know the code, you know the language and ecosystem well and the cost of doing a new release is tiny. But with time things change and this tiny cost start to increase. A lot happened in my life during those 4 years, I changed city, started a new job as SRE, broke of a 7 years relationship, trained to run a marathon, and now trying myself into a devlead position. All of that to say that things that once felt familiar start to get distant if you are not practicing it regularly. The Travis build is failing even while you have done nothing, the great library you used start making breaking changes every new version, the 30 min cold build was not an issue because you already had the dependencies cached but now start to feel like your nemesis every time you think to touch the project, new compiler version and OS breaking things, you think doing a quick release but end up doing a shitty one because you are not really into/willing to do it, ... The idea is that maintaining a project is an endless stream of work and the more you distance yourself from it, the more it becomes to be a burden when you want to come back at it.

Even when it felt like a burden to maintain this project and other, I kept doing it because it felt so rewarding. If you skip over the angry/impolite/toxic people that appear from time to time. Wstunnel rewarded me with thank you email from people living in less than democratic country who wanted to share they joy of being able to escape some firewalls in Iran, Russia, China, Israel. It provided me with an endless source of astounishement of how and in which context people were using my projects. It seems that running a VPN business is a flourishing activity. I accepted my first freelance gig from some chinese that wanted "private" features. Got some strange pcap capture from I don't know which network, from people not willing to disclose that they were doing... If it was not thanks to open source, I don't think I would have been able to reach all of those people in my life, and for this I am thankful.

Closing Words

This is the latest and I hope the last release of wstunnel, a TCP/UDP tunneling websocket tool. I wanted to share with you my story with Haskell, and take some time to thank all the maintainers in the world that are dedicating some of their personal time to keep open source projects working, I deeply understand your burden and I can't even imagine what it is to be responsible for a successful project on the long run, so thank you :) For my part, I wish that maybe one day I will be able to taste the feeling of sufficiency and completeness that you can often see in the look of young mothers, or maybe I will end up like Faust in its cabinet, lamenting himself that he wasted his whole life building knowledge without really living and end up making a devil pact with Mephistopheles. Who knows, at least it will be fun adventure !

Watch the video Watch the video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment