Hjertnes.blog

#

November 15, 2017

To the untutored eye, Lisp is a strange programming language. In Lisp code there are parentheses everywhere. Some people even claim that the name stands for “Lots of Isolated Silly Parentheses” — An Introduction to Programming in Emacs Lisp

#

November 14, 2017

#

November 14, 2017

Testing out a new text editor this week. I’m very happy with Spacemacs this far.

Variables

November 14, 2017

There are now three different ways to create a variable in Javascript. There are many different minor differences between the three.

<li>

  When you create a variable with &#8216;var&#8217; you also add a property to the window object, this is not the case with let or const

</li>

<li>

  Var and let are replaceable, const are not; all of them are mutable.

</li>

<li>

  Let variables can be local to a block (see example below)

</li>

I would stay away from var unless you have a really good reason to use it. Then I always start with a const, and migrate it to a let if I really need to replace it.<br /> Local scoping with let:

The example above shows how lexical scopinng can work with let. But use it with caution, because it can be confusing for developers that don&#8217;t understand the differences between let and var. Example one and three shows how it works without local "scoping" and the one in the middles shows how it works with local scoping. The short version is that you can define variables with the same names in different scopes without them writing over each other. Very useful for variables that don&#8217;t need to be available outside and for using the same variable name for all temporary data of a certain type or use.

#

November 13, 2017

Being more mindful about what kind of functions you use where

November 13, 2017

Let’s talk about arrow functions versus regular functions. I love how much more minimal and elegant arrow functions look. But I think we might need to start being more mindful about what we use where.

The key difference between the two is that an arrow function shares it&#8217;s this with where it is defined, while a function either shares it with the global scope, or the context it is bound to; if you are using strict you have to bind it to something to have a &#8216;this&#8217; at all.

I see all the time that me and many other developers are using each one for all the wrong reasons.

Use regular functions if you don&#8217;t interact with &#8216;this&#8217; or if you are going to bind it. And use arrow functions if you are going to use the &#8216;this&#8217; of where it is defined.

A typical place where many people use regular functions where arrow functions is a better option is event handlers in React. And a typical place where people use arrow functions a lot, instead of regular functions, where they are not the best option (because we are lazy) is utility functions.

Be mindful about the differences, and understand what you are doing and why.

Workflow and Pythoninsta.

November 13, 2017

I was looking into how to do something really simple using Drafts and Todoist on Saturday.

The basic idea was that I wanted an easy way to either add or create a new project and then add a series of tasks to it. (First line is the project, and the rest is tasks).

Well. I thought, this is a perfect opportunity to play around with Workflow. So, I made the damn thing and then I also did it using Pythonista.

The verdict? It took way shorter time using Pythonista because I know how it works, but I think something like Workflow is the right tool, if you don’t know how to code.

This is a common thing I often see myself doing. When something is very simple, I almost always end up writing it myself, because then I don’t need to learn all the “jargon” and metaphysics every single system always have.

The difficult thing is to know when to write it yourself, and when to learn what is already there.

#

November 12, 2017

#

November 12, 2017

Anyone tested out Lightroom CC?

#

November 11, 2017