{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "de55150d-5d65-406a-8d24-5e3777cdbc79",
   "metadata": {},
   "source": [
    "# Work Environment"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91f3f340",
   "metadata": {},
   "source": [
    "## Editing Tools\n",
    "\n",
    "For most programming languages, including Python, there are many tools you can use to write and run programs. Some of the code-editing development tools are full-featured integrated development environments (IDEs), some are lightweight code editors, while others are specialized development environment such as Jupyter and Google Colab.\n",
    "\n",
    "- Full IDEs like PyCharm, IntelliJ, and Visual Studio are comprehensive environments designed for full-scale software development: building complete applications, managing large codebases, and collaborative development. They're the standard choice for professional software engineering where you need structure, performance, and the ability to handle complex projects. Full IDEs have comprehensive tooling: debuggers, refactoring, testing frameworks, and project management. They're heavier but more powerful for large projects. [PyCharm ](https://www.jetbrains.com/pycharm/) is a popular IDE for both learners and professionals, [VS Code](https://code.visualstudio.com/) is a code editor turned full IDE through extensions. \n",
    " \n",
    "- Code editors like Visual Studio Code (VS Code), Sublime Text, and Atom are lightweight tools for writing and editing code with features like syntax highlighting and basic autocomplete. They're fast to start up, use minimal resources, and have a simple interface. \n",
    "\n",
    "- Terminal-based editors like **nano** and **vim** run directly in the command line with no graphical interface. Nano is beginner-friendly; vim has a steeper learning curve but is highly efficient once mastered. Both are available on virtually every Unix/Linux/macOS system and are useful when working over SSH or in environments without a GUI. On Windows, **Notepad** is a built-in plain-text editor — minimal, but sufficient for quick edits.\n",
    "\n",
    "- Jupyter Notebook is a specialized development tool. It's an interactive, cell-based environment primarily designed for data analysis, scientific computing, and exploration. You write code in individual cells that you can execute independently, and results (including visualizations and formatted text) appear immediately inline below the cell. Jupyter supports mixing code, markdown documentation, equations, and outputs in a single document, making it excellent for data science.\n",
    "\n",
    "As you progress in learning how to code, you may find VS Code and PyCharm more useful when you mainly work on coding rather than data flow and documentation. If you are just getting started, I strongly recommend you start with Jupyter Notebook.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c42034f-682b-4008-8643-a5f082a1a649",
   "metadata": {},
   "source": [
    "## The File System\n",
    "\n",
    "Unix-like OSs (such as Unix, macOS, and Linux) systems are file-based, meaning the design principle dictates that everything in the system is a file, and the files are organized as a tree-like file system structure following the [Filesystem Hierarchy Standard](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard). In the CLI, a file **path** is then used to access a file or a directory/folder in the computer’s hierarchical file structure in the absence of a GUI. \n",
    "\n",
    "The file system structure begins with the **root** (`/`), which contains several default first-level directories representing various functionalities. For example, one of the first default locations after logging in is the user’s home directory, which is specified as `/home/USER_NAME`. A typical Unix-like system would have a system directory structure similar to {numref}`linux_directory_tree`. Note that in {numref}`linux_directory_tree`, there is a number of first-level directories under the root directory, and there are two user directories (\"bill\" and \"patrick\") under the home directory, where all user accounts are created under. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "082edfd1-3f74-4a92-884f-b78d8dd2669b",
   "metadata": {},
   "source": [
    "```{figure} ../../images/linux_directory_tree.gif\n",
    ":name: linux_directory_tree\n",
    ":alt: linux_directory_tree\n",
    ":width: 75%\n",
    ":align: center\n",
    "\n",
    "[A Linux Directory Tree Example](https://www.oreilly.com/openbook/debian/book/ch04_03.html)\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77a6cc11-0433-4ae8-9dd2-1617bba25650",
   "metadata": {},
   "source": [
    "Similarly, in Windows, files and directories are organized in a hierarchical structure; except that drive letters such as `C:` and `D:` are used for separate file structure roots, while Linux uses a unified, hierarchical structure starting from a single **root** (/) for all drives and devices. In {numref}`windows11-directory-c-drive`, you see that, in File Explorer, if you click on `C:`, there is a number of folders and files organized under the `C:` drive, just like the root in Linux."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18951042-bf3f-4fb4-931f-52e8ffe3175a",
   "metadata": {},
   "source": [
    "```{figure} ../../images/windows11-directory-c-drive.png\n",
    ":name: windows11-directory-c-drive\n",
    ":alt: windows11-directory-c-drive\n",
    ":width: 75%\n",
    ":align: center\n",
    "\n",
    "Windows 11 Directory C: Drive\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fe19608-bd72-4a7f-9e40-fa360b7ca597",
   "metadata": {},
   "source": [
    "If you click to expand the `Users` folder, File Explorer will display the folders (usernames) contained within it. When you select to highlight a username, you will see all the files and directories of that user. In this example in {numref}`windows11-directory-user`, a folder called **`workspace`** is highlighted. \n",
    "\n",
    "Note that, in the CLI, this user folder is the default location when a user first logs in. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ab89182-815e-4a69-90d1-eec0744a3156",
   "metadata": {},
   "source": [
    "```{figure} ../../images/windows11-directory-user.png\n",
    ":name: windows11-directory-user\n",
    ":alt: windows11-directory-user\n",
    ":width: 75%\n",
    ":align: center\n",
    "\n",
    "Windows 11 Directory Hierarchy from C: Drive to User Home Directory\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c160bf1b-7338-454d-b4de-2a6afe3ff047",
   "metadata": {},
   "source": [
    "## The Command Line"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3530dfc",
   "metadata": {},
   "source": [
    "Having some knowledge of using the command line interface (CLI) is necessary when learning how to code. A CLI is often referred to, interchangeably, as the _command prompt_ in Windows, **shell** in Linux/macOS, or **command line** or **terminal** in general. Major operating systems (OSs) all have CLIs for users to interact with the operating system by issuing text commands in the CLI rather than using GUIs for speed, automation, and granular control. (For a discussion on terminology such as terminal, console, and shell, see [here](https://www.hanselman.com/blog/whats-the-difference-between-a-console-a-terminal-and-a-shell).\n",
    "\n",
    "\n",
    "Different OSs are shipped with different CLIs, which include: \n",
    "- **Terminal**: A terminal is an application (or “terminal emulators” as they emulate the locally-attached dumb terminals) to access the shells.\n",
    "- **Shell**: A shell is a command-line interface for the user to issue commands to the operating system.\n",
    "- **REPL**: A REPL (Read–Eval–Print Loop) is an interactive programming environment for a specific language. \n",
    "\n",
    "In summary, terminals are programs like Windows PowerShell/Command Prompt, macOS Terminal.app, or Linux Terminal that you open to access the `shell`. A shell is a command-line **interpreter**. Note that a GUI is also considered a shell as it interfaces with the OS.\n",
    "\n",
    "While a terminal can support multiple shells, each shell performs the same core function of interacting with the operating system. Major OSs and their default or commonly used shells are:\n",
    "\n",
    "| OS | Terminal Emulator | Common Shell |\n",
    "|---------|----------|----------------------------|\n",
    "| Windows | Windows Terminal | PowerShell, Batch (command prompt, CMD) |\n",
    "| macOS   | Terminal | Bash, Zsh              |\n",
    "| Linux distributions |  GNOME, Konsole | Bash |\n",
    "\n",
    "In addition, it is also common to refer to the CLI interpreter of a computer programming language as `shell`, such as Python shell for Python or `CSharpRepl` for C#."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57dd62e4-e8f9-4ad8-9e7e-15bf26d41424",
   "metadata": {},
   "source": [
    "When you open the CLI terminal application, you mainly use the keyboard, rather than a mouse, to issue text commands (you can still mostly use the mouse to highlight and copy/paste text). In order to do that, some special pathname characters are commonly used (and are supported by major shells such as Bash and PowerShell):\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 from 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": "31c3b169-079a-4a2f-81bd-240b6fb8139c",
   "metadata": {},
   "source": [
    "In addition to pathnames, to start navigating around the file system directory structure, some of the essential commands are helpful:\n",
    "\n",
    "- `ls` (list storage) to show the files and directories in the current directory\n",
    "- `cd` *path* (change directory) to change in the path directory in the directory tree structure (path “..” means the upper level directory).\n",
    "- `touch` *filename* to create an empty file.\n",
    "- `rm` *filename* to remove a file.\n",
    "- `mkdir` *foldername* (make directory) to create an empty directory.\n",
    "- `pwd` (print working directory) to see the full path of the current location.\n",
    "- `cat` *filename* to display the contents of a file.\n",
    "- `cp` *source_file destination* to copy a file\n",
    "- `^+C` (hold the Control key and then hit the C key) to terminate a process.\n",
    "- `exit` to exit out of the terminal app."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "a22b0ac4-5fc8-44d3-ab04-cda7eb189ff8",
   "metadata": {},
   "source": [
    "To start a **terminal session** in Windows, you search for *PowerShell*, and you will see **Windows PowerShell** as an App. For macOS/Linux, you search for **Terminal.app**. You then mouse-click on the application or press _Enter_ to open the terminal application and access the shell.\n",
    "\n",
    "In the shell, you see a **command prompt** (e.g., `[user]@computer_name:~$` for macOS/Linux or `C:\\Users\\[user]>` for Windows), followed by a cursor (may blink), which indicates where you type to issue your commands for execution."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98847e47-f22f-4b3d-a408-4a6686115c3f",
   "metadata": {},
   "source": [
    "In Windows, if you type the command `ls` and hit Enter to list storage, you see the directories and files listed:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "550968c0-46fd-4534-89cb-a1c2d0e3638d",
   "metadata": {},
   "source": [
    "```powershell\n",
    "PS C:\\Users\\[user]> ls\n",
    "    Directory: C:\\Users\\[user]\n",
    "Mode                 LastWriteTime         Length Name\n",
    "----                 -------------         ------ ----\n",
    "d-----        12/25/2025  10:46 PM                .dotnet\n",
    "d-----         8/30/2025  10:25 PM                .ipython\n",
    "d-----         8/31/2025  10:53 AM                .jupyter\n",
    "d-----         9/11/2025  12:01 AM                .ssh\n",
    "d-----          9/4/2025   7:59 PM                .vscode\n",
    "d-r---         8/30/2025   5:52 PM                Contacts\n",
    "d-r---         9/11/2025  12:35 AM                Desktop\n",
    "d-----         9/12/2025  10:27 AM                Documents\n",
    "...\n",
    "...\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b381a90e-3823-4bb5-a9a1-7425fc3de4d1",
   "metadata": {},
   "source": [
    "or, if you issue the same `ls` command in your macOS shell (default zsh or bash):"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38b9b90f-f5d0-4c5c-9c2a-07ac6c53238e",
   "metadata": {},
   "source": [
    "```bash\n",
    "[user]@computer:~$ ls\n",
    "Applications Documents    Google Drive Library      Music        Public       teaching     workspace\n",
    "Desktop      Downloads    GoogleDrive  Movies       Pictures     research     temps\n",
    "[user]@computer:~$ \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a497bde8-c367-4506-a507-e257b10fe0a9",
   "metadata": {},
   "source": [
    "To see the file details like in PowerShell, you need to issue the `ls` command with the _long format_ option `-l`:\n",
    "\n",
    "```bash\n",
    "[user]@[computer]:~$ ls -l \n",
    "total 0\n",
    "drwxr-xr-x   10 [user]  staff   320 Dec 18 15:14 Applications\n",
    "drwx------@  58 [user]  staff  1856 Dec 19 15:50 Desktop\n",
    "drwx------@  11 [user]  staff   352 Oct  2 22:46 Documents\n",
    "drwx------@ 271 [user]  staff  8672 Dec 28 22:36 Downloads\n",
    "lrwx------    1 [user]  staff    66 Dec 27 09:56 Google Drive -> /Users/[user]/Library/CloudStorage/GoogleDrive-[user]@gmail.com\n",
    "drwxr-xr-x@  21 [user]  staff   672 Dec 27 09:56 GoogleDrive\n",
    "drwx------+ 139 [user]  staff  4448 Oct  6 17:41 Library\n",
    "...\n",
    "...\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8f9dc04-b928-4c0a-bace-d3b166007886",
   "metadata": {},
   "source": [
    "## The Python Shell\n",
    "\n",
    "While shell languages such as bash and PowerShell communicate with operating systems, a programming language may have its own \"shell\" or **REPL** (Read-Eval-Print Loop), which serves as a command-line interactive environment for running code written in the programming language. This means that when you type code, the REPL interprets it and displays the results immediately. A REPL perfect for testing snippets, learning syntax, and exploring modules without creating files. Different languages have different REPLs, for example:\n",
    "\n",
    "| Language  | REPL   |\n",
    "|-----------|--------|\n",
    "| Python    | Python shell |\n",
    "| Java      | JShell   |\n",
    "| C#        | CSharpRepl |\n",
    "\n",
    "The Python interpreter features a built-in interactive shell (the **Python shell** or \"the interpreter\"), which is the standard Python REPL and is widely used for quickly testing code. To access the Python shell, you can start your terminal (PowerShell in Windows Terminal or Terminal in macOS) and type `python` or `python3` with Enter. You will see the primary prompt (aka, chevrons), <span style=\"color: white; background:darkblue\">**>>>**</span>, where you input code for immediate evaluation from the interpreter:  \n",
    "\n",
    "````{tab-set}\n",
    "```{tab-item} Windows\n",
    "```powershell\n",
    "PS C:\\Users\\[user]> python\n",
    "Python 3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32\n",
    "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
    ">>> 1 + 1\n",
    "2\n",
    ">>>\n",
    "```\n",
    "\n",
    "```{tab-item} macOS\n",
    "```bash\n",
    "[user]@[computer]:~$ python3\n",
    "Python 3.12.12 (main, Oct  9 2025, 11:07:00) [Clang 17.0.0 (clang-1700.3.19.1)] on darwin\n",
    "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
    ">>> 1 + 1\n",
    "2\n",
    ">>> \n",
    "```\n",
    "````"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "666fab34-bc4b-4552-a1b2-b31e27357fc8",
   "metadata": {},
   "source": [
    "In the Python shell, you may start experiencing Python programming by printing \"hello, world\":\n",
    "\n",
    "````{tab-set}\n",
    "```{tab-item} Windows\n",
    "```powershell\n",
    "PS C:\\Users\\[user]> python\n",
    "Python 3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32\n",
    "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
    ">>> print(\"hello, world\")\n",
    "hello, world\n",
    ">>>\n",
    "```\n",
    "\n",
    "```{tab-item} macOS\n",
    "```bash\n",
    "[user]@[computer]:~/workspace/dsm$ python\n",
    "Python 3.13.7 (main, Aug 14 2025, 11:12:11) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin\n",
    "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
    ">>> print(\"hello, world\")\n",
    "hello, world\n",
    ">>> \n",
    "```\n",
    "````"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb30607d-1965-4ab9-8cc2-64ce041e3f30",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
