Skip to content

Latest commit

 

History

History
475 lines (309 loc) · 11.1 KB

main.md

File metadata and controls

475 lines (309 loc) · 11.1 KB

Sciware

Tools to make programming easier

Intro to code editors and debugging

https://github.com/flatironinstitute/learn-sciware-dev/tree/main/16_EditorsVSCode

Rules of Engagement

Goal:

Activities where participants all actively work to foster an environment which encourages participation across experience levels, coding language fluency, technology choices*, and scientific disciplines.

*though sometimes we try to expand your options

Rules of Engagement

  • Avoid discussions between a few people on a narrow topic
  • Provide time for people who haven't spoken to speak/ask questions
  • Provide time for experts to share wisdom and discuss
  • Work together to make discussions accessible to novices
(These will always be a work in progress and will be updated, clarified, or expanded as needed.)

Zoom Specific

  • If comfortable, please keep video on so we can all see each other's faces.
  • Ok to break in for quick, clarifying questions.
  • Use Raise Hand feature for new topics or for more in-depth questions.
  • Please stay muted if not speaking. (Host may mute you.)
  • We are recording. Link will be posted on #sciware Slack.

Future Sessions

  • Chat & office hour: Jul 22 3-4pm
  • Blender tutorial for scientific visualization animations
  • Suggest topics and vote on options in #sciware Slack

Today's agenda

  • Introduction
  • Examples and demos of features
  • Help with setting up your own environment

How can you code faster?

What do you spend time doing (other than thinking about logic)? Translating ideas into code:

  • is this the right syntax?
  • what was that function called? what are the arguments?
  • what is in this variable?
  • does it compile? does it run?
  • trial-and-error, looking at documentation
  • repetitive editing tasks
  • saving and switching files

What is an IDE?

Integrated Development Environment

(or just "editor")

  • an interactive environment (tool or program)
  • for developing (writing, editing) code
  • that integrates other features
  • designed to make it easier to write code all in one place

Text editor

  • Most IDEs are, at the core, a text editor
  • Fancy "spell checker" (variables, functions, syntax), autocomplete
  • Aware of code structure, projects, programming language, libraries
  • Integrated tools for running, compiling, testing, debugging, checking, documenting, sharing, ...
  • No need to switch to terminal to run/build, web browser to look up documentation, ...

Old school options (evolved text-editors)

  • emacs: old UNIX editor, CTRL-heavy (C-x C-c), many optional extensions, fully functional programming environment (1976)
  • vim: based on vi (vi improved), old UNIX editor, heavy on single-key short cuts ("modal"), many optional extensions with IDE functionality (1991)
  • Notepad++: in the tradition of Notepad, open-source Windows editor (2003)

Learning curves

Newer options

  • Sublime Text: proprietary editor with fancy navigation, focused on MacOS (2008)
  • PyCharm, Spyder: python-specific IDEs with focus on debugging (2010)
  • Atom: open-source cross-platform editor from Github, "web" (js) based, can be a bit slow (2014)
  • Visual Studio Code ("vscode"): open-source cross-platform editor from Microsoft (2015)
    • not to be confused with MS Visual Studio, an older Windows IDE (1997)

Today

  • You'll see examples of a number of features
  • Get a sense of what's possible
  • No need to follow along on your own, live
  • Slides can be used as reference to come back and try later
  • Most features exist in many other editors (sometimes with plugins, extensions)

Basic functionality

Jeremy Magland & Jeff Soules (CCM)

https://github.com/jsoules/vs-code-introduction

Workspaces, integrated execution and debugging

David Silva Sanchez (CCM)

Workspaces

Workspaces are a quality of life feature of vscode that let you:

  • Save which folders you are using.
  • Configure settings that only apply to said folders.
  • Set tasks (compiling/running) and debugging configurations.
  • Store and restore UI state associated with that workspace (opened files, tab order, ...)
  • Enable or disable extensions only for that workspace.

Creating a workspace

Open the folder(s) you will use

Save workspace

Load workspace

Integrated execution

Execute python codes without a terminal!

Select your python interpreter

Press Ctrl+Shift+p and look for "python: Select interpreter"

Run your code!

Press Ctrl+F5 or press the green arrow

Compile and Debug c++ code

Create a task file

It tells VSCode how to compile your code

Compiling the code

After you create the task file just press Ctrl+Shift+B!

Examples

Compiling with g++

