A customized shortcuts scheme for an improved debugging workflow in Visual Studio

Update: I just realized I’d forgotten one of my favorite shortcuts: Alt + N. So what does it do? See the list below! Suffice it to say, after using it I no longer worry about getting lost in tangent code while debugging. 😉

I love a good shortcut. I love it when I can perform a task without removing my hands from their regular location on the keyboard, and without having to look down to find that one special hard-to-reach key. Now as every moderately experienced programmer knows, debugging is often an essential part of the job. In fact it can sometimes take up the clear majority of your time for extended periods. That’s why I’ve always found it so strange that the shortcuts for regular debugging actions such as step over, step into, step out of and so on have such (in my opinion at least) impractical shortcuts.

The following is a scheme of key bindings that I have been using for two or three months now, and which I find natural and easy. The effect of this change has been bigger than I had anticipated: Since I no longer need to pause to look down at the keyboard while stretching for the F11 key for example, my train of thought is slightly less prone to being interrupted. Cutting out these minimal context switches means I can focus better on the code, which means I work faster and spend less mental energy keeping track of where I am, and what is going on — and there’s your improved debugging workflow.

(*) shift + F11 is a common shortcut for “step into”.

Shortcuts

These are the main shortcuts I’ve added. Some are inspired by the use of Vim (J moves the cursor to the next line in Vim – her it steps to the next line of code), while others are based on mnemonics (G for “Go” to either start or continue debugging, S for “Stop“), etc.

Continue reading

A Powershell alias for outputting info from functions

In most common programming languages, a function (or method) defines a block of code that does some work internally, and returns a value at the end, either implicitly (the result of processing the last line is returned), or explicitly (a keyword such as return is used to specify the return-value). In Powershell on the other hand, everything is returned out. Take the following example for instance:

function get-an-array {
    "Creating an array..."
    $arr = "one","two","three"
    "Array created; returning it now:"
    return $arr 
}

#calling the function:
$myArray = get-an-array

In most languages, you would expect $myArray to contain just that – an array after executing the code above. Also, you might have expected the messages in between to have been written out to the screen. Not so! The actual content of the resulting variable will be as follows:

Continue reading

Git bash: Clear screen and show diff

I just added another little convenience command for Git Bash. This is for clearing the screen and showing the diff (changes) in your branch. I added support for a parameter so you can use it either to show all differences, show the changes for a specific file, or append some other parameter to it (see the examples below).

Here`s the code itself – append it to your .bash_profile file, then restart your git bash:

cdiff(){
    clear
    if [ "$1" ]; then
        git diff "${1}"
    else
        git diff
    fi
}

Examples of usage:

cdiff # Will clear screen and show all changes not added

cdiff --cached # Will clear screen and show changes in added files

cdiff my-file.xyz # Wil clear and show changes for the specified file

cdiff --name-only # Will clear, then list all changed files (not added)

A use case for bash functions with git on Windows

When you open a Git Bash shell, it will typically open under your home directory, as indicated by a yellow tilda (~) at the end of the command line.

Side-note tip if you’re new to unix type shells:
~ refers back to your home directory – e.g. C:\users\YourUserName\ under Windows, so entering cd ~/SomeDirectory from any location will always change your current dir back to c:\users\SomeDirectory.

For my part, I’ve got most of my projects and source code under a directory called “source“, and all my git-projects below that again in a directory called repos. This means that each time I open the git shell to do any work, the first thing I need to do is change directory using: cd source/repos/TargetRepo where TargetRepo would be the name of a given project.

This is not a big deal, but it would be better if I could simplify the process of moving to whichever project I wanted to. I could do just that thanks to this simple solution found on Stack Overflow (new window). I’m expanding slightly on it here so I know I’ll find it if I need it again, and because I’m convinced it can be useful to others too.

Continue reading

GIT alias: List all branches

Using GIT? Quick tip of the day: Add the line below to the  [alias] section of your .gitconfig file (you should find it in your home directory). This will let you quickly list all the branches available for a repo.

brl = branch --list --all

Save the file, and try the following command in a GIT window:

git brl

You should see a list of all available branches for the repo, both remote and local, with an asterisk marking the branch you currently have checked out: