10 ms·
I took CS019 with Shriram a few years back and immediately guessed the authors based on paradigms like making testing a natural part of the language and the enc
by tbenst 13y ago
I took CS019 with Shriram a few years back and immediately guessed the authors based on paradigms like making testing a natural part of the language and the encouragement to use annotations. In the class, we were taught a design process for Racket that will work very well for Pyret:
1. Identify the data - create data definitions (You are gixen x and expected to produce y)
2. Write concrete examples of the data (This is hard and takes time)
3. Write contract, purpose, header for functions (contract and header are annotations in Pyret, purpose should be a commented statement)
4. Write concrete examples of the function (This is hard and takes time. This means test cases!)
5. Write the template (This may only apply to recursion in Racket, but the idea is if you're dealing with a cons, you always have the same structure of checking if a cons? or empty? and must recur)
6. Fill in the template (ie, complete the function)
- sesm 13y agoThere is a book about this approach (http://htdp.org/ http://htdp.org/), as well as a MOOC on Coursera (https://www.coursera.org/course/programdesign https://www.coursera.org/course/programdesign)
- m_for_monkey 13y agoThe second edition of How to Design Programs is not finished yet, but I recommend it anyway: http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html
- oahziur 13y agohtdp was my first programming book, and it is really helpful.
- agumonkey 13y agoCan't suggest these enough for any programming student.
- skrishnamurthi 13y agoWell done, T.B.! The same idea applies to recursive data in any language; you'd use exactly this to write a tree-walker in Java, for instance. And likewise in Racket. E.g.: fun f(l :: List<T>): cases (List) l: | empty => ... | link(f, r) => ... f ... f(r) ... end end Note that because you can put type annotations in the cases statement, you can remind yourself of the type of the locals: fun f(l :: List<T>): cases (List) l: | empty => ... | link(f :: T, r :: List<T>) => ... f ... f(r) ... end end which further nudges you towards a possibly recursive solution.