{
 "version": "2.0.0",
 "tasks": [
  {
   "type": "cppbuild",
   "label": "Build .cpp file", //Remember this label!
   "command": "/usr/bin/g++", //Compiler
   "args": [
    "-g",
    "${workspaceFolder}/simple_addition.cpp",
    "-o",
    "${workspaceFolder}/simple_addition.out"
   ],
   "options": {
    "cwd": "${fileDirname}"
   },
   "problemMatcher": [
    "$gcc"
   ],
   "group": {
    "kind": "build",
    "isDefault": true
   },
   "detail": "compiler: /usr/bin/g++"
	 }
 ]
}

Compiling with make

{
 "version": "2.0.0",
 "tasks": [
  {
   "type": "shell",
   "label": "Build .cpp file", //Remember this name!
   "command": "make",
   "group": {
    "kind": "build",
    "isDefault": true
   }
  }
 ]
}

Create a launch file

Defines how the debugging goes

Starting a debugging session

Press F5 for starting the session

Examples

For c++

{
 "version": "0.2.0",
 "configurations": [        
   {
    "name": "(gdb) g++ buld and debug",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/simple_addition.out",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceFolder}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
     {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
     }
    ],
    "preLaunchTask": "Build .cpp file"
   }
 ]
}

For python

{
 "version": "0.2.0",
 "configurations": [
  {
   "name": "Python: Specific file",
   "type": "python",
   "request": "launch",
   "program": "${workspaceFolder}/simple_addition.py",
   "console": "integratedTerminal"
  }
 ]
}

Debugging options

Breakpoints

Types of breakpoints

  • Normal breakpoints: "Breaks" the execution of the code when it is hit.
  • Conditional breakpoints:
    • Expression condition: The breakpoint will "break" execution whenever the expression evaluates to True
    • Hit count: "Breaks" execution only if it has been hit a particular number of times
  • Inline breakpoints: Only are hit when the execution reaches a specific line and column.

Debugging Actions

  • Continue/Pause (F5)
  • Step Over (F10)
  • Step Into (F11)
  • Restart (Ctrl+Shift+F5)
  • Stop (Shift+F5)

Step Over

Step Into

Step Out

Watch Variables

Remote environments

Wen Yan (CCB)

Working on Remote Clusters

All of the cool features you've seen so far, can be used when editing remote files, i.e. on a cluster!!

How It Works

What You Can Do

  • View, move, and reorganize directories
  • Edit files
  • Debug
  • Static linting
  • Formatting
  • View figures

Bonus: Setup

  1. Get OpenSSH compatible SSH client
  2. Download the Remote SSH extension for VSCode
  3. Enable key-based authentication, see the VSCode docs for details
  4. From the VSCode command palette search for Remote-SSH: Connect to Host
  5. Enter your username and host info, e.g. jasm3285@login.colorado.edu

See the official instructions here

Customization

Adam Lamson (CCB)

Links and resources

Finding, adding, and editing shortcuts

  • Most shortcuts begin with cmd, alt, or ctrl depending on system.
  • Shortcut for editing your shortcuts:
    • (Mac) cmd + K cmd + S
    • (Windows/Linux) ctrl + K ctrl + S
  • If you find yourself using one task a lot. Find or make a shortcut for it!
    • Tip: Don't be clever. Use the combination that first comes to mind.
  • Cheatsheets: macOS, Windows, Linux

JSON keybinding and settings file

Why

  • Often easier to edit file directly instead of using UI
  • Easily copy settings other people recommend
  • Transfer settings over to other machines

How

Some useful shortcuts to add to

  • Move through open tabs quickly
    {
        "key": "ctrl+n",
        "command": "workbench.action.nextEditor",
    },
    {
        "key": "ctrl+p",
        "command": "workbench.action.previousEditor",
    },
  • Quick file search
    {
        "key": "cmd+p",
        "command": "workbench.action.quickOpen"
    },
  • Open and edit keybindings and settings
   {
        "key": "cmd+;",
        "command": "workbench.action.openGlobalKeybindings"
    },
    {
        "key": "cmd+.",
        "command": "workbench.action.openSettingsJson"
    },

Other things to play around with

Color theme

  • Access with cmd + k cmd + t
  • Plenty of themes in extensions

Other editor keymaps

  • Vim, Emacs, Sublime, etc.

Survey

https://bit.ly/sciware-IDEs

Questions & Help