hjertnes.blog

Programming asynchronously

08.11.2017 01:00

One of the big issues with using either callbacks or Promises is that the code becomes much more complex that it would, if you were using a synchronous programming language. This is where async and await comes in. The keywords are borrowed from C# and .NET and is without doubt one of my favourite features of using C#. You need to prefix your function with the “async” keyword before you can use the await keyword. And every async method will return a promise. This means that you could make a promise by making a async method and use return and throw instead of a regular promise with resolve and reject. So, you’re inside a async method and want to fetch some data from a method that returns a promise; either a promise or another async method. You could either use .then() like before or you could just do something like this: let data = await method() Look at the full example below:

I think that async / await in general makes code less complex, because you can hide most of the callback / promise stuff behind the await keyword, and treat it more like a regular program in for example Python or Ruby. But remember that every method that uses await, need to be async; this means that you need to do this "hack": <code>await Promise.all(data.map(async d =&gt; d*2))</code> hack if you need to do await inside a map. Because the map code will return a array of promises. Like I said, all async methods returns a promise. Then, you can resolve them using promise all, and if you prefix it with await, it will give you the result of all of them in an array as result.<br /> Again, Promises and Async methods are two sides of the same coin. I personally look at Promises as the technology behind it all, and mostly use async await to make and deal with them. </div>

#

07.11.2017 01:00

Another week another American massacre

Hello world!

07.11.2017 01:00

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

Hello world!

07.11.2017 01:00

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

My Rules

07.11.2017 01:00

```text I have mentioned “I have a rule against” a few times while writing this site. This will be a summary of them. ```

```text
  • Buying stuff: I’m a minimalist, and I do therefore try to minimise the amount of stuff I own and use. And therefore I try to only have notebooks, inks, pens etc that are useful for me. If I test out a notebook, I make sure that it is something I can use, even though I prefer other notebooks. For example the Rhodia Webnotebook, it isn’t my preference, but it is still close enough to what I usually use for me to use it from page 1 until the end
  • Notebooks: every notebook I review and test on this site, will be used to its fullest, and if my views on it change after my initiallreview I’ll write about it. I never stash stuff away before I have used it up.
  • Inks: I limit the amount of ink I have on my desk, because I feel very uncomfortable about the idea to have enough ink to last longer than a life time. I currently own two a little bit over half full bottles and one almost empty.
  • Pens: I want to have enough pens in rotation so that I can always refill my pen case with a full pen when needed. Most of them are cheap, and two of them are expensive.
  • ```

    Programming asynchronously- Callbacks

    06.11.2017 01:00

    Most mainstream programming languages are synchronous, which means that it runs line one, and when that’s finished in continues to the next one etc. While in asynchronously programming a lot of things are going on at once. There are good and bad sides to both. I personally think that asynchronously is the way to go if you are building user interfaces because you don’t need to deal with firing off threads etc when a user clicks a button. The bad side is that some people find it confusing and that the code is a little bit more complicted by necessity. The way we deal with stuff that takes an unknown amount of time in asynchronously languages like for example Javascript is that you define a method(or apair of methods in some cases) to be ran when it succeeds or experiences some kind of error. For example like this:

    ```text Some libraries use a single function, like above, while others, like jQuery (not that jQuery is a good example of anything these days) use a separate callback for success and error. But the basic idea is that the function (or functions) you define will run when an error occurs or you get a response. ```

    #

    05.11.2017 01:00

    Another Review of the J. Herbin 1670 Caroube de Chypre

    05.11.2017 01:00

    ```text I got this bottle of ink from Pen Chalet for the purpose of reviewing it, and I did, but I was never that happy about the review. I’m not sure why, probably because this ink is so far removed from what I usually use. ```

    ```text My typical ink in the beginning was black, I used the Lamy and Pilot cartridges for a very long time. And I loved them for the convenience. I would probably have used cartridges in my Vanishing Point if the Iroshizuku line was available on that form(you can have that idea for “free” Pilot, just send me a red Falcon with a soft broad nib in exchange). Then I moved over to bottles, first Noodelers Bernanke (which I loved), then I moved over to the Lamy black (which I hate) before I ordered my first Iroshizuku bottle (take-sumi) and I have gone through two full bottles and two half bottles of Iroshizuku ink since then. ```

    ```text They have some shading, in the of their inks, but no glimmer or crazy colours. This J’herbin ink is all kinds of crazy, the colour is fantastic, it is a reddish brown, with gold glimmer. ```

    ```text This is probably the first time I’ve used “fantastic” and “brown” in the same sentence. ```

    ```text I have now used the ink quite a lot. First I used it in a Noodlers Ahab for a few weeks, and now I have used it as my only ink in all of the pens I have in rotation. And I enjoy it a lot. ```

    ```text The dry time is a little bit longer than what I prefer. But I think it is a great ink. ```

    App Review

    05.11.2017 01:00

    ```text Finder is a pretty good file manager, not the best for everything; but I believe it is the best option for a majority of user for a majority of tasks. ```

    ```text When I want something more powerful, I always go for Path Finder. ```

    ```text There are two aspects of it in particular that makes it very useful in certain situations. ```

    ```text The first is that it does not close the window when a drive or CD is removed. This might seem like a minor thing, but it is a major pain in the ass when you are copying the contents of many different CD’s, like I often do, when I get rolls of film back after getting them developed. ```

    ```text The Second is its dual browser. This is a very old feature, that used to be in more or less every file manager. Especially in the world of text based software. I remember to use it a lot in GNU Midnight Commander in my Linux days. ```

    ```text This feature alone is worth the price of Path Finder, it makes it so much faster to re-organise stuff on my Mac. ```

    ```text Path Finder is not as pretty as Finder, but it is the power user version. Instead of hiding useful but confusing features and information it is there, right in your face. ```

    ```text Check it out, if you are looking for a more powerful alternative to Finder. ```

    #

    04.11.2017 01:00

    “Optimising your notation to not confuse people in the first 10 minutes of seeing it but to hinder readability ever after is a really bad mistake.” (David MacIver, via a post about Scala syntax).