# Looking for a block-based programming language for AP CS P

This question is specific for teachers of the United States College Board's AP Computer Science Principles class.

I'm looking for a block based programming language that allows for:

• Procedures that return values
• For each that will iterate through lists

In addition, we are to teach basic 2D robot programming with commands such as TURN_AROUND(), MOVE(), TURN_RIGHT() etc.

My research has come up with MIT's Scratch IDE; but I was wondering if there is a better choice for high school students.

• There is no such thing as a procedure that returns something. Procedures are subroutines that do something. A function is a subroutine that has no side effects and returns something. (except that they do not need to be implemented with subroutines, it is the behaviour that matters.) Though these terms are often mixed up, and I know of no language that 100% enforces the separation (command/query separation). Jun 15, 2017 at 18:01
• @richard A pure function has no side effects. Most (all?) non-functional programming languages don't enforce purity of functions, so you'll find plenty that have side effects (but still return stuff).
– JAB
Jun 15, 2017 at 18:17
• Though Scratch might seem a little juvenile for high school students, if you can overcome the students' initial distaste for something that appears to be tailored towards younger children, Scratch can truly be a powerful tool to teach. I've seen Scratch successfully illustrate complicated concepts in CS principles on multiple occasions. Jun 15, 2017 at 21:03
• @jab yes “I know of no language that 100% enforces the separation” Jun 15, 2017 at 21:27

You will probably want to look into Snap!. It was built upon Scratch and would probably meet your needs. This is from its About page:

Snap! (formerly BYOB) is a visual, drag-and-drop programming language. It is an extended reimplementation of Scratch (a project of the Lifelong Kindergarten Group at the MIT Media Lab) that allows you to Build Your Own Blocks. It also features first class lists, first class procedures, and continuations. These added capabilities make it suitable for a serious introduction to computer science for high school or college students.

Additionally, I asked a question a few weeks ago about the differences between Scratch and Snap!. You might find this discussion helpful: "What can Snap! do that Scratch cannot?"

Edit: In the context of AP CS Principles, it may also be helpful to know there is a full curriculum available from Berkeley that utilizes Snap!. It is called The Beauty and Joy of Computing.

• yes snap. I have heard that it is used to teach first your undergrad. It certainly seems to have all the features needed. Even lambdas. If is a proper functional programming language (like lisp). Jun 15, 2017 at 17:57
• There is also Blockly, but I haven't used it before, so I can't vouch for it. Jun 15, 2017 at 18:07
• @Peter Blockly (which I worked on) is really an editor, not a language. Languages can be built on top of it, as App Inventor is. Jun 20, 2017 at 23:14

Not strictly block based, but I like Codesters as a nice midway point. It has a DnD interface but the blocks you drop become Python code.

Code.org has a CS Principles curriculum available for free, and I think this would meet your needs. https://studio.code.org/courses/csp

I've never used it with a class, but it starts with an implementation of blockly (https://developers.google.com/blockly/) and transitions to Javascript in Units 3 and 5. It also allows students to create apps, using AppLab. It starts with a turtle and moves through to user interfaces and beyond.

While I definitely recommend Snap!, for completeness sake you might take a look at:

• Scratch -- though w/o custom functions this may be limiting
• PencilCode -- a blocks+text environment around CoffeeScript
• GP (gpblocks.org) -- a desktop environment that looks similar to Scratch/Snap! But has dozens more blocks as well as a very interesting model for exploring classes and inheritance.
• AppInventor -- using blocks to build Android apps.

For me, Snap! strikes a good middle ground between freedom and complexity.

• Welcome to Computer Science Educators! This answer could really benefit from explanations on why Snap! might be a good option. Aug 9, 2017 at 7:57
• Also, feel free to come by The Classroom and say hi. That's where we all tend to hang out. ;-)
– Ben I.
Aug 9, 2017 at 15:09

On CodeHS we have a block-to-text based programming environment and a full curriculum for AP CS Principles that you can use for JavaScript. It has a unit to teach JavaScript, including functions and lists among other topics, and also starts with a unit on Karel the Dog. Karel the Dog is a JavaScript implementation of the Karel programming language, which is very similar to the style of problems on the AP CSP exam. Karel knows the commands

move(); putBall(); takeBall(); turnLeft(); and later turnAround();

Essentially it is the same as 2D robot programming but with a dog instead of a robot, which is a bit friendlier.

You can use this with blocks or text - it's just in JavaScript, and you or students can also easily build their own worlds. Hope that helps!

StarLogo Nova is another MIT project. It's block based like scratch, but I personally find it much nicer to use, and it allows (I think) for more complex programs. It is more simulation oriented than scratch, but you can still make just about anything with it. Also, it has a flying turtle for a logo:

It's got a nice setup for classes - each user has a profile with a public and a private gallery. You can add collaborators to projects, set up some form of "class" on the system, though I don't know quite what that entails, etc.

Here's a screenshot of the coding environment with some code for a project I did in it:

On the left, you have a menu with the different coding blocks, the drop down has categories very similar to those in scratch. The tabs on top of the coding section are basically for the different "agents" and for the "world". This program, if you're wondering why there's a "Killers" tab, is to simulate an epidemic. There's support for all sorts of things - procedures that return values, movement of "turtles" which are basically robots on the screen, etc.

Here's a screenshot of the section of the screen that shows the result of your program:

This shows the level of complexity you can get too - you can have output graphs and number boxes, input sliders, etc. You can also keep it very simple - the two things that are pretty much always there are the "setup" and "forever" buttons. This screenshot was taken right after "setup" was pressed - it initialized the turtles, widgets, breeds in the right proportions, etc.

I'd definitely recommend this language.

Python has a turtle graphics module that is quite a bit of fun to play around with. It is simple to use and you can have your students write functions to drive it and to draw custom graphical elements such as stars.

Turtle graphics can be used to make looping visual. You can also add an event-driven element by making your drawing panels mouse-sensitive. The Python site has complete documentation. Tough exercise: Draw an American flag. Easier: Draw a Texas flag; making a five-sided star is a fun puzzle.

You can incorporate this into your class and experiment with it a variety of levels.