

I told my 2nd year CS students to create a programming language - dovyski
http://www.dovyski.com/2012/04/i-told-my-2nd-year-cs-students-to-create-a-programming-language

======
dandrews
I did something like this once many years ago for one of my wife's students, a
precocious high-schooler who needed to be challenged beyond the elementary
Fortran she was teaching at the vocational school. So I outlined the steps it
would take to translate a toy language into a toy computer's instruction set,
and reviewed it with the young man one afternoon at my office - an abbreviated
compiler theory class with an eager audience of one. Tom took the big
flowchart that we made home, studying and meticulously documenting it. When he
brought me the documented design a couple of days later I asked him to
implement it.

Tom spent awhile doing this in Waterloo Fortran, and when he presented me with
the working compiler I said "Good job. Now execute the code." He blinked his
surprise - until then I don't think he'd considered that the toy machine could
have been interpreted. A revelation! He went back home and wrote the VM for
the toy machine without any assistance; it worked well and I was as proud of
him as I could be.

A couple of years later I hired Tom and a couple of years after that he lapped
me, going on to better things. 30 years later I still keep a copy of his
compiler and interpreter, reminding me from time to time of the bright kid who
grew up to become a fine programmer and family man.

~~~
sounds
Thank you. Though you only helped one kid, someone else helped me...

...I was once the precocious high-schooler; in my History class I put a .com
file in the program's directory that ran a look-alike program which didn't in
fact work - on perhaps the only IBM PC in the school.

(Since DOS executed .com's first, and only the .exe if no .com was found,
adding a .com was a prank and harmless, but that didn't help my case.)

It was only a few years later, me interviewing for a job at a tech company
that the manager told me he was my History teacher's husband, and had cleaned
up my mess.

I could only thank him for both placating my teacher and then going on to
offer me a job.

In hindsight, I could have figured out that the nicest PC in the school
wouldn't be there just out of sheer random chance...

------
semisight
I wish I had a professor like you. When I asked why there was no compiler
class, the answer I was given was: "compilers are a solved problem; there's no
point in teaching them anymore."

Maybe it's just my school though.

~~~
enjo
That's jaw-dropping really... every student should have to experience the
horrors of the dragon book.

*edit: I say that firmly tongue in cheek. The Dragon book is one of the most important pieces of CS literature ever written. It's a fine book, the subject matter is just difficult:)

~~~
chimeracoder
Agreed. I'm taking a class right now with the dragon book (taught by Aho,
actually - one of the authors of the book), and it's easily the best and most
important CS class I've taken[1]. The main project for the class is to design
a language and write a working compiler/interpreter for it - in all the years
he's taught the class, apparently no group has failed to do this. The really
tricky part is making a language that other students in your class will _want_
to use, though, and that goes beyond the 'simple' issue of compiler structure!

I half-wish that there would be a way to teach a compilers class as the second
class in a CS track (ie, right after the intro class), but the problem is that
it just requires too much familiarity with the details in order to impose upon
most beginner/intermediate students, even if a few _really_ interested ones
could potentially handle it.

It might be easier if you started off with Scheme and then went from there (a
la SICP), but even then, you'd miss a lot of the more fundamental concepts
assumed in the Dragon book that really just need a lot of time to be digested.

[1] Alright, there's probably a three-way tie for 1st, but it still counts. My
education would not have been complete without it; I _highly_ recommend the
Dragon book to anybody who has the time and interest.

~~~
ataggart
My compilers class was a nightmare (and we used the Dragon book). I had hoped
a compilers course would actually teach about the full process by which a text
file becomes executable 1s and 0s. Instead it was a months-long torture of
parsing text. Regex to NFA, NFA to regex, regex to DFA, NFA to DFA, DFA
minimization, LL(1), LR(0), SLR(1), LR(1), LALR(1), along with memorizing all
the rules governing which grammars are amenable to which parser, and working
through all of the preceding by hand. And then finally about a week of teach-
yourself-LLVM.

I don't know if "compilers are a solved problem", but I'm pretty damned sure
that the only people who need to know that much about text parsing know who
they are, and would be able to reference it when needed. As an undergraduate
course, it was utterly worthless.

------
aik
This is great. More professors need to be like you.

With the exception of barely 2 projects in uni, all my homework/projects were
short and small scale, meaning I already knew how to complete 90% of it, and
just had to learn the content from the latest lecture to complete the rest.

