5. Review and Abstraction

5.1. Can I reset a Git repository?

  1. Find the hash number for the first commit of your in-class repo.

  2. On your terminal, navigate to that repo.

  3. Check out that commit git checkout <paste hash here>

  4. Look back at what happened, using ls

  5. Make a new branch called ‘reset’ and push that branch to GitHub.

  6. Switch back to the current version of the repo

  7. In browser, compare the two branches, visually.

5.2. Moving Files Requires Care

A question from last week was what happens if we move a file to an address where there already is one?

touch fa
echo "file one" > fa
cat fa
echo "file two" > fb
cat fb
mv fa fb
cat fb

5.3. Standard In, Out, and Error

We have been using bash to move files around and explore the system so far. In doing so we have also seen cat that we saw would display the contents of a file.

What it actually does is a little bit different. Let’s try cat without putting a file name after it.

cat

It waits for us to type, if we type and then press enter, what we typed is displayed and it keeps waiting.

Use control/command + d to exit.

cat actually looks at standard input, a special file in our computer that gets the input from the keyboard if we don’t tell it otherwise.

cat fa

is a shortcut basically for

cat < fa

which says explicitly, get ready to the contents of standard in to standard out and then put the contents of fa and put it on standard in. The arrow is called a redirect.

We used echo to write to a file above in the little experiment.

echo "some text" > a_file
cat a_file

and we get output as before

some text

That line has two new parts both echo and the < syntax. Let’s try echo by itself.

echo "hello world"

and we see

hello world

Echo puts content on standard out, which is a special file that is by default linked to the display of the terminal. It could have been set elsewhere, and that’s what the redirect does.

echo "some text" > a_file
cat a_file

This sends that text to standard out and redirects standard out to the file a_file

some text

if we use two arrows it will append instead of overwriting.

echo "some more text" >> a_file
cat a_file
some text
some more text
man echo

Name

File descriptor

Description

Abbreviation

Standard input

0

The default data stream for input, for example in a command pipeline. In the terminal, this defaults to keyboard input from the user.

stdin

Standard output

1

The default data stream for output, for example when a command prints text. In the terminal, this defaults to the user’s screen.

stdout

Standard error

2

The default data stream for output that relates to an error occurring. In the terminal, this defaults to the user’s screen.

stderr

Important

GitBash does not support man the reasons athe developer does not want to are also visible. You can use the help option -help try the help command.
The help is slightly different from the man pages overall.

Alternatively, you can modify your environment further. Enabling the Windows subsystem for Linux is one option. So is booting into Linux for example ubuntu that is installed on a flash drive. This uses the flas drive as the hard drive for the operating system. This option creates 2 whole “computers” at the software level, that use the same hardware.

5.4. Layers of a Computer System

  1. Application

  2. Algorithm

  3. Programming Language

  4. Assembly Language

  5. Machine Code

  6. Instruction set Architecture

  7. Micro Architecture

  8. Gates/registers

  9. Devices (transistors)

  10. Physics

5.5. Prepare for Next Class

  1. install h/w simulator

  2. Add a glossary, cheatsheet entry, or historical context/facts about the things we have learned to the site.

  3. Review past classes prep/more practice and catchup if appropriate

  4. Map out how you think about data moving through a small program using the levels of abstraction. Add this to a markdown table in your KWL chart repo called abstraction.md. If you prefer a different format than a table, that is okay, but put it in your KWL repo. It is okay if you are not sure, the goal is to think through this.

5.6. More Practice

  1. Once your PRs in your KWL are merged so that main and feedback match, pull to updates your local copy. In a new terminal window, navigate there and then move the your KWL chart to a file called chart.md. Create a new README files with a list of all the files in your repo. Use history N (N is the number of past commands that history will return) and redirects to write the steps you took to reorg.md. Review that file to make sure it doesn't have extra steps in it and remove any if needed using nano then commit that file to your repo.

  2. find a place where there is a comment in the course notes indicating content to add and submit a PR adding that content. This could be today's notes or a past day's.

  3. Add a new file to your KWL repo called stdinouterr.md Try the following one at a time in your terminal and describe what happens and explain why or list questions for each in the file. What tips/reminders would you give a new user (or yourself) about using redirects and echo?

    • echo "hello world" > fa > fb

    • echo "a test" > fc fd

    • > fe echo "hi there"

    • echo "hello " > ff world

    • <ff echo hello

    • fa < echo hello there

    • cat

Tip

pay attention to how many steps you do to know what value of N to use. You should be able to do all of number 1 in your terminal.

5.7. Questions After class

5.7.1. What happens if I don’t meet the requirements for the grade I contract for?

You will be able to revise the contract if you choose to earn a different grade. The revision will also have to get approved, but it is an option. If you do not fulfill your contract in the form it is stated at the end of the semester, you will get an incomplete and then we will make a plan to change that to a letter.

5.7.2. When can we expect approved pull requests?

Feedback hours mostly, which are 5-6pm on Tuesday and 4-5pm on Thursday

5.7.3. Can you echo multiple files at the same time?

Echo sends only to stdout, we can redirect stdout to a different file, but echo specifically goes to the one place. The question then becomes can we redirect std out to two places at once, which we cannot do with redirects alone either. However, we can send output multiple places using a few more commands. We’ll come back to this one next week. Also try the last exercise under more practice.

5.7.4. does this character “<” do something different than the redirect character “>”?

They are both redirections < is less common.

5.7.5. What’s under the hood with >?

The official documentation for redirections describes some. We’ll come back to it after we talk through the overview of hardware a bit more in the next class.

5.7.6. What level of understanding of the abstraction stack is typical for a programmer?

This is going to depend on their training. A person who programs after a short coding bootcamp or a scientist who codes in order to do their scientific research may only understnd the application and algorithm layers and be perfectly content and able to fulfill their goals. With a Computer Science degree we hope that by the end you have down to Assembly very strong and the basic ideas down to gates/ registers. Someone with a Computer Engineering degree will have more understanding at the lower levels but maybe less in programming languages and algorithms than a CS degree. Plus anyone can go learn more and forget things they once knew. Also how much you actively use this knowledge is going to vary. Someone who writes firmware is going to be focused on a very different point in that stack that someone who develops new machine learning applications for example.

5.8. Why you would want to override the name/path of a file?

You probably would not want to do this very often, but for example, I do this when I download a newer version of a file and my browser names the new version something like file_name (1).ext I actually wanted to overwrite but it assumes that I do not, so I use mv file_name\ (1).ext file_name.ext to overwrite the new, updated content into the better file name (without the space and (1))

5.8.1. How does Authentication on GitHub work?

GitHub provides a whole page on that with advice and links. We will also come back to this in order to talk about ssh keys and ssh generally next week.