Using Emacs - 3 - How to think about Emacs

Many people think of Emacs as an editor. I like to think of it as an Elisp interpreter where you live code documents.

In some ways, it's like those new fangled interactive programming environments where you type in code and the updates are reflected instantly.

In this video, I try to explain the way I think about Emacs and why it's so cool.

The only change we made to our configuration was adding:

(tool-bar-mode -1)

Which gets rid of the tool bar at the top.

Next time, we start talking about efficiently using Emacs.

Relevant links:

Using Emacs - Intro to Org Mode

This video is a brief introduction to org-mode, a mode I use for all sorts of things.

We'll dive into org-mode later in the series. Right now I just want you to see the basics since we'll be using org-mode for any notes that are written up during this series.

Actually, all my blog posts are written in org-mode.

Here are the important lines to add to your Emacs init.el file to get the nice looking bullets when in org-mode:

(use-package org-bullets
  :ensure t
  :config
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

About a month ago, Emacs user Harry Schwartz gave a nice overview talk on org-mode. If you want to get a better idea as to all the things you can do with it, check it out: https://www.youtube.com/watch?v=SzA2YODtgK4

Next time, we'll look at a little Elisp. After that, we'll dive in to using Emacs effectively and efficiently.

Relevant links:

Using Emacs - Setting up the Package Manager

This video will step you through setting up Emacs to use MELPA for packages.

We configured emacs by creating a folder named .emacs.d and creating a file within it named init.el.

Here's the contents of that file:

(setq inhibit-startup-message t)


(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
	     '("melpa" . "https://melpa.org/packages/"))

(package-initialize)

;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
	(package-refresh-contents)
	(package-install 'use-package))

(use-package try
	:ensure t)

(use-package which-key
	:ensure t 
	:config
	(which-key-mode))

The last two inituse-package clauses install two helpful packages:

  • try: let's you try packages without installing them.
  • which-key: brings up help on key combinations.

Relavent links:

Using Emacs - Introduction

I'm sure I've mentioned that I've been an Emacs wonk for decades. Since the mid-80's in fact. I've spent time using other editors, word processors, and development tools but always find my way back.

I recommend that budding computer science students develop a good tool set and encourage them to explore Emacs but while it's pretty easy to load Emacs and find your way around, particularly if you use the mouse and menus there isn't a clear path to take you from beginner to using it as an efficient tool let alone customizing it.

Inspired by Mattias Petter Johansson, or MPJ who make a weekly video, I decided to try to create a series of YouTube videos and matching blog posts. I'll try to post one a week and I'll try to keep the videos, at least after the first couple to just a few minutes and have them focus on micro-habits - one or two small things that you can bring to your work flow and internalize.

The first three four (this one and the next three) will focus on setting things up. After this post we'll have

  • Setting up the package manager
  • Intro to org-mode (just so that you recognize the markup)
  • Intro to Elisp (just so you have an idea of those configuration lines)

and then we're off to the races. Here's what I'm thinking about for the first few topics after the above mentioned ones:

  • Efficient Navigation
  • Windows and Buffers
  • Theming
  • Auto Completion

and then a series of short topics to show some of my favorite editing tools. We'll also cover some larger topics including:

  • Python Development
  • C/C++ Development
  • Document Preparation
  • Scheduling / Calendaring / Note Taking

I'll put together an index to these posts along with any ancillary materials here: http://cestlaz.github.io/stories/emacs.

Getting started

This series is going to assume you've installed emacs and worked your way through the included tutorial.

To help you get to that point, here are some links to posts and sites that I've found useful:

And here's a 10 minute getting started guide:

So, stay tuned.

Collaborative Coding or Cheating

I haven't been teaching this past semester. That's why I haven't been writing much about lessons. I miss working with students but that will resume in the fall and this semester has allowed me to get a jump on new projects.

It's also allowed me to look at some student issues from a bit of a distance.

One issue that keeps coming up is cheating.

Some of it, classroom cheating. my friend Ria recently asked a question on Facebook about it. A nice thread ensued but unfortunately, it's locked in the Facebook silo. I've got a lot to say on that and hope to explore it soon but today let's focus on project cheating - something that could just as easily apply to homeworks and student essays and research papers as well.

One part of the question is on students using code they find out in the wild. Alfred wrote a bit about it on his blog here where he points out some pluses, some minuses, and raises some good thought points.

I want to keep it in the class - code sharing amongst students, project and source code submission, and group projects.

Teachers have all sorts of options these days including:

  • Using a CMS like Blackboard or Moodle
  • Dropbox based solutions
  • Emailing projects
  • Using development tools and sites such as git with GitHub, BitBucket or other repository hosting services

I've always been a fan of having the kids learn real software engineering skills along with the CS so Git, GitHub and public repos have been my weapon of choice.

Interesting enough, I've gotten an earful both from fellow teachers and professors and online for my stance on public repos.

I keep hearing "the kids will copy from each other" or something like that.

As Alfred said in his post: "Students have been copying from classmates for years."

Students who want to copy assignments have done so long before we've been teaching CS and they'll be doing it for years to come.

Using a hidden submission system doesn't help and could hurt.

Far better to create an open environment. You get an opportunity to talk about code sharing, attribution, learning from each other, supporting each other, and where to draw the line.

On top of that, the students learn a real tool set and have a chance to learn real development methodologies.

It's a win all around.

Will open repos stop cheating and irresponsible copying? Certainly not. It could, however, raise awareness.

So what do I do on the cheating front?

Besides trying to create a culture where cheating is discouraged, cooperation is encouraged but where students know the line, I will try to keep them honest.

Frequently, the day a big project is due, I'll give a quiz on the project. Students will have to describe parts of the project and what they did. Either a student will have had to contributed or at least will have had to have studied the rest of the teams code to pass the quiz.

GitHub also gives tools that help.

Here's the GitHub graph for a project:

github-graph.png

You can see who did what and when. The teacher can drill down further to examine the diffs – what code did each student write, when, and from where. If two students submit very similar code, the commit timestamps will even tell you who was first.

The tooling for teachers could be better but the infrastructure is there.

Technology isn't going to prevent cheating and more often than not, it seems that measures taken don't stop the bad guys but inconvenience those trying to do it right.

Much better to build a class culture where the kids want to do it the right way.

Shell short - tagging old posts in Nikola

Quick post to add to the recent command line fu I've been writing about.

Douglas Peterson had another Whatever happened to post. This time on Logo. I wanted to reply, talk about NetLogo and link to some of my old NetLogo posts to help show how cool it is.

Nikola supports tags, makes a nice tags page and for each tag, a nice page of all the links.

Nikola has a plugin tags which lets you manage tags from the command line. For instance:

nikola tags -a netlogo posts/somepost.org

Would add the tag netlogo to the specified post.

The problem: The tags plugin only works if the post has a tag: line already present in it's header comment and I hadn't put them in my older posts.

I had a bunch of posts, all of them in one directory. All the new ones were .org files and had the tag slug. The others were .md markdown files and .html html files.

Here's what a typical top block looks like:

<!--
.. title: Looking for interesting questions
.. slug: 2010-01-03-looking-for-interesting-questions.html
.. date: 2010-01-03
.. type: text
-->

Sed to the rescue. Here's the what I ended up typing (from within the posts directory) to add the tags slug to the top comments right above the .. type: text: line:

ls *md *html | while read filename
do
    sed "/type: text/ i .. tags: " $filename
done

A line at a time:

ls *md *html

This lists all the files with that end in md or html

| while read filename

The vertical bar (pipe) sends the output of ls into the while read command. The while command sets up a loop which, each time through, reads the next input and places into the variable filename. The body of the loop is between the do and the done.

sed "/ type: text/ i .. tags: " $filename

Sed is the stream editor. The stuff between the slashes finds the line with the text type: text in it. The i inserts a line above and the rest of the stuff in the quotes is what to insert. The $filename expands to each filename, one each time through the loop.

Now all of my files have blank tag slugs so I can find my netlogo posts and tag them:

nikola tags -a netlogo `grep -i -l netlogo posts/*`

Any command in backticks expands to the result of the commmand. The grep command has two argiments: -i means ignore case so it will find netlogo, NetLogo, NETLOGO, etc.. The -l tells grep to just output the filenames. So, the grep command will expand to a list of files that mention netlogo. The full command adds the netlogo tag to all of them.

So, just a bit of quick shell scripting and I've:

  • modified all old posts to accept tags.
  • added the netlogo tag to all my netlogo posts.

You can find all those posts here.

REPOST - Shell games - who confirmed attendance

Repost

This is a repost from March 2015. It didn't transfer when I rebooted the blog.

Original

Quick post on why I love the Unix command line.

We're busy organizing CSTUY's first hackathon. It's going to be at SumAll, where we hold our weekly hacking sessions but while taking registration, we had a little program.

The kids signed up on a Google doc but we all know the story – when people sign up for a free event, even one with free food and t-shirts, many don't show. I asked all of the applicants to confirm by filling out a second Google doc.

Then it got to reminder time - I wanted to send an email out to all those kids who signed up on the first form, but hadn't confirmed on the second.

Two Google spreadsheets with an email field. I needed all the people on sheet 1 that weren't on sheet 2. I'm sure there's some spreadsheet-fu that accomplishes this, but nothing I know. I also could have written a little python script which isn't so bad, but this was a perfect time to turn to the shell.

So, here's how a command line guy would do this.

To start, I put the emails in two files: e1 and e2. The first has all the original applicants, the second those that confirmed.

e1   e2
a@a.com   b@b.com
b@b.com   F@f.com
c@c.com   c@c.com
d@d.com   d@d.com
e@e.com    
f@f.com    
g@g.com    
h@h.com    

If we put these lists together, any email that appears twice would indicate that it's the email of someone that confirmed entry. Here we use cat to catenate e1 and e2 and pipe them through sort.

cat e1 e2 | sort

First problem –the upper case F – let's use tr to make everything lower case:

cat e1 e2 |  tr A-Z a-z | sort

Now we can see the duplicates next to each other. Next, uniq -c tells us how many times each line appears:

cat e1 e2 | tr A-Z a-z | sort | uniq -c | sort

I added the sort at the end, but we didn't need it.

Here's what we get:

1 a@a.com
 1 c@c.com
 1 c@c.dom
 1 e@e.com
 1 g@g.com
 1 h@hc.om
 2 b@b.com
 2 d@d.com
 2 f@f.com

To pull out the ones that haven't replied I used egrep with a regex that means "any line that starts with 1 or more spaces followed by the number 1":

cat e1 e2 | tr A-z a-z | sort | uniq -c | egrep "^ +1"

and finally to isolate the emails using sed which removes the spaces and number 1 from the beginning of the line:

cat e1 e2 | tr A-z a-z | sort | uniq -c | egrep "^ +1" | sed "s/\ \+1 //g"

Each of the little utilities aren't all too useful by themselves but if you learn them over time you start thinking about how you can combine them to solve problems.

If you think this way and know some basic tools, all of a sudden all manner of text manipulation problems become pretty easy.

BASH scripting?

Over in the Facebook AP Computer Science Teachers group someone asked for thoughts on covering BASH scripting as a post AP topic.

A number of us made suggestions. I linked to this old blog post.

One group member said she asked around for similar suggestions and the response she got was "vi and awk." I wanted to jokingly respond "and after they suggested that they got into their time machine and went back to the 70's."

In all seriousness though, I think that suggesting specific tools or commands is off base.

The important thing to know about Vi is how to get out of it but it isn't really a tool in the scripting sense. I do think students should spend a good amount of time learning a powerful editor and should try bot Emacs (my choice) and Vim but that's another story.

I also use AWK but as it's a programming language in it's own right, I'm not sure if I'd introduce it right off the bat.

There are a number of important ideas kids can take away from learning some Linux (or other Unix flavor):

  • There's something out there besides Windows and MacOS
  • All about free software
  • The Unix Philosophy

That last one is the biggie and more specifically, there's a huge upside in teaching kids the value of "OS as Toolset" where they can compose the many tools that comprise the Linux experience to get things done.

I gave an example of that in the post I previously linked to.

For the teacher, that means wrapping your head around that way of working. Living in the shell and using pipes to connect program to progarm to program.

I'd recommend getting into a time machine ourselves and taking a look at:

English4.gif

It's dated but it's really a great book on getting into the Unix way of doing things, particularly the chapter about filters. It also has one of the best and clearest introductions to writing a compiler in the chapter on program development.

As I said, it is dated - shells are much easier to use and much more robust, there are many more tools now, and they've evolved but it's really a must read book.

In terms of tools, I get a lot of mileage out of:

command description example explanation
cat catenate or display a file    
tr Translate characters tr A-Z a-z convert upper to lower case
sed Stream editor sed "s/a/b/g" Replace all a with b
wc word count   counts words lines and chars
cut cut columns    
sort sort lines    

A nice simple thing you can do with these is clean data. Let's say you want to do some analytics on a book from Project Gutenberg. You might want to convert all non letters to spaces, and all letters to lower case:

cat book.txt | sed "s/[^a-zA-Z ]/ /g | tr A-Z a-z"

That sends book.txt into sed which uses a regular expression to convert no space and letters to spaces. The tr command converts all upper case letters to lower case.

If you want one word per line, add:

| sed "s/\n/g"

and maybe get rid of blank lines:

| sed "/^$/d"

We can now count the number of words in the file using *wc or even get counts of all the words:

| sort | uniq -c | sort -n

sort will sort all the lines, uniq -c will compress the lines that are adjacent and the same and give you a count and then sort -n will sort the results numerically.

I wrote another post a while ago about using the shell to detect who responded on a Google form. It looks like it didn't convert when I moved to my current blogging platform - I'll repost that shortly.

Should We Teach HTML?

Yesterday, Doug Peterson wrote a "Whatever happened to" post subtitled HTML as an essential 21st Century skill? It's a nice post.

I left a comment but thought I'd elaborate here.

No, knowing HTML is not programming - it's markup. Even so, when I help people design CS programs, I'll frequently recommend starting with HTML or at least introducing it early.

Why?

It's a gateway and not just to programming.

HTML is pretty easy, you want something bold, you just wrap the word in <b> and </b>:

<b>something</b>

It's also empowering and demystifies the web. Kids can create a simple web page and load it right into their browser.

It's true that today's web pages are chock-full-o javascript and css but with just the basics, students can get the idea. You can also show them pages by right clicking and viewing source.

You can even have them change a live page.

Try it.

Right click on the top of this page where it says "Musings about…" Chose inspect element. In the "debugger" window double click the text, change it and hit enter. This is just temporary - just reload the page but it's pretty neat for a kid to change an article and then screenshot it.

HTML is also a nice stepping stone towards coding. You're working in a plain text editor by adding special code words to basic text which are then interpreted by, in this case, the web browser.

The big reason for teaching html actually goes beyond this. Next step after learning HTML is having the kids programatically generating web pages in whatever language you're using for the class. I like using Python. This requires a little infrastructure setup to serve kids work but then there are two huge wins.

First, as the kids learn programming, instead of just printing out results, they can make a web site with their results and share it with friends, family, and the world.

The other big bonus is that kids might be able to leverage take these skills to other classes. If the student has a history paper to write, maybe the teacher will accept a history web site where the student can write code to do their analytics and build nice looking tables and graphs with results.

So while knowledge of HTML in and of itself isn't really needed anymore it's still an important part of the programs I build.

A World Without Advanced Placement

Some good points in the Facebook comments on my last post. One notable comment was the fact that many teachers wouldn't be able to gain the traction needed to teach CS without an AP designation. This is true but also sad that we've awarded such educational authority to a private company that's accountable to no one. Schools should run courses because they're good for kids not specifically because they're AP.

Stuyvesant just implemented a policy that every student has to take at least one AP class to graduate and that now every student in an AP class has to take the AP exam. There's also been a push for Stuy to run APCS Principles in spite of the fact that the current home grown intro course is superior.

These policies and pushes at Stuy are purely for the sake of ratings and in no way for the benefit of the student.

But let's imagine a world without the college board. To do this we're going to have to take off our computer science hats and look at another, more established high school subject area - mathematics.

First, setting the stage.

It's the mid 1990's. High school students across the nation are taking math classes. Some are even taking calculus. This makes the College Board happy since they offer two AP Calculus exams. But the College Board notices that many students aren't ready for calculus. To fill this gap, they create AP Statistics. First offered in 1997 to 7,667 students it was given to almost 200,000 students last year.

According to wikipedia, the course was created to give an AP mathematics option for students not ready for calculus.

I don't seem to recall any huge demand for an AP statistics course but it was created and adopted. It turned into one of the fastest growing AP classes and a nice money maker for the college board. I don't know how the class was pushed or perceived in other schools but at Stuy it was seen as a way to get an easy AP math course on the transcript. Before any statisticians get the torches and pitchforks - I'm just relaying the student perception. I haven't looked into the course sufficiently to form an opinion on it.

Now, let's imagine a world without the College Board.

An individual school would look at it's students needs and decide if they needed an additional math course. Maybe they'd conclude that what they were doing was fine or maybe they would conclude that a new class was needed.

If they decided they needed a new advanced course the school would either have the expertise to create it in house or they'd probably turn to the local college or university for guidance.

They might end up with a course very similar to AP Statistics or they might end up with something very different. They might end up with another class like Discrete Math or they might end up partnering with the college and having students take classes there. In all cases, since math teachers generally have a pretty good math backgroud, schools could make good decisions and design sound educational experiences for their kids.

All of these seem to be better results for the students than blindly following the College Board - keeping education and education decisions local.

What about CS?

I admit that's a tougher nut to crack.

Most schools generally don't currently have the in house expertise needed to build their own solutions or even to really critically judge what's out there.

That said, even if you need join the cult of the College Board to get your school to run some CS you can:

  • Grab all the materials you can find - those labeled AP and those not labeled AP.
  • Don't bother with AP Syllabus certification. Teach what you think is best. Designate the class as honors to differentiate them from other classes.
  • Engage with your local college and tech sector. They're not high school educators but they are valuable resources.
  • Unrelated side note - be wary of code schools - most don't really have any educational chops.
  • Don't force kids to sit for the exams and only encourage them to do so if the exam will likely do something for the kid.

I think that's it or my College Board rants.

Then again, I also thought that when I wrote Friday's post.


Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative