# More On Types

DevFeed: [More On Types](<https://devfeed.tech/articles/more-on-types-21795.md>)

Original publisher: [Read original article](<http://blog.cleancoder.com/uncle-bob/2021/06/29/MoreOnTypes.html>)

Published: 2021-06-29T00:00:00Z

Content type: article

Language: en

Sources: [Robert C. Martin](<https://devfeed.tech/sources/robert-c-martin.md>), [The Clean Code Blog](<https://devfeed.tech/sources/the-clean-code-blog.md>)

Topics: [Clojure](<https://devfeed.tech/topics/clojure.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>), [Framework](<https://devfeed.tech/topics/framework.md>), [GUI](<https://devfeed.tech/topics/gui.md>)

Tags: [clojure](<https://devfeed.tech/tags/clojure.md>), [code](<https://devfeed.tech/tags/code.md>), [framework](<https://devfeed.tech/tags/framework.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [programming](<https://devfeed.tech/tags/programming.md>), [state](<https://devfeed.tech/tags/state.md>), [types](<https://devfeed.tech/tags/types.md>), [velocity](<https://devfeed.tech/tags/velocity.md>)

## AI overview

The article presents a turtle graphics program written in Clojure and explores the type model of its turtle object using clojure/spec. It describes the turtle's geometric and animation-related state, including position, heading, velocity, distance, angular velocity, pen state, and related constraints.

## Source excerpt

Recently I wrote a cute little program for doing Turtle Graphics. For those of you who don't know, turtle graphics were originally added to the LOGO language by Seymour Papert in the late 1960s. He built a robot that he called a "turtle" that could hold a pen. The robot had wheels and could move forwards and backwards, and could rotate left and right. It could also raise and lower the pen. When placed on a sheet of paper, the turtle could be commanded to draw interesting designs. Papert's goal was to teach children about programming. As the years went by the robot got replaced with screens, and the turtle became an icon that could draw lines. Children from the 70s until now have been enthralled by the simple commands for directing the turtle, and the elegant drawings they can make. For example, this is how you might draw a square: forward 100 right 90 forward 100 right 90 forward 100 right 90 forward 100 right 90. Recently I had a need to explore some interesting geometrical designs. Turtle graphics would be perfect for my purposes. So I wrote a turtle graphics processor in Clojure. [code] I used the quil framework which is based on the Processing framework in Java. This framework makes it very easy to create simple GUIs in Clojure. Now consider the problem of the Turtle. What is the type model for this object? What fields does it have, and what constraints must be placed on those fields? Here was my solution to that problem, written in clojure/spec. As usual, in Clojure, you start at the bottom and read towards the top. (s/def ::position (s/tuple number? number?)) (s/def ::heading (s/and number? #(<= 0 % 360))) (s/def ::velocity number?) (s/def ::distance number?) (s/def ::omega number?) (s/def ::angle number?) (s/def ::weight (s/and pos? number?)) (s/def ::state #{:idle :busy}) (s/def ::pen #{:up :down}) (s/def ::pen-start (s/or :nil nil? :pos (s/tuple number? number?))) (s/def ::line-start (s/tuple number? number?)) (s/def ::line-end (s/tuple number? number?)) (s