With this assignment I probably would have known ~40%, meaning I wold have to
buckle down and actually get invested - figure out what I know and don't know,
and self study to the answer. Because I wouldn't just be able to rely on my
teacher and lecture notes, I would actually have to take (some) control of my
learning to succeed (rather than expect the teacher and textbook to hand feed
me everyone I need to know). Because I'm not hand fed everything, I would
actually become motivated because my success (or failure) for once would be
somewhat in my own hands. What a concept!!! Congrats.

~~~
dovyski
Thank you!

You described my thoughts when I created the assignment :) Like I said, I was
afraid to push them too hard. However I was denying them a real challenge,
filled with surprises, learning experiences and fun.

------
beambot
Go check out Peter Norvig's "Write a lisp interpreter in Python":
<http://norvig.com/lispy.html>

It's a very slick implementation. BTW, we had a similar requirement for our
"Programming Languages" undergraduate course: to implement our own language
with a BNF grammar, parser, etc (done in ML). It was one of the best learning
experiences we had!

~~~
dovyski
Thanks for the link and for sharing your experiences. Based on what you said,
it looks like I'm on the right track to create a great learning experience.
Nice :)

------
blahedo
It's a neat idea, but I really want to hear an experience report on the
_results_. I don't want to throw cold water on this, because I want it to work
and I think it might, but I have a fair amount of experience here[0] and can
think of a number of reasons why it might go poorly as well. All we see in the
OP is, "here's an idea that's cool (and it is) and I'm optimistic that it will
work."

[0]I have taught courses where intro-level students write Scheme interpreters
(in Scheme, in Java) and courses where students implement interpreters for
higher-level languages, and courses (well, one so far) where they implement an
actual compiler (for a subset of C).

~~~
dovyski
I will share the results on a future post. I understand your point, but I
think the assignment will enhance their skills related to objects, classes,
methods and instantiation.

That's my goal, not teaching about compilers or language structure. About that
they will learn empirically.

~~~
blahedo
Yup! And I didn't mean to sound so negative (sorry). I do hope it works (and
want to hear about it when it does!). I've definitely gotten really excited
about assignments before when _I_ thought they were neat and that the students
_ought_ to be able to figure everything out---but which turned out to be just
a bit too hard and thus demoralising rather than empowering. (If _that_
happens, it's still not worth dropping---tweak it until it works. Once you get
it working, there's probably a SIGCSE or ITiCSE paper in it for you!)

~~~
dovyski
No problem :)

I really got your point now. I thought about the "demoralising X empowering"
and my solution for that was to work with pairs of students. Working as a
team, they can discuss and motivate each other.

When I blog about the results, I will highlight the number of pairs that
completed, partially completed and did not complete the assignment.

------
vessenes
Cool!

It's interesting that you want them to make a procedural language, although if
they started with C, it makes some sense.

I wonder if you could broaden the experiment slightly by relaxing your
constraints and saying they either need to allow reassignment of variables, or
else support lambdas, and in exchange they can assume immutability.

~~~
dovyski
Thanks!

I think a procedural language makes more sense for them at this time. They are
just learning OOP, so it would be hard to implement an interpreter for that.

About your suggestion, that's cool. I think most of them are already assuming
immutability and using floats/doubles as the type of all variables.

~~~
Jach
I agree with your blog post that it's a more interesting assignment than yet-
another-Tic-Tac-Toe clone. I wish more curricula did this, and earlier! I
think after the assignment is done it'd be worthwhile to show them that they
can get all the Java-style OOPy features with just lexical closures, and I
think showing Forth as a powerful, simple, and simple-to-implement language
would be neat too. (Also yacc and lex deserve a mention, I like this PDF that
accomplishes the goal of the assignment:
<http://www.scribd.com/doc/8669780/Lex-yacc-Tutorial> )

If you relaxed the constraint on syntax and just stipulated Turing-
completeness, it would be very amusing if someone implemented a clone of
Brainfuck. ;) (Especially for the unlucky pair who has to write two programs
for it!)

~~~
dovyski
Thanks for the words and suggestions! About yacc they will meet that when they
attend the compiler course.

I didn't see a Brainfuck clone yet, but I saw something in the same level of
oddity. It was a language called "Star Wars", I guess. I can remember some
commands such as "Darth Vader told to a = 1" and "Skywalker from 0 to 10" haha
:)

