My take on test driven development

09.06.2019 12:18

If you do formal Test Driven Development (TDD) there are some rules for how you should do it, like you start with the test, then you write a failing test, but not more than to make it all fail. Then you fix it, add another test etc.

I’m not into this for a number of reasons, but I do agree with the basic idea: you don’t write anything without also writing tests to make sure it works. It takes some time, but it will save you a lot of time as you move forward.

This is how I do it for backend code:

  • I write the controller, and then the services behind it, plus model changes etc that are required for the controller to do what it needs to do. Sometimes that also means so extra filter/middleware stuff etc.
  • When the code makes sense I write tests for it.
  • I exclude what I don’t need to test (classes with just setters getters) or can’t test
  • Write unit tests for the rest
  • Finally I write a test in Javascript that use the controller over HTTP

The big difference between them is that I only care about making sure there are good tests in place by the time I’m done; how you do it isn’t that important.


07.06.2019 17:16

It never stops to impress me how many blog posts I read or skim each week.

Dealing with weird bugs

03.06.2019 04:59

I spent most of the day today at work dealing with a weird problem. The summary is that when add prettier as a dependency in a create react app based front end project jest breaks down and none of our tests work. The reason as far as I can tell is that something weird happens to the dependency graph and some babel runtime stuff aren’t where it should be.

When stuff like this happens, and I have no idea what’s going on, I try to locate what I think is the reason for it. Like in this situation I thought it was some dependency doing something weird.

The process from there was to remove everything except react-scripts from dev and regular dependencies. And start the process: run tests, add the dependency it complained about, and repeat until I either got it running or I met the issue.

To my surprise I managed to get it running before getting there. Then I added linting to the mix. Run tests, run lint, add missing dependency.

Then when I discover the problem child I start a new blank project and tries to reproduce it there.

The reason I do the last thing is to make sure it isn’t anything dumb I have done.

My experience is that it is usually because of something I have done, and not a real bug.

The idea behind finding problems is to figuring out where it is, that means where it is not. The most efficient way is to just start in one end and just start looking.

It can be really time consuming. Or is really time consuming. And there are no short cuts to finding the kind of problems that don’t give you any hints.

You just need to think straight, pick a strategy and start in one end.


31.05.2019 08:32

I tried looking into doing some basic categories on the links, and I didn’t end up with anything useful. It was either a bunch of very small categories or too generic to be of any use. These links are intended to be a low effort way for me to just dump out everything I’ve read in the last week that I consider worth sharing.

Another look at the Classroom Friendly

26.05.2019 06:27

I got this sharpener last summer, and I have used it close to a year now, and I do love it:

  • It has a cool and vintage look
  • It makes a perfect point every single time; that isn’t so sharp that it breaks too easy.
  • It sharpens pencils really fast.

But it isn’t perfect:

  • It leaves some tiny marks on the pencil
  • It’s noisy.
  • And it almost always leaves some pencils shavings where I use it

The marks on the pencil bothers me a little, but not that much to be honest. And I do think all the bad isn’t close to being even to all the great things about this sharpener. Seriosly. It would take me less than 5 minutes to sharp the both sides of a 12 pencils.

Learning SED

26.05.2019 06:25

Sed is this weird unix tool, it is basically a command line tool for doing text editor stuff as a command line command. It can work directly on files or by piping things into it and redirecting the output.

This is one of the things I should have taken the time to learn a million years ago. But I didn’t. So I spent some time learning it a few weekends ago.

Always use the -E option, it makes the regular expressions a little bit less What the fuck. Sed have become how I do large scale search and replace after the inital learning period. The big advantage to it over a text editor is that it scales much better. I used to and still use Visual Studio Code for this a lot of the time, because it’s inteface for it is awesome. But it fails beyond the point of being funny if you try to do use it on thousands of files.

Use -i if you want to do in place editing aka doing it on the actual files; and for christ sake, use git. The manual is the place to start.


25.05.2019 15:16

I knew I kind of promised to start doing some basic categories, but I do not have the time for it, but I’ll try to do it next week.

Review: Hario Soto Magu

24.05.2019 16:39

I’ve been using travel mugs by Contigo featuring their autoseal system. It is awesome, and very convenient but there is this rubber part that keeps water from leaking out that is small and wears down in this annoying way very soon, where you hear the pressure leak out. It usually starts after a few months, then after like a year I usually replaced them because they start to look really gross.


The problems with the Contigo mugs:

  • Impossible to clean really clean the lid.
  • There is this part in the lid that wears down too fast.

So I decided to change, because I’m sick of replacing them, and there is no good way to order replacement lids.

I decided to get the Hario Soto, because a lot of coffee nerds like them, and they looks like a good option. None of the parts looks like the kind that would wear out fast and it is easy to disassamble it lid and properly clean it.

The lid itself is great, a little bit less convnient to drink from while traveling than the Contingo, but still great. It is a lot smaller, while only having room for a little less coffee.

Time will only show. But I’m confidnet that this was a better option, and I wish I’d done it before.


19.05.2019 10:58

Popsockets are this thing you glue to the back of your phome that you can pull out or collapse so that you have something to hold onto that does’t bulge out a lot when you pocket your phone.

They look kind of weird, but I am really enojoying using them. They have multiple versions, I’m using the kind you can twist off so wireless charging still works.

What a popsocket gives you is a easier way to hold modern larger smartphones, you can kind of just let the popsocket rest between your fingers and you don’t have to grip it. I have noticted that I’m enojoying hold my phone way more, I have less pain in my wirst when I use my phone a lot and I’ almost never tired in my hand because of it.

They are not expensive, and I’d give it a shot. I didn’t think I would like it before ordering some, but now I can’t imagine having a phone without.

Five year journal

19.05.2019 10:50

Five year journals was something (I think) I first heard about on Patrick Rhone’s old podcast Enough a very long time ago. Then I have looked at them many times over the years, but I first got serious about maybe getting one between 1,5 - 2 years ago. And about 2 months ago I finally ordered one. I got one from Leuchtturm1917 in the A5 format.

A five year journal is just a thick hardbound notebook with one page per day, with a date printed on the top and divided in five.

I’m really enjoying in this far, I have not skipped a day yet, and I kind of regret not getting one earlier. What I really look forward to now is to get past the first year so I can see what I wrote on this day last year.

You have some room, but not a lot of room each day, and that have made it easy to write something each morning. But I got to admit it, I freaked out a little bit when I realized that this is FIVE years. That is a really long. And I’m also wondering how well it will hold up that long.