lördag 27 oktober 2018

Kul respons på min kommentar till mjukvaruutvecklar-podcasten Väg 74


Efter att ha lyssnat på några avsnitt av podcasten Väg 74 och det i mina öron många gånger låtit som att jag lyssnat på en skiva med Trazan och Banarne så skrev jag nedanstående tweet.



Nästan ett halvår senare lyssnar jag på avsnitt 83 "Undvik projekt", som har ett intro (lyssna här) baserat på tweeten, kul! :)

Just det avsnittet tyckte jag inte var så givande för mig annars, men är du sugen på att börja lyssna så kan jag rekommendera t ex avsnitt 17 "Vrid upp samarbetet till max med Mobprogrammering" eller avsnitt 15. "Tänk på test".

Och för er som växt upp utan Trazan och Banarne så finns de tydligen både på SVT:s Öppet Arkiv och Youtube såklart!




torsdag 25 oktober 2018

Open PowerShell (or Command Prompt) in Admin mode in the current folder from File Explorer

Sometimes it can be handy to open a PowerShell (or Command Prompt) from File Explorer and directly end up in the same folder that you had open in File Explorer.

These two instructions might be exclusive for Windows 10 only, I'm not sure.

Non-admin mode
Go to the address bar, type cmd and press enter.


Admin mode
For PowerShell, press alt, then f, then s then a. Alt, f, s, a
For Command Prompt, alt, f, m, a

1. Pressing Alt will bring up this menu with hotkeys



2. Pressing f will present the next menu with a new set of hotkeys




3. And pressing opens the last menu



4. Tada: PowerShell i admin mode in the correct folder



torsdag 4 oktober 2018

Do you use big enough color distance?

Read the texts in the image below.

Which text do you find easiest to read?


Probably the one with the largest color distance between the text and the background color. That is the one to the right.

How can you make sure you use big enough color distance so that even the audience in the far back can read the text in your presentation?

One way is to use Mark Millers Highlight Explorer app where you can experiment with different colors for backgorund, foreground and highlighted text.

https://github.com/MillerMark/HighlightExplorer (it's just the source code so you need Visual Studio to run it though...)


If you got money to spend and want to know more about it you can take his course The Science of Great UI

måndag 9 april 2018

Do your ajax calls block each other so they don't run in parallell? Setting the right SessionStateBehavior might fix it!

Today I tried to optimize an asp.net mvc page. The page did three ajax calls, two of them were fast and one was slow. The slow one executed first and blocked the other two so they couldn't execute and return with their data until the slow one had finished.

I was surprised by this since the ajax calls really should be asynchronous. The problem turned out to be the use of session. When session is passed with the ajax call, the call blocks other calls that passes the same session. Because if the first call alters the session it should have an impact on the other calls so they have to wait.

The solution to this was to add this attribute on the controller.
[SessionState(SessionStateBehavior.ReadOnly)]

When the controller is marked with that attribute asp.net knows that the code in the controller can't alter the session state so the other calls don't have to wait for it.

Here's the blog post that got us on the right track.

söndag 11 mars 2018

Multi-cursor editing in Visual Studio Code, edit many places simultaneously!

Did some pair programming with @nevva and saw him do some multi-cursor editing in Visual Studio Code I hadn't seen before. So here's three different ways to edit your text files at multiple places simultaneously.

Use Esc to exit multi-cursor mode.

1. Ctrl + Alt + arrow down (or arrow up)
A simpler variant of this in the classic Visual Studio is Shift + Alt + any arrow


2. Alt + left mouse click


3. Mark some text => all occurrences gets highlighted
Ctrl + Shift + L => every occurrence gets its own cursor


söndag 28 januari 2018

Two subtle Linq-related bugs that ReSharper highlighted during code review

ReSharper, a productivity tool that helps you automate some of the code writing and also analyses the code written. The biggest drawback I find with it is that it makes the Visual Studio startup a lot slower. Yes, that is annoying, but I still value the code quality help it gives me more than a fast startup.

This is two examples of Linq-related bugs that ReSharper pointed out for me when I was reviewing code. I hope I would have found the bugs anyway, but Resharper made it a no-brainer to find them and almost impossible to miss.
The examples do not show the original code, only the same problems.
The code writers did not use ReSharper.

Example 1

This is example 1, without the help of ReSharper, do you see the problem?

This is the same code, but with ReSharper active, the problem is shown more clearly, isn't it?


The gray code in the if-block tells us that the code isn't used. Ok, so why isn't it used? Hoover over the blue squiggly-lined code and you will see:



Expression is always false. This hopefully makes a programmer with little experience in Linq to do some research to find out why. And then change the if-condition
projects == null 
to 
projects.Count == 0 
or 
!projects.Any()

Because Linq's ToList() does never return null, if no rows are matched an empty list is returned.

Example 2

This is a similar problem, do you see what the problem is this time?


With ReSharper activated it looks like this again, but not for the same reason.


The variable projects is not the resulting list of the query. It IS the query. A query that hasn't been executed. And therefore, since it is a query (or an IQueryable object) that is assigned to a value during creation, it cannot be null when the execution of the code reaches the if-condition.


Conclusions

These two bugs can to a code writer or reviewer be rather subtle, but with the help of ReSharper they are not so subtle. Subtle bugs can easily go under the review radar and if the code isn't tested thoroughly it can even reach production. And bugs having come that far are often more cumbersome/expensive to fix than if they had been caught earlier in the process.
That's why I find ReSharper worth its price, both when it comes to money and performance.

torsdag 25 januari 2018

The Visual Example I Always Search for Before Doing a Feature Branch Rebase

Now and then we discover that we've branched out a feature branch off of the wrong branch. To get the workflow correct, we need to move the feature branch so it branches off of the correct branch, a so called feature branch rebase. 

This happens so seldom that I always have forgotten the command for how to do it, so I google it and hope for finding the same example that I found useful the last time. The example isn't hard to find, but this post is for making sure I don't lose it.

The example is copied from the section More Interesting Rebases at https://git-scm.com/book/en/v2/Git-Branching-Rebasing