------
stcredzero
So, from what I understand, they have the flexibility to choose their own
syntax. If they're interested in doing the least amount of work possible, they
could either implement a Lisp-like language or Forth. (Smalltalk is pretty
teeny as well. A basic Smalltalk-y language would weigh in at 1/6th the size
of Python's grammar.)

~~~
dovyski
One pair of students decided to create a stack-based language. I guess they
noticed it would save several lines of code and make the interpretation
process easier to do.

~~~
sounds
I see you have other students use the language at the end.

If you have a chance, it might be a rare opportunity to point out some of the
innovative ideas, after all the projects are done.

~~~
dovyski
Yeah, it's true. I will try to analyze and discuss the implementations at the
end.

~~~
LeonidasXIV
Could you keep us updated about that? Such a round-up post with interesting
ideas could be marvelous!

~~~
dovyski
Sure, I will blog about that in the future. Stay tuned :)

------
kaens
Will you be able to show off the results? I'd be really pretty interested to
see what some 2nd year comp-sci students come up with.

The pipe dream part of me wants you to have them stick their results on github
and work with each other, or start getting taught stuff by ... well, everyone.

My high-school comp-sci teacher is a large part of the reason why I can reason
clearly about code, and he would push us in directions like this -- not as
extreme, but similar in the "ok, here's an end goal that you can achieve by
thinking about it and making combinations of what you know" sense.

I know a _lot_ of programmers who don't grok compilers, even at a high level,
and it's a shame -- a lot of things are a lot easier, and you open the doors
to doing a lot more if you do.

~~~
dovyski
Sure, I will share the results on a future post. I think the same way your
high-school comp-sci teacher does, but this time I decided to break the line.

About the github idea, I like it, but my students are not familiar with git
yet. I will try to blog about their main ideas and language syntax in the
future.

------
evincarofautumn
Couldn’t commend you more highly for this—not least because it’s exactly what
I would do if I were a CS professor. ;)

Interpreters, compilers, and games are the things that have taught me the most
about programming and computing in general. Implementing programming languages
pushes high-level CS concepts as well as firsthand understanding of how
languages work. Games are a fun practical application of those
concepts—embedded scripting languages in particular—plus trig, vectors,
matrices, rendering, optics, audio, DSP, physics, you name it. And languages
and games both provide plenty of opportunities to learn about optimisation.

I hardly know why CS is taught any other way.

~~~
dovyski
Thanks!

I totally agree with you. My student's next assignments will be game-related:
develop an agent to fight inside an arena and create a Guitar Hero like game.

I really think they will learn more and better if they have to accomplish that
kind of assignments.

------
Tyr42
Our advanced CS class (first year) has written a scheme interpreter. We were
going to port it to C, from racket, but we ran out of time in the class. I
might just finish it for fun this summer.

------
micheljansen
Cool! I had a (mandatory) course on compiler construction in my second year of
CS as well. It was one of the toughest subjects, but it also made me
understand and appreciate programming languages so much better. Like everyone,
we tried to create a language without the annoyances found in many modern
languages. Like everyone, we found that those annoyances are actually really
hard to avoid. It was tons of fun :)

~~~
dovyski
I had the same fun when I created my own language during an also mandatory
course on compilers :) Even though my goal is to enhance my student's skills
about OOP, I hope they have fun creating a language.

------
dkrich
Not sure what's unusual about this except for the fact that it was assigned to
2nd years. I had to create a compiler from scratch during my course work, and
I'm sure many other CS programs require the same.

It is a great way to learn how a compiler works, but then again, in this day
and age it seems less and less relevant to know that stuff, especially if you
are going into a typical programming position.

------
weiran
We did this for our Compilers module during my second year CS degree at
Nottingham university. It's a very interesting subject and I thought it gave a
very good grounding in understanding new languages. Unfortunately we had to
write our compiler in Java, we had the option of using Haskell but I didn't
really learn get to grips with functional programming until the third year.

------
tylerhowarth
I am in a principles of programming languages class currently, and we are
doing very similar work. We are writing interpreters, type checkers, and more
for a new language our teacher has defined. We are doing all of this in Scala.

~~~
dovyski
Cool! It looks like you are creating a more robust interpreter. The one I told
them to implement is simpler (no type check, for instance).

------
kingkilr
I gave a talk yesterday on implementing a VM in 30 minutes. I'm not sure how
well it went (it's a lot of material for 30 minutes), but I hope I at least
got some people excited about implementing languages.

~~~
dovyski
As a programmer, I really enjoy the idea of creating my own VM and make it
able to interpret/run a language I designed. Surely some people got excited
about that :)

------
iz_mani
I think this is a pretty good approach. You don't learn till you get your
hands dirty. I hope kids do well.

------
voodoochilo
the dragonbook is never more than an armlength away from my screen. love the
idea.

