\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=0.75in]{geometry}

% set up hyperlink coloring
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan
}

\setlength{\parindent}{0pt} % no indentation

\renewcommand{\familydefault}{\sfdefault} % default to sans serif

% code support: listings and fancy verbatim
\usepackage{listings}
\lstset{basicstyle=\ttfamily\footnotesize}
\usepackage{fancyvrb}

\renewcommand{\familydefault}{\sfdefault} % default to sans serif

%%%%%%%%%%%%%%%%
\begin{document}

\title{Homework 4\\Text Editors}
\author{EECS 201 Winter 2020}
\date{}
\maketitle

\section*{Submission Instructions}
Answer the bolded text that begins with a bolded number e.g. ``\textbf{1}'', ``\textbf{2}''.
Submit this assignment on \href{https://gradescope.com}{Gradescope}.
\textbf{When submitting please select the right pages for each question or we will not grade the question}.
You may find the free online tool \href{https://www.pdfescape.com}{PDFescape} helpful to edit and fill out this PDF.
You may also print, handwrite, and scan this assignment.
\\\\
If you feel enterprising, you can edit the TeX file directly, compile it to a PDF, and submit that!
I ask that if you do so, please make the answer text stand out from the rest of the homework.

\section*{\textit{Optional} Readings}
Previous iterations of this class included some optional readings with this week.
You may find the ideas and topics they bring up interesting.

\subsection*{Interrupting Developers and Makers vs Managers}
\medskip
\noindent
\url{http://thetomorrowlab.com/2015/01/why-developers-hate-being-interrupted/}\\
\textit{Why developers hate being interrupted}, by Derek Johnson at The Tomorrow Lab.

\noindent
\url{http://www.paulgraham.com/makersschedule.html}\\
\textit{Maker's Schedule, Manager's Schedule}, by Paul Graham, co-founder of Y~Combinator.

\subsection*{Software Engineering in the Real World}
\url{http://blogs.msdn.com/b/peterhal/archive/2006/01/04/509302.aspx}\\
\textit{What Do Programmers Really Do Anyway?}, by Peter Hallam, then-Microsoft~Developer
\begin{quote}
  \textit{%
    Why is 5 times more time spent modifying code than writing new code? The
    answer is that new code becomes old code almost instantly.  Write some new
    code. Go for coffee. All of sudden you've got old code.
  }
\end{quote}

\medskip
\noindent
\url{http://www.joelonsoftware.com/articles/fog0000000069.html}\\
\textit{Things You Should Never Do, Part I}, by Joel Spolsky
\begin{quote}
  \textit{It's harder to read code than to write it.}
\end{quote}

\medskip
\noindent
\textit{When was the last time you saw a hunt-and-peck pianist?} -Jeff Atwood,
co-founder of Stack Overflow and Discourse.\\
Some extras on the
\href{http://blog.codinghorror.com/we-are-typists-first-programmers-second/}
{value of being a good typist}
and
\href{http://blog.codinghorror.com/going-commando-put-down-the-mouse/}
{ditching the mouse for the keyboard}.


\newpage
\section{Trying out fancy features}
For this question, we'll be looking at the two big terminal editors: \texttt{vim} and \texttt{emacs}
and exploring their capabilities. 
You may choose either of them to work with for this question.

The intent of this question is to expose you to the more advanced features that other editors like
Microsoft Notepad or GNU \texttt{nano} may not have as well as building competency in terminal text editors.
I encourage you play around with the editors and look into the neat features that they have.
\\\\
\textbf{If you're using \texttt{emacs}, remember to run it in non-GUI mode i.e. \texttt{emacs -nw} for this question}.

\bigskip
\hrule
\vspace{1em}
To start, grab a copy of this file that's full of code:
\begin{quote}
  \texttt{\# Example from \url{http://web.mst.edu/~price/cs53/code_example.html}}\\
  \texttt{wget \url{http://web.mst.edu/~price/cs53/KatsBadcode.cpp}}
\end{quote}
\smallskip
\hrule
\bigskip

\begin{enumerate}
  \item Sometimes you will come across some ugly code. Your editor can help
    make it better. Open \texttt{KatsBadcode.cpp}. Among other issues, the
    really bad tabbing makes this hard to read.\\
    \textbf{1: Describe how to automatically fix the indentation for the whole file.}
    \vspace{10em}

    Now imagine if you are editing code and you determine you can
        remove an if block, for example removing the \texttt{if} on line~28 of
        \texttt{KatsBadcode} and running its body unconditionally. You need to
        fix the indentation level of all 20~lines of the body.\\
        \textbf{2: Describe how to change the indentation level of a block of code.}
        \vspace{10em}
  \item Editing one file is nice, but often it's really useful to compare
    files side-by-side (source and headers, spec and implementation).\\
    \textbf{3: Describe the command sequence to create a window split (within your
        text editor) side-by-side with your current window, switch to it, and then open a file in that window.}\\
    \vspace{10em}

    Try playing around with these two views, copy/paste code between them,
    bind them so they scroll together, resize them, add more splits.\\
    \newpage
  \item Editors also have pretty nice integration with compilation tools. With
    \texttt{KatsBadcode.cpp} open, try typing \texttt{:make KatsBadcode} in
    \texttt{vim} or \texttt{M-x compile<enter>make KatsBadcode} in
    \texttt{Emacs}.\footnote{
      Descriptions of \texttt{Emacs} commands are usually written as
      \texttt{C-c} or \texttt{M-x}, which mean ``Ctrl+C'' or ``Meta+x''
      respectively. Meta is often mapped to the escape and/or alt key,
      \texttt{M-x} means press Escape and then x or hold alt and press x.
    }
    \begin{quote}
      First cool thing that happened: Yes, you can run \texttt{make}
      \textit{without} any Makefile anywhere. We'll cover how that happened
      during build-system week.
    \end{quote}
    Building \texttt{KatsBadcode.cpp} will fail with several errors.\\
    \textbf{Optional: Describe how to navigate between compilation errors automatically.}
    \vspace{6em}
  \item While C-style languages support \texttt{/* block comments */}, others
    such as Python have no block comments and require you to put a \texttt{\#}
    at the beginning of every line.\\
    \textbf{4: Describe how to efficiently comment out a large block of Python code.}
    \vspace{8em}
  \item Many times you have a repetitive task that you need to do say 10 or 20
    times. It's too short to justify writing a script or anything fancy, but
    it's annoying to type the same thing over and over again. As example,
    reformatting the staff list to a nice JSON object:
    \begin{verbatim}
                                staff = [
Boole,George                        {"first": "George", "last": "Boole"},
Lovelace,Ada                        {"first": "Ada", "last": "Lovelace"},
von Neumann,John                    {"first": "John", "last": "von Neumann"},
Hopper,Grace                        {"first": "Grace", "last": "Hopper"},
Turing,Alan                         {"first": "Alan", "last": "Turing"},
Shannon,Claude                      {"first": "Claude", "last": "Shannon"},
Dijkstra,Edsger                     {"first": "Edsger", "last": "Dijkstra"},
Hamilton,Margaret                   {"first": "Margaret", "last": "Hamilton"},
Knuth,Donald                        {"first": "Donald", "last": "Knuth"},
                                ]
    \end{verbatim}
    Editors support the record and replay of \textit{macros}. With macros, you
    can start recording, puzzle out how to turn one line into the other, and
    then simply replay it for the rest. As a general rule, do not bother
    trying to be optimal or efficient, just find anything that works.
    Try starting with the column on the left and devising a macro to turn it
    into the column on the right.\\
    \textbf{5: Describe how to record and replay a macro.}
    \textit{\small (you do not need to include the contents of your macro; make your best attempt at trying to make a macro that works, but don't worry if you are unable to get it to work perfectly)}
    \vspace{6em}

\newpage
    \vspace{12em}
  \item Some final little things
    \small
    \begin{enumerate}
      \item Editors understand balanced ()'s and \{\}'s.
        \textbf{6: Describe how to jump from one token to its match, such as from
          the opening \{ on line~29 of \texttt{KatsBadcode} to its partner \}
          on line~58.
        }
        \vspace{8em}
      \item Sometimes it's useful to run quick little commands. For example,
        your code needs to read from a file, but you can't remember if it's
        called \texttt{sample\_data.txt} or \texttt{sampleData.txt}.\\
        \textbf{7: Describe how to run `ls' directly from within your editor.}
        \vspace{8em}
            \end{enumerate}
\end{enumerate}
        \subsection*{Personalising your Editor (Ungraded but recommended)}
        Similar to how \texttt{$\sim$/.bashrc} configures \texttt{bash}, a
    \texttt{$\sim$/.vimrc} or \texttt{$\sim$/.emacs} file\footnote{
      These files do not exist by default, you have to create them.
    } can configure how your editor behaves.
    \textbf{Add something useful not listed above to your editor's configuration file.\\}




\newpage
\section{Remote work}
One thing that can make life very convenient is learning how to work on remote
machines. CAEN has a large number of machines available for students to use
remotely, at \url{login.engin.umich.edu}. Let's check that out.

\texttt{ssh} is the \textbf{s}ecure \textbf{sh}ell program, and is used to
securely log in to remote machines.

Run \texttt{ssh~<your uniqname>@login.engin.umich.edu} to log into a CAEN machine. Take a look
around, this is the same login environment and home directory as if you had
sat down at a physical CAEN machine.

Use \texttt{vim} or \texttt{emacs} to create a file called \texttt{test.txt}
on CAEN. Put some text in it, save, and quit.

Now try to run \texttt{gedit~test.txt}.

\textbf{1: What error do you get? Why?}
\vspace{6em}

Close your ssh session (log out of the terminal, either by typing
\texttt{exit} or pressing \texttt{Ctrl-d} at an empty prompt). Then log in
again with the additional \texttt{-X} flag to ssh:
\texttt{ssh~-X~<your uniqname>@login.engin.umich.edu}.

Now try running \texttt{gedit test.txt} -- great! Only, now you cannot do
anything else in that terminal.

\textbf{2: How can you keep using this terminal without killing the gedit session
  that is already running?}

\textbf{3: How should you launch \texttt{gedit} so that you can still use the
  terminal?}

\textit{\small (Hint: remember we talked about shell \underline{job control} a few
  weeks ago)}
\vspace{12em}

Try running a more graphically intensive program, such as the \texttt{eclipse}
IDE or \texttt{matlab}. How does it compare to sitting at a physical CAEN
machine? How does it compare to using
\href{http://caenfaq.engin.umich.edu/12374-Linux-Login-Service/how-do-i-connect-to-a-caen-linux-computer-remotely}{VNC}
to log into CAEN? (And how good is your Internet connection right now ;) ?)

\bigskip
\hrule
\vspace{1em}
You may also find the \textbf{s}ecure \textbf{c}o\textbf{p}y program,
\texttt{scp}, and \texttt{rsync} useful for moving files between your machine and the remote
machine. No question on either of these, just letting you know they exist.

\vspace{3em}

\textbf{4: Roughly how long did you spend on this assignment? \rule{5cm}{0.1mm}}

\end{document}
