Hjertnes.blog

#

November 12, 2017

Anyone tested out Lightroom CC?

#

November 11, 2017

#

November 11, 2017

#

November 10, 2017

The only way to make sure I see everything going on at Micro.blog I have found so far, is to add my timeline feed to Feedwrangler.

Understanding the difference between functions and arrow functions

November 10, 2017

Most React components are written something like this

I personally think this is very verbose, compared to what it has to be. Because just because most people use regular functions inside their ES6 classes, doesn&#8217;t mean you have to. You might disagree, but all the methods I define inside a component should either be moved to some utility file or they need to interact with the components &#8216;this&#8217;.<br /> The way I write React Components these days, if they aren&#8217;t stateless, is written something like this:

The big difference between the two is that I have ditched the constructor, because I&#8217;m only using it to set the default state and binding the functions. Then all the methods in the previous class have been replaced by arrow functions that use the expression syntax. Which removes some lines with brackets and a return statement.<br /> I personally think the latter versjon looks a lot better; or at least a lot cleaner. There are less "stuff". And I&#8217;m going to start re-writing a lot of react code to follow this form, and everything new I write will follow this form. I could probably remove many hundred lines of code just in removing brackets, return and unneeded binds and constructors in my work projects.

#

November 09, 2017

Just got my my new Apple Silicone case for my 8 Plus. It looks good, feels good, adds protection without too much bolk.

I personally think that Apple makes the three best cases for iPhone. The Silicone and the Leather Case is without doubt the best general case, and the Smart Battery Case is awesome; if you want a battery case.

Most of the cases I see out there looks pretty bad. Big and or ugly.

When it comes to the case or not question, I think that there was no need for a case, unless you needed extra battery before the 6 and 6 Plus.

But I think you need one with anything larger than a 5. And the fact that Apple makes cases for them, and not the 5 size or smaller speaks for itself.

You can blame it on the size or how slippery they are. But the larger phones need a case.

I used a red silicone case on my iPhone 6S Plus, until it fell apart, and then I used a leather case until the phone died.

And I ordered a new silicone case a few days after I got my new phone. I didn’t really consider anything but a Apple case, because they are the best.

Javascript is not syncronous; don’t treat it as such.

November 09, 2017

I get some StackOverflow thread named “How to do”Insert what I Googled for here” syncronous” every single time I google anything generic about Node. And while I do understand the question, I think they are asking the wrong question.

Node is awesome when you let node be node, and it is horrible when you try to treat it like for example Python or Java with Javascript syntax. Because node is async while Python and Java is sync. This means that everything that might block the main thread will be spun off as its own thread, without you telling it to do that. And then you have to either deal with it through callbacks or promises.

The reason you want this is that you don&#8217;t want your web server to be unresponsive while you are executing a huge database query, or your web app to be unresponsive while you are doing a very heavy filter.

I have seen some developers that I have worked in the past treat Node as something it isn&#8217;t. And I told them time after time after time to use Promises or callbacks to deal with what they were doing. Because what you are doing here will never work well. They aren&#8217;t terrible developers, most of them are actually execellent, but they aren&#8217;t that great with Javascript. And were always talking about rewriting it, instead of doing a trivial change, because they didn&#8217;t understand it or what ever.

You have two options if you don&#8217;t want to write callbacks; either as in callbacks or as in dealing with promises. Use something else than Javascript or use async await. It will let you write code, as if it was syncronous while still being asyncronous.

Node and Javascript makes it very easy to write high performing async code. But you need to embrace that it is how it works. And stop to think like a Python programmer.

#

November 08, 2017

I always think “has Facebook a new authentication system?” when I see FaceID

Programming asynchronously

November 08, 2017

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>

#

November 07, 2017

Another week another American massacre