{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ff8c0f2b-eee1-4078-9812-52f1d8192e50",
   "metadata": {},
   "source": [
    "```{index} development tools\n",
    "```\n",
    "\n",
    "(development-tools)=\n",
    "\n",
    "# Development Tools\n",
    "\n",
    "The tools required for this book include the .NET SDK, VS Code, and the C# extension\n",
    "(a VS Code extension). In addition, we will also use the command line interface\n",
    "(CLI, the Command Prompt in Windows or shell in macOS/Linux, or just “the terminal”)\n",
    "for certain operations from time to time.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f4597ac",
   "metadata": {},
   "source": [
    "## .NET & .NET SDK\n",
    "\n",
    "**.NET** (pronounced \"dot net\") is a free, open-source, cross-platform framework developed and maintained by Microsoft. It provides the runtime environment, libraries, and tools needed to build and run applications on Windows, macOS, and Linux. Originally released as the Windows-only **.NET Framework** in 2002, Microsoft later rebuilt it from the ground up as the cross-platform **.NET Core**, which has since evolved into the unified **.NET** platform (starting with .NET 5 in 2020). Today, .NET is one of the most widely used application development platforms in the industry.\n",
    "\n",
    "At the heart of .NET is the **Common Language Runtime (CLR)**, which manages program execution — handling memory allocation, garbage collection, and type safety so that developers can focus on application logic rather than low-level system management. .NET also ships with a rich **Base Class Library (BCL)** offering thousands of built-in types and utilities for tasks ranging from file I/O and networking to cryptography and data access. Languages such as C#, F#, and Visual Basic (VB.NET), along with third-party languages, all compile to a common intermediate language that runs on the CLR, making .NET a true multi-language platform."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1a86e20",
   "metadata": {},
   "source": [
    "### The .NET SDK\n",
    "\n",
    "A software development kit (SDK) is a collection of software development tools in one installable package.\n",
    "They facilitate the creation of applications by having a *compiler*, debugger and sometimes a software framework.\n",
    "SDKs are normally specific to a hardware platform and operating system combination."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01dd0dab",
   "metadata": {},
   "source": [
    "### .NET Runtime\n",
    "\n",
    "  As part of the .NET SDK, the **.NET runtime** is a virtual machine that converts the compiled intermediate code into\n",
    "  machine code to be executed on the CPU. In addition, the .NET runtime provides an environment, that performs\n",
    "  services such as exception handling and garbage collection."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba5c98ce",
   "metadata": {},
   "source": [
    "## Terminal Apps & Shell\n",
    "\n",
    "Having some knowledge of using the command line interface (CLI, often referred to as command prompt in Windows,\n",
    "“shell” in Linux/macOS, or *command line*/*terminal* in general) is necessary when learning how to code. Major operating systems all have CLIs for users to interact with the operating system by issuing text commands in the terminal rather than using the graphical user interface (GUI). Different operating systems are shipped with different default terminal applications (or “terminal emulators” as they emulate the locally-attached dumb terminals in the old time).\n",
    "\n",
    "When we open a terminal application, a default *shell* program is running as a command line interpreter program\n",
    "that takes **commands** (therefore \"command line\") from users for the computer to execute. The terminal applications can run\n",
    "different shells and they work similarly. We use the shell languages to, e.g., move around the OS directory structure, manipulate files and folders, and manage software packages, etc.\n",
    "\n",
    "| OS | Common Terminal App | Common Shell Language |\n",
    "| ---| ---- | ---- |\n",
    "| macOS | Terminal.app |  Bash, Zsh |\n",
    "| Linux Desktop | GNOME Terminal, Konsole, etc.  | usually Bash |\n",
    "| Windows | PowerShell, Terminal, Command Prompt (CMD.exe) | PowerShell, Batch |\n",
    "\n",
    "When you open the CLI application, you use the keyboard (without a mouse) to issue shell commands (note that in most modern systems, you can still use a mouse for highlighting and copy-n-paste). In the terminal, you see a **shell prompt** followed by a **cursor** (maybe blinking), which is where you type to issue your commands.\n",
    "\n",
    "::::{tab-set} \n",
    "\n",
    ":::{tab-item} Windows (PowerShell)\n",
    "```console\n",
    "C:\\Users\\user_name>\n",
    "```\n",
    ":::\n",
    ":::{tab-item} macOS / Linux (Bash)\n",
    "```console\n",
    "user_name@computer_name:~$\n",
    "```\n",
    ":::\n",
    "::::\n",
    "\n",
    "For Windows users, you may issue `wsl` to switch from the default PowerShell to Windows Subsystem for Linux (WSL)\n",
    "to use Bash as your shell. Your command prompt will change to `user_name@computer_name:/mnt/c/Users/user_name$`.\n",
    "For the purpose of this book, you may use PowerShell and use the Bash commands with a slightly different interface.\n",
    "\n",
    "Unix-like OSs (such as Unix, macOS, and Linux) system are file-based, meaning the design principle dictates that\n",
    "everything in the system is a file, and the files are organized as a tree-like file system structure. In the\n",
    "command line, a *file path* is then used to specify the location of a file in a the computer's file system structure.\n",
    "The file system structure begins with the root (`/`), with a number of default first level directories representing the\n",
    "functionalities. For example, oen of the first the default location after logging in is the user's home directory, which is specified\n",
    "as /home/USER_NAME.\n",
    "\n",
    "> :::{figure} ../../images/linux_directory_tree.gif\n",
    "> :scale: 80%\n",
    ">\n",
    "> A hypothetical Linux directory tree\n",
    "> :::\n",
    "\n",
    "To start navigating around the file system structure, some of the essential commands include:\n",
    "\n",
    "- `ls` (list storage) to show the files and directories in the current directory\n",
    "- `pwd` (present working directory) to see the full path of the current directory\n",
    "- `mkdir` *folder* (make directory) to create a new directory called *folder*\n",
    "- `cd *path*` (change directory) to change in the *path* directory in the directory tree structure (path \"..\" means the upper level directory).\n",
    "- `^+C` (hold the Control key and then hit the C key) to terminate a process.\n",
    "- `touch *filename*` (Mac) to create an empty file.\n",
    "- `new-item *filename*` (PowerShell) to create an empty file.\n",
    "- `exit` to exit out of the terminal app.\n",
    "\n",
    "Some special pathname characters are commonly used for specifying paths:\n",
    "\n",
    "- `/` is the root of the system's file directory tree structure\n",
    "- `~` is the user's home directory\n",
    "- `..` is the pathname of the directory one-level up of the current directory\n",
    "- `.` means the current directory; but when placed at the beginning of a file, it makes the file a hidden file."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6288374",
   "metadata": {},
   "source": [
    "### Creating Directories and Files\n",
    "\n",
    "To create a project diretory and a test file, do the following:\n",
    "1. Terminal application: Open your terminal app (Windows PowerShell or macOS Terminal).\n",
    "2. Create directories:\n",
    "\n",
    "> 1.  Create a directory called `workspace` in your home directory (`mkdir workspace`), then change directory into the workspace directory (`cd workspace`)\n",
    "> 2.  Create a directory called `tests` in the workspace directory ((`mkdir tests`)), then change directory into the tests directory (`cd tests`).\n",
    "\n",
    "1.  Create a file: Create an empty file called test.txt (`new-item test.txt` for Windows and `touch test.txt` for macOS).\n",
    "2.  Make sure the files is created: Use the list storage command (`ls` then Enter) to list the files to make sure the file test.txt is created.\n",
    "3.  Change directory to your user home directory: Change your location back to the user home directory (`cd ../..`).\n",
    "4.  Exit out of terminal app: `exit` then Enter to exit.\n",
    "\n",
    "The whole process should look similar to this in Windows:\n",
    "\n",
    "```powershell\n",
    "\n",
    "PS C:\\Users\\[username]> mkdir workspace                 ### create the workspace directory in user home directory\n",
    "PS C:\\Users\\[username]> cd workspace                    ### change directory into workspace\n",
    "PS C:\\Users\\[username]\\workspace> mkdir tests           ### create the tests directory\n",
    "PS C:\\Users\\[username]\\workspace> cd tests              ### change into the test directory\n",
    "PS C:\\Users\\[username]\\workspace\\tests> new-item test.txt   ### create an empty file; use \"touch test.txt\" if you use macOS.\n",
    "PS C:\\Users\\[username]\\workspace\\tests> ls              ### list storage to see the file\n",
    "test.txt\n",
    "PS C:\\Users\\[username]\\workspace\\tests> cd ../..        ### change to the upper directory twice to user home directory\n",
    "PS C:\\Users\\[username]>exit                             ### exit --> Enter to leave the terminal\n",
    "```\n",
    "\n",
    "\n",
    "If you use macOS, the process should look similar enough:\n",
    "\n",
    ":::{figure} ../../images/shell_create_workspace_tests.jpg\n",
    ":scale: 35%\n",
    "\n",
    "Creating a workspace directory, tests subdirectory, and a test file in macOS.\n",
    ":::\n",
    "\n",
    "Note that:\n",
    "- To rename a file or a directory, use the `mv` (“move”) command. For example:\n",
    "`mv ist_1551 introcscs` will rename a folder called ist_1551 to introcscs.\n",
    "- To remove/delete a file, use `rm *file_name*`.\n",
    "- To remove an empty directory, use `rmdir *directory_name*`.\n",
    "- To remove a directory and all its content, use `rm -rf *directory_name*`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c853e986",
   "metadata": {},
   "source": [
    "## IDE\n",
    "\n",
    "Integrated development environment (IDE) applications play a critical role in software development workflow and\n",
    "usually contains tools such as source-code editor, build automation tools, and a debugger.\n",
    "IDEs commonly used by professionals developers are: Visual Studio Code, Visual Studio, IntelliJ IDEA, Notepad++, and Vim.\n",
    "\n",
    "Visual Studio Code (VS Code) is an editor with plenty of features. It has turned from a text\n",
    "editor into an integrated development editor (IDE) with a large number of\n",
    "extensions available to enhance and enrich its tools and features. A great advantage of learning\n",
    "VS Code is that it is extremely versatile. Once you learn how to use it, you can use it for\n",
    "almost every other programming languages and technology as long as they involve editing and coding.\n",
    "\n",
    ":::{figure} ../../images/popular_ide.jpg\n",
    ":scale: 25%\n",
    "\n",
    "Visual Studio Code remains the preferred IDE across all developers. [^1]\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dea762b1",
   "metadata": {},
   "source": [
    "### VS Code\n",
    "\n",
    "The Visual Studio Code (VS Code) editor, powered by plenty of extensions, has made the editor a very powerful tool for coding and programming and worth learning.\n",
    "\n",
    "The popular IDE/editor VS Code user interface include several panes:\n",
    "\n",
    "1.  Activity Bar - Where you change Views. For example, the default view is Explorer (<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\"><path d=\"M7.5 22.5H17.595C17.07 23.4 16.11 24 15 24H7.5C4.185 24 1.5 21.315 1.5 18V6C1.5 4.89 2.1 3.93 3 3.405V18C3 20.475 5.025 22.5 7.5 22.5ZM21 8.121V18C21 19.6545 19.6545 21 18 21H7.5C5.8455 21 4.5 19.6545 4.5 18V3C4.5 1.3455 5.8455 0 7.5 0H12.879C13.4715 0 14.0505 0.24 14.4705 0.6585L20.3415 6.5295C20.766 6.954 21 7.5195 21 8.121ZM13.5 6.75C13.5 7.164 13.8375 7.5 14.25 7.5H19.1895L13.5 1.8105V6.75ZM19.5 18V9H14.25C13.0095 9 12 7.9905 12 6.75V1.5H7.5C6.672 1.5 6 2.1735 6 3V18C6 18.8265 6.672 19.5 7.5 19.5H18C18.828 19.5 19.5 18.8265 19.5 18Z\"/></svg>) for managing files.\n",
    "2.  Primary Side Bar\n",
    "3.  Editor\n",
    "4.  Panel (toggled by <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\"><path d=\"M15 12.5C15 13.881 13.881 15 12.5 15H3.5C2.119 15 1 13.881 1 12.5V3.5C1 2.119 2.119 1 3.5 1H12.5C13.881 1 15 2.119 15 3.5V12.5ZM2 10H14V3.5C14 2.672 13.328 2 12.5 2H3.5C2.672 2 2 2.672 2 3.5V10Z\"/></svg> where TERMINAL resides)\n",
    "5.  Status Bar\n",
    "\n",
    "**Activity Bar**: In the Activity Bar on the left of the window, you can access different\n",
    "Views such as:\n",
    "\n",
    "> 1.  Search - Provides global search and replace across your open folder.\n",
    "> 2.  Source Control - VS Code includes Git source control by default.\n",
    "> 3.  Run - VS Code’s Run and Debug View displays variables, call stacks, and breakpoints.\n",
    "> 4.  Extensions - Install and manage your extensions within VS Code.\n",
    "> 5.  Custom views - Views contributed by extensions.\n",
    ">\n",
    "> :::{figure} ../../images/vscode_interface.jpg\n",
    "> :scale: 50%\n",
    ">\n",
    "> Basic elements in VS Code user interface\n",
    "> :::\n",
    "\n",
    "**Terminal**: In the Panel section ({{ vscode_toggle }}), you have access to the TERMINAL and other console tabs. Note that:\n",
    "\n",
    "> - The TERMINAL is exactly the same as your terminal application.\n",
    ">\n",
    "> - When you open a project by issuing `code .` in the project directory, the terminal will be default\n",
    ">   to the project directory.\n",
    ">\n",
    "> - You may use Cmd+J (Ctl+J) to toggle the Panel to use the terminal.\n",
    "\n",
    "**Command Palette**: In addition to the UI elements, an important key combination to learn is\n",
    "`Ctl + Shift + P` on Windows and Linux, or `Shift + Command + P` on Mac. Command\n",
    "palette gives access to all the functionalities within VS Code. For example,\n",
    "if you type `.NET` at the command palette, you get to access the .NET commands\n",
    "and features as follows.\n",
    "\n",
    ":::{figure} ../../images/command_pallette_dontnet.jpg\n",
    ":scale: 25%\n",
    "\n",
    "Using vscode Command Palette\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae27425c",
   "metadata": {},
   "source": [
    "## C# REPL (`csharprepl`)\n",
    "\n",
    "While VS Code and .NET templates have made coding C# easy, a REPL (Read–Evaluate–Print-Loop, or language **shell**/**interpreter**) provides immediate evaluation (execution and result return), which can be very useful as you get to see immediate feedback of your code. This means direct **execution** of C# code without creating projects and files, which is very handy for learning and testing syntax.\n",
    "\n",
    "To use C# REPL ([CSharpRepl](https://github.com/waf/CSharpRepl)):\n",
    "\n",
    "- Installation: CSharpRepl can be installed by issuing `dotnet tool install -g csharprepl` at command line.\n",
    "- Invocation: CSharpRepl is invoked by using the `csharprepl` command at command line.\n",
    "\n",
    "We want to use start by using `csharprepl` so that we can run some\n",
    "quick-and-dirty C# code for practice and testing purposes.\n",
    "\n",
    "```powershell\n",
    "PS C:\\Users\\[username]\\test> csharprepl\n",
    "Welcome to the C# REPL (Read Eval Print Loop)!\n",
    "Type C# expressions and statements at the prompt and press Enter to evaluate them.\n",
    "Type help to learn more, exit to quit, and clear to clear your terminal.\n",
    "\n",
    ">\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf1ee2a6",
   "metadata": {},
   "source": [
    "The `>` prompt tells you that the C# interpreter has started and is awaiting input. This allows you to test C# code interactively without having to create a project, modify it, save it, and run `dotnet run` to test it.\n",
    "\n",
    "When you are done with `csharprepl`, you can enter `exit` to quit the shell.\n",
    "\n",
    "The *repl* part in csharprepl is an acronym for the *Read-Evaluate-Print Loop* (REPL). A REPL is a language shell provides simple interactive computer programming environment that runs code piecewise. It evaluates expressions immediately and prints the result on a line without a prompt. The REPL can evaluate arbitrary C# expressions. It is very handy for testing as you get used to C# syntax."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2685a17",
   "metadata": {},
   "source": [
    "### Expressions in C# REPL\n",
    "\n",
    "Start csharprepl and enter what comes after the prompt and the REPL prints the results directly. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e779c14a",
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "source": [
    "```csharp\n",
    "> 2 + 3\n",
    "5\n",
    "> \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4eb7928a",
   "metadata": {},
   "source": [
    "```csharp\n",
    "> 10 -3\n",
    "7\n",
    "> \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1dea16d",
   "metadata": {},
   "source": [
    "In the Math class, you could enter something like 4(10) for multiplication, but in C#, you need to use the multiplication operator `*`:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8621700",
   "metadata": {
    "vscode": {
     "languageId": "csharp"
    }
   },
   "source": [
    "```csharp\n",
    "> 4*10\n",
    "40\n",
    ">\n",
    "``` "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2722b061",
   "metadata": {},
   "source": [
    "## Other Development Tools\n",
    "\n",
    "There are plenty of development tools that are worthy of our time to learn, except that we would\n",
    "not be able to learn all of them in one semester. A short list of those tools would include:\n",
    "\n",
    "- Version Control (such as GitHub)\n",
    "- Containerization (Docker)\n",
    "- Shell Scripting (Bash)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7609bce4",
   "metadata": {},
   "source": [
    "## Git Workflow Basics\n",
    "\n",
    "Version control protects your progress and enables team collaboration."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33800c9c",
   "metadata": {},
   "source": [
    "### Core habits\n",
    "\n",
    "1. Commit small logical changes.\n",
    "2. Write meaningful commit messages.\n",
    "3. Pull before starting major work.\n",
    "4. Avoid mixing unrelated changes in one commit."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6cb95ab7",
   "metadata": {},
   "source": [
    "### Suggested single-developer loop\n",
    "\n",
    "```bash\n",
    "git pull\n",
    "git status\n",
    "git add <files>\n",
    "git commit -m \"Implement CSV parsing validation\"\n",
    "git push\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da1208e9",
   "metadata": {},
   "source": [
    "### Suggested team loop\n",
    "\n",
    "```bash\n",
    "git checkout -b feature/score-summary\n",
    "# work + tests\n",
    "git add <files>\n",
    "git commit -m \"Add score summary report\"\n",
    "git push -u origin feature/score-summary\n",
    "```\n",
    "\n",
    "Then open a pull request and request review."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "311f69f4",
   "metadata": {},
   "source": [
    "### Commit message quality\n",
    "\n",
    "Weak:\n",
    "\n",
    "- `\"update\"`\n",
    "\n",
    "Strong:\n",
    "\n",
    "- `\"Validate malformed CSV rows before parsing scores\"`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b876f25",
   "metadata": {},
   "source": [
    "### Merge conflict basics\n",
    "\n",
    "When conflict markers appear:\n",
    "\n",
    "1. read both versions carefully\n",
    "2. decide final merged code\n",
    "3. remove markers\n",
    "4. run tests\n",
    "5. commit merge result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "footnotes",
   "metadata": {},
   "source": [
    "```{rubric} Footnotes\n",
    "```\n",
    "\n",
    "[^1]: For a comprehensive introduction to the interface of VS Code, see: <https://code.visualstudio.com/docs/getstarted/userinterface>\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}