<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Friendly Error Fellowship</title>
    <description>This is a blog for &lt;a href=&quot;http://twitter.com/iamjessklein&quot;&gt;Jess Klein&lt;/a&gt; and &lt;a href=&quot;http://portfolio.toolness.org/&quot;&gt;Atul Varma&lt;/a&gt;'s 2016 Processing Foundation Fellowship.
</description>
    <link>http://processing.toolness.org/</link>
    <atom:link href="http://processing.toolness.org/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 24 Oct 2016 12:35:16 +0000</pubDate>
    <lastBuildDate>Mon, 24 Oct 2016 12:35:16 +0000</lastBuildDate>
    <generator>Jekyll v3.2.1</generator>
    
      <item>
        <title>Meet the P5 Maker:Sue</title>
        <description>&lt;p&gt;Twitter Handle: @deathbearbrown
Occupation: Open Web Developer
What she makes with p5: Experimental Art&lt;/p&gt;

&lt;p&gt;Sue learned about p5 from her colleague at Bocoup, a open web consultancy. Her colleague shared an experimental drawing application (making a realistic pencil stroke) at a staff show and tell. Sue was inspired and embarked on her own tinkering journey. As an Engineer, she came to p5 with quite a bit of past coding experience. In fact, Sue used processing.js  when she was in graduate school. At that time she was interested in manipulating datasets and crafting data visualizations.&lt;/p&gt;

&lt;h1 id=&quot;what-do-you-like-about-p5&quot;&gt;What do you like about p5?&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Pretty much all of my processing code from back in the day works in p5! I currently use it for experimental  art stuff. I like doing stuff with repetitive algorithms and fractals and then trying to modify it … and modify it until it gets really bizarre and interesting.” Sue often tinkers with opacity and different variables to achieve the effect that she desires.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;what-are-your-barriers-to-entry&quot;&gt;What are your barriers to entry?&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Random and random seed - while it’s a completely normal thing in other programming languages. It’s baffling to me and it’s baffling to anyone who is using this. I have a hard time figuring out how to structure my code so that what I think will happen will happen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;have-you-used-any-other-introductory-creative-coding-tools&quot;&gt;Have you used any other introductory creative coding tools?&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;2js and 3js a bunch. 2js is a 2d implementation that 3js is (a google experiment) - you can make shapes, animations and effects. I don’t use 2js because I was getting annoyed with the performance  - the things that I was doing were crashing the browser. When I got bored with 3js I just went directly to canvas.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;what-are-your-goals-for-using-p5&quot;&gt;What are your goals for using p5?&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;I have an art project that i want to do. I guess getting through each step of that, and learning how to make that possible. 
# How are you going about learning?
I’ve been doing “Fractal Fridays.” I got the algorithm from wikipedia and then go on to mathoverflow to convert the  formula. A lot of it was really basic algebra. I got into fractals because they look cool. I had taken a course in computer graphics - the math that goes into that. That helped me to see that math could be fun. I realized that I liked learning math through graphics. Everything that I know about p5, I know because I’m converting it from Processing. Ill convert it and then run it, if it breaks, I go to the p5 documentation to see if anything has changed or been renamed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;I like to see inspiring things made with p5, but I need them to be modifiable so I can play with it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;how-do-you-handle-receiving-error-messages&quot;&gt;How do you handle receiving error messages?&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;If it’s an error message that makes no sense to me then I copy, paste and google - I usually end up looking on stack overflow. If it’s a situation where my code is just breaking - then I’ll add breakpoints in my code to see where it fails. 
I read error messages all of the time.  I can’t even think of an error message in p5.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Most of my problems with p5 aren’t errors. It’s working fine but it’s just not doing the thing that I want it to do.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;here-are-some-projects-that-sue-has-made-with-p5&quot;&gt;Here are some projects that Sue has made with P5:&lt;/h1&gt;

&lt;blockquote class=&quot;twitter-tweet&quot; data-conversation=&quot;none&quot; data-lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;I didn&amp;#39;t set randomSeed() &lt;a href=&quot;https://t.co/f6LzlQKR14&quot;&gt;pic.twitter.com/f6LzlQKR14&lt;/a&gt;&lt;/p&gt;&amp;mdash; You just got Sue&amp;#39;d (@deathbearbrown) &lt;a href=&quot;https://twitter.com/deathbearbrown/status/700823766700417024&quot;&gt;February 19, 2016&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;//platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

</description>
        <pubDate>Fri, 29 Apr 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/04/29/Meet-the-P5-Maker-Sue.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/04/29/Meet-the-P5-Maker-Sue.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>Peer Learning with P5</title>
        <description>&lt;p&gt;I have always been a tinkerer, I love to craft–Pinterest is my jam, but with coding I’ve really never felt like I have been able to get to a place where I could tinker. &lt;a href=&quot;https://twitter.com/toolness&quot;&gt;Atul&lt;/a&gt; convinced me to apply for this fellowship because it would give me a chance to experiment and learn p5 in order to tinker with code in a lightweight way, so that we could help other designers and artists who, like me, might be enthusiastic but just a bit overwhelmed with code.&lt;/p&gt;

&lt;p&gt;The way that I approached learning p5 was pretty simple. I started by watching &lt;a href=&quot;https://www.youtube.com/watch?v=8j0UDiN7my4&amp;amp;index=1&amp;amp;list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFAhttps://www.youtube.com/watch?v=8j0UDiN7my4&amp;amp;index=1&amp;amp;list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA&quot;&gt;Dan Shiffman’s videos&lt;/a&gt; on YouTube. They are great tutorials and super funny. Atul and I watched together, and then when I reached a point where I felt like I could try something, I would stop and make something in &lt;a href=&quot;http://codepen.io/&quot;&gt;CodePen&lt;/a&gt;. I chose CodePen because it was a great environment for me to prototype an idea and then share it with Atul, so that he could then provide me mentorship directly in the code, or if we weren’t physically next to each other, with &lt;a href=&quot;https://screenhero.com/&quot;&gt;Screenhero&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My first little project that I made for myself was designing a lumberjack. I don’t know where the idea came from, but I just went for it. Like most of my projects, I started by sketching in my notebook.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/lumberdoodle.jpg&quot; alt=&quot;notebook doodle of lumberjack&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This helped me to think through how I could break down my concept into shapes, which I could then reference in the &lt;a href=&quot;http://p5js.org/reference/&quot;&gt;documentation section&lt;/a&gt; on the p5 site.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/ref.png&quot; alt=&quot;p5 ellipse reference doc&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first thing that I realized was a challenge for me was understanding the canvas. It’s basically the first thing that you do when you start a sketch in p5, and I get the general size of the container that I’m working in, but when I was making shapes, I was ballparking it - almost as if I had imaginary rulers on the page guiding my designs. Once I got the hang of that, the project became an exercise in deconstructing my composition into shapes and practicing how they work together, in groups, alone, overlapped, with different opacities, etc.&lt;/p&gt;

&lt;p&gt;As I worked, Atul encouraged me to keep my thoughts about how to improve the tools in a notebook, so that once I mastered the technical skills, we prototype making the user experience better for learners. My notes are pretty simple, they look like this:&lt;/p&gt;

&lt;pre&gt;
Canvas - why is it stuck to the edge? I want to move it to the center
Is there a chart somewhere that shows all the RGB values?
You can’t copy and paste from the documentation.
You can’t have two functions that are named the same thing. 
You need to specify what functions will be “drawing” by putting them under the draw function and then calling them.
I wish there was a ruler
I wish that there was a color picker in the IDE
I wish that the p5 site was responsive because I make the reference screen small while I’m coding 
Error: Uncaught SyntaxError: missing ) after argument list    &amp;lt;— that feels really wordy and confusing, just tell me I forgot a closing parenthesis.
The comments in the code in the examples aren’t legible if they are long lines on copy.
The edit and reset buttons cover the documentation 
&lt;/pre&gt;

&lt;p&gt;Here’s what the Lumberjack looks like right now. You can check it out &lt;a href=&quot;http://codepen.io/iamjessklein/pen/wGJMLE?editors=0010&quot;&gt;on my CodePen&lt;/a&gt;. It even has a little animation - with a wink that I threw in there!&lt;/p&gt;

&lt;p data-height=&quot;480&quot; data-theme-id=&quot;dark&quot; data-slug-hash=&quot;wGJMLE&quot; data-default-tab=&quot;js,result&quot; data-user=&quot;iamjessklein&quot; data-embed-version=&quot;2&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/iamjessklein/pen/wGJMLE/&quot;&gt;Lumberjack&lt;/a&gt; by Jess (&lt;a href=&quot;http://codepen.io/iamjessklein&quot;&gt;@iamjessklein&lt;/a&gt;) on &lt;a href=&quot;http://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;//assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;At this point all of my notes that I created from this exercise have been converted into github issues in the &lt;a href=&quot;https://github.com/processing/p5.js-website/issues?utf8=%E2%9C%93&amp;amp;q=is%3Aissue+author%3Aiamjessklein&quot;&gt;p5 website repo&lt;/a&gt;.  So, the question of the day: was I able to feel like I was tinkering with p5? Yes. I think that the reason why was that I was able to start and end small. I wasn’t building an application or website, just a simple illustration. It’s something that I was able to do by myself, but the learning experience was greatly improved by having a more advanced learner such as Atul by my side. The resources on the p5 website are great; I ended up supplementing them a bit with &lt;a href=&quot;http://shop.oreilly.com/product/0636920032076.do&quot;&gt;Getting Started with p5.js&lt;/a&gt; by Lauren McCarthy, Casey Reas and Ben Fry.&lt;/p&gt;

&lt;p&gt;I’m now wondering how I might improve this exact experience for learners. Here are some initial thoughts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Make documentation forkable/remixable.&lt;/strong&gt; Using CodePen was invaluable for me. I could code, not have to deal with servers and it felt like a safe space to fail. It also provided a way for me to pass around code with Atul fairly easily. This is currently a bit challenging to do via the p5 reference library. There are some simple solutions such as widgetizing elements that would support this kind of interaction.
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Start a community gallery for examples.&lt;/strong&gt; &lt;em&gt;Getting Started with P5.js&lt;/em&gt; had some great examples, and the p5 website itself has even more examples on the homepage - but either the examples are too basic or unfathomable. I want an easy way to see designs and code examples. This will do two things: 1. Expose the design process and thinking behind p5 sketches. 2. Raise the bar of work done in the field, by essentially crafting an online gallery space.
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Make errors friendlier.&lt;/strong&gt; I failed a lot in this experiment, but because of mentorship and the approachability of the p5 suite of tools, I felt compelled to continue on my coding quest. This kind of support can be translated into simple errors and suggestive, didatic resources. 
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s where I’m at now. I am going to work a bit on tackling these ideas with Atul and the p5 team and continue to build out the animations for the lumberjack. I’d love to hear from you. As a learner, have you experimented with peer learning through pair programming or like in my case, peer binge watching YouTube tutorials? &lt;em&gt;What has been an effective learning technique or tool for you?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Feel free to tweet your responses to &lt;a href=&quot;https://twitter.com/iamjessklein&quot;&gt;@iamjessklein&lt;/a&gt;!&lt;/p&gt;

</description>
        <pubDate>Fri, 15 Apr 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/04/15/peer-learning-with-p5.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/04/15/peer-learning-with-p5.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>Overwriting p5 Globals</title>
        <description>&lt;p&gt;It turns out that one of the problems with having global functions
with very simple names like &lt;code class=&quot;highlighter-rouge&quot;&gt;text&lt;/code&gt; is that beginners may accidentally
overwrite them, and then become confused when they try using them.&lt;/p&gt;

&lt;p&gt;This was first brought to our attention when a newcomer to p5
filed issue &lt;a href=&quot;https://github.com/processing/p5.js/issues/1314&quot;&gt;#1314&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Ultimately, the problem was fixed by PR &lt;a href=&quot;https://github.com/processing/p5.js/pull/1318&quot;&gt;#1318&lt;/a&gt;, which logs helpful
warnings if the user overwrites global functions.&lt;/p&gt;

&lt;p&gt;For example, the following sketch:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;blarg&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;logs this warning:&lt;/p&gt;

&lt;pre&gt;
You just changed the value of &quot;text&quot;, which was a p5 function.
This could cause problems later if you're not careful.
&lt;/pre&gt;

&lt;p&gt;Hopefully this change will make it easier for users to debug
their sketches.&lt;/p&gt;

&lt;h2 id=&quot;a-note-about-community&quot;&gt;A Note About Community&lt;/h2&gt;

&lt;p&gt;One of the particular things I like about this story is the way
the p5 community responded to it. While many open-source projects
would immediately dismiss an issue like &lt;a href=&quot;https://github.com/processing/p5.js/issues/1314&quot;&gt;#1314&lt;/a&gt; as “user error”
and be done with it, the p5 community instead helped the user debug
their problem, and then wondered if there was a way to alleviate such
a frustrating experience. Potential solutions were proposed,
community members responded with &lt;a href=&quot;https://github.com/processing/p5.js/issues/1317#issuecomment-199930427&quot;&gt;helpful feedback&lt;/a&gt;, and the original 
bug reporter was treated like a valuable contributor (which they were!)
rather than being dismissed as a noob.&lt;/p&gt;

&lt;p&gt;I wish all open-source communities worked this way.&lt;/p&gt;

</description>
        <pubDate>Tue, 05 Apr 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/04/05/overwriting-p5-globals.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/04/05/overwriting-p5-globals.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>TypeScript to the Rescue</title>
        <description>&lt;p&gt;After writing about &lt;a href=&quot;/general/2016/03/05/unit-testing-reference-docs.html&quot;&gt;Unit Testing Reference Documentation&lt;/a&gt;, I realized
that there’s a very interesting tool that can help us ensure the quality
of our documentation &lt;em&gt;and&lt;/em&gt; improve the development experience for p5
beginners and experts alike.&lt;/p&gt;

&lt;p&gt;It’s called &lt;a href=&quot;http://typescriptlang.org/&quot;&gt;TypeScript&lt;/a&gt;. It basically adds a nice layer of type-checking
on top of JavaScript, and the great thing about it is that you don’t even
really need to know anything about it in order to benefit from it. For
example, it allows us to build helpful autocomplete interfaces like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/typescript-autocomplete.gif&quot; alt=&quot;Animated GIF of autocomplete in Sublime Text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The above animated GIF happens to be taken from a session of Sublime Text
with the TypeScript plugin installed, but similar plugins exist for 
other editors like Atom. With a bit of work, we can build similar
functionality into the p5 IDE itself!&lt;/p&gt;

&lt;p&gt;Thanks to TypeScript’s static analysis, we can also use it to provide
friendly error feedback before the user has even started running their code.
For example, here’s what it looks like in Sublime Text when we pass a string
instead of a number as the first parameter of &lt;a href=&quot;http://p5js.org/reference/#/p5/createCanvas&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;createCanvas()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/typescript-error.gif&quot; alt=&quot;Animated GIF of error feedback in Sublime Text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Compared to the standards of the friendly error system, that feedback isn’t
particularly amicable, but we can do better if we integrate
custom support into the p5 IDE. The important thing here is that we’re
able to leverage the rich set of static analysis functionality that
TypeScript provides us, all without needing the user to know anything
about TypeScript itself.&lt;/p&gt;

&lt;h2 id=&quot;how-it-works&quot;&gt;How It Works&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Before reading this section, you’ll probably want to review the
&lt;a href=&quot;/general/2016/03/05/unit-testing-reference-docs.html&quot;&gt;Unit Testing Reference Documentation&lt;/a&gt; post if you haven’t already.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I wrote a &lt;a href=&quot;https://github.com/toolness/friendly-error-fellowship/blob/gh-pages/experiments/typescript/generate-typescript-annotations.js&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;generate-typescript-annotations.js&lt;/code&gt;&lt;/a&gt; script that essentially
converts p5’s YUIDoc metadata into something called a &lt;strong&gt;TypeScript
declaration file&lt;/strong&gt;. For example, here’s what the auto-generated entry for
&lt;code class=&quot;highlighter-rouge&quot;&gt;createCanvas()&lt;/code&gt; looks like:&lt;/p&gt;

&lt;pre&gt;
/**
 * Creates a canvas element in the document, and sets the dimensions of it
 * in pixels.
 */
declare function createCanvas(w: number, h: number, renderer?: string): any;
&lt;/pre&gt;

&lt;p&gt;Actually, the aforementioned script generates &lt;em&gt;two&lt;/em&gt; TypeScript declaration
files, which correspond to the different ways in which p5 can be used:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/toolness/friendly-error-fellowship/blob/gh-pages/experiments/typescript/p5.d.ts&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;p5.d.ts&lt;/code&gt;&lt;/a&gt; contains TypeScript declarations for p5’s &lt;em&gt;instance mode&lt;/em&gt;,
which is the way to use p5.js if you want to work with other third-party
libraries (or just generally keep your global scope clean).&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/toolness/friendly-error-fellowship/blob/gh-pages/experiments/typescript/p5.global-mode.d.ts&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;p5.global-mode.d.ts&lt;/code&gt;&lt;/a&gt; contains TypeScript declarations for p5’s
&lt;em&gt;global mode&lt;/em&gt;, which is what beginners use, and what most example
code snippets lying around the Web use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that these files aren’t completely accurate yet, as there are some
wrinkles involved in converting p5’s YUIDoc metadata into TypeScript 
declaration files. The methods and properties that haven’t been converted
yet are commented-out, with additional comments explaining the problems
the conversion script ran into.&lt;/p&gt;

&lt;p&gt;While it’s certainly possible to &lt;em&gt;not&lt;/em&gt; auto-generate the TypeScript
declaration files from p5’s YUIDoc metadata, I think that doing so keeps
things nice and &lt;a href=&quot;https://en.wikipedia.org/wiki/Don't_repeat_yourself&quot;&gt;DRY&lt;/a&gt;. It also serves as a nice “forcing function” to
ensure the quality of our documentation!&lt;/p&gt;

&lt;h2 id=&quot;ensuring-quality&quot;&gt;Ensuring Quality&lt;/h2&gt;

&lt;p&gt;Aside from making it easier for people to learn p5 and fix their errors
before they run their code, we can also use these TypeScript declaration
files to ensure that p5’s own example snippets are error-free.&lt;/p&gt;

&lt;p&gt;Because TypeScript works via static analysis, we don’t even need to &lt;em&gt;run&lt;/em&gt; our
example snippets: it should be fairly straightforward to write a test suite
that just iterates through all of p5’s reference documentation examples,
&lt;a href=&quot;https://github.com/processing/p5.js/tree/master/test/manual-test-examples&quot;&gt;manual test examples&lt;/a&gt;, and &lt;a href=&quot;https://github.com/processing/p5.js-website/tree/master/examples/examples_src&quot;&gt;examples on p5js.org&lt;/a&gt; to ensure that
our YUIDoc metadata and our example code agree with one another.&lt;/p&gt;

</description>
        <pubDate>Wed, 16 Mar 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/03/16/typescript-to-the-rescue.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/03/16/typescript-to-the-rescue.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>Unit Testing Reference Documentation</title>
        <description>&lt;p&gt;Part of the work of the Friendly Error Fellowship involves resurrecting
the original work on p5’s Friendly Debugger, which was disabled due to
various limitations documented in &lt;a href=&quot;https://github.com/processing/p5.js/issues/971&quot;&gt;#971&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the core features of the legacy Friendly Debugger was an argument
validator, which would:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Check that a function call contains the correct number of parameters, and&lt;/li&gt;
  &lt;li&gt;Check that a function call contains the correct type of parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This would be useful for beginners in particular. For instance, imagine
passing a number into a p5 function that expects a string; if the function’s
implementation calls &lt;code class=&quot;highlighter-rouge&quot;&gt;toUpperCase()&lt;/code&gt; on the argument, this will result in
&lt;code class=&quot;highlighter-rouge&quot;&gt;TypeError: toUpperCase is not a function&lt;/code&gt; being raised, which will be quite
confusing to newcomers. Much more helpful will be to log a friendly error 
suggesting the user pass in a string instead.&lt;/p&gt;

&lt;p&gt;Now, let’s take a quick detour to look at how p5’s reference documentation is
defined. We use a tool called &lt;a href=&quot;http://yui.github.io/yuidoc/&quot;&gt;YUIDoc&lt;/a&gt; that generates it from some
specially-formatted comment blocks in p5’s source code that look like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;param&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v1&lt;/span&gt;   &lt;span class=&quot;nx&quot;&gt;gray&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;red&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;hue&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;relative&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;to&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;                              &lt;span class=&quot;nx&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;current&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;string&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;param&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;nx&quot;&gt;gray&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;green&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;saturation&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;                                 &lt;span class=&quot;nx&quot;&gt;relative&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;current&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;range&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;                                 &lt;span class=&quot;nx&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;param&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gray&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;param&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;v3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;nx&quot;&gt;gray&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;blue&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;brightness&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;                                 &lt;span class=&quot;nx&quot;&gt;relative&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;current&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;range&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;param&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;relative&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;current&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;range&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The above is a snippet taken from the source code for &lt;a href=&quot;http://p5js.org/reference/#/p5/color&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;p5.color()&lt;/code&gt;&lt;/a&gt;, and
is used to generate its documentation.&lt;/p&gt;

&lt;p&gt;As Jason Sigal brought up in &lt;a href=&quot;https://github.com/processing/p5.js/issues/759&quot;&gt;#759&lt;/a&gt;, it should &lt;em&gt;theoretically&lt;/em&gt; be possible
to take the metadata extracted from such comment blocks, and leverage it to
do some of our type-checking for us, rather than violating &lt;a href=&quot;https://en.wikipedia.org/wiki/Don't_repeat_yourself&quot;&gt;DRY&lt;/a&gt;,
potentially introducing more errors, and complicating our codebase by
manually writing extra type validation code.&lt;/p&gt;

&lt;p&gt;However, we’re also in a bit of a bind because we don’t actually know
if our reference documentation is &lt;em&gt;correct&lt;/em&gt;. It would be really
unfortunate for the friendly error system to give the wrong kind of
advice to beginners, increasing their frustration even more!&lt;/p&gt;

&lt;p&gt;So how might we “unit test” our own reference documentation?&lt;/p&gt;

&lt;p&gt;Here’s one approach: write a type-checker that uses p5’s own YUIDoc
metadata, and use it to type check p5’s own example snippets.&lt;/p&gt;

&lt;p&gt;Doing this has a few advantages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;It ensures that our documentation is accurate. For example, if a working
example snippet is passing a &lt;code class=&quot;highlighter-rouge&quot;&gt;p5.Color&lt;/code&gt; instance as a first
argument to &lt;code class=&quot;highlighter-rouge&quot;&gt;lerpColor()&lt;/code&gt; but this isn’t documented as a valid
argument type, our type checker will complain. We fix the bug by
fixing our documentation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Conversely, it helps ensure the quality of our example snippets. If
our example snippet is calling a p5 API the wrong way, it’s probably
broken!&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;It’s possible that we can reuse the type-checking logic to resurrect
the Friendly Debugger’s type-checking system going forward.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’m now working on one approach to this kind of solution in &lt;a href=&quot;https://github.com/processing/p5.js/pull/1287&quot;&gt;#1287&lt;/a&gt;.&lt;/p&gt;

</description>
        <pubDate>Sat, 05 Mar 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/03/05/unit-testing-reference-docs.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/03/05/unit-testing-reference-docs.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>Using p5 Globals in Top-Level Code</title>
        <description>&lt;p&gt;One of the unintuitive aspects of p5 that beginners often make is using
p5 globals in their “top level” code, i.e. outside of &lt;code class=&quot;highlighter-rouge&quot;&gt;setup()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;draw()&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myColor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'blue'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;myColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Believe it or not, this sketch doesn’t work, and will result in the
following error being thrown:&lt;/p&gt;

&lt;pre&gt;
ReferenceError: color is not defined
&lt;/pre&gt;

&lt;p&gt;The full reasoning and workaround for this is described in the &lt;a href=&quot;https://github.com/processing/p5.js/wiki/Frequently-Asked-Questions#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup&quot;&gt;p5 FAQ&lt;/a&gt;,
suffice to say that programmers of all experience levels &lt;a href=&quot;https://github.com/processing/p5.js/issues/903&quot;&gt;encounter&lt;/a&gt; &lt;a href=&quot;https://github.com/processing/p5.js/issues/1237&quot;&gt;it&lt;/a&gt; a &lt;a href=&quot;https://forum.processing.org/two/discussion/12985/color-is-not-defined&quot;&gt;lot&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It’s hard to detect such errors with 100% accuracy, but in &lt;a href=&quot;https://github.com/processing/p5.js/pull/1130&quot;&gt;#1130&lt;/a&gt; I added some code that attempts to detect it, and in &lt;a href=&quot;https://github.com/processing/p5.js/pull/1256&quot;&gt;#1256&lt;/a&gt; I improved on it so that the following console message is now displayed when the above sketch runs:&lt;/p&gt;

&lt;pre&gt;
Did you just try to use p5.js's color() function? If so, you may want to move it into your sketch's setup() function.

For more details, see: https://github.com/processing/p5.js/wiki/Frequently-Asked-Questions#why-cant-i-assign-variables-using-p5-functions-and-variables-before-setup
&lt;/pre&gt;

&lt;p&gt;I wish there was an easy way to get feedback on whether users actually find this message helpful. I can think of a few solutions to this, but more on that in a future blog post!&lt;/p&gt;

</description>
        <pubDate>Mon, 22 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/02/22/p5-globals-help.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/02/22/p5-globals-help.html</guid>
        
        
        <category>general</category>
        
      </item>
    
      <item>
        <title>Towards Zero Errors</title>
        <description>&lt;p&gt;What’s better than friendly errors? &lt;em&gt;Zero&lt;/em&gt; errors! We can help ensure this if we have accurate documentation.&lt;/p&gt;

&lt;p&gt;But one of the hardest things about fixing a mistake in the documentation is figuring out where it’s located in a project’s source code.&lt;/p&gt;

&lt;p&gt;So I thought that it might be nice to &lt;em&gt;unintrusively&lt;/em&gt; link to the source code for a p5 API in its documentation. I stress the word &lt;em&gt;unintrusively&lt;/em&gt; because I don’t want to confuse the beginners who may be learning programming for the first time, and could be thrown off by the extra information.&lt;/p&gt;

&lt;p&gt;Other benefits of linking to the source:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It invites users of p5 to become contributors.&lt;/li&gt;
  &lt;li&gt;It generally makes it easier to “pop open the hood” and see how p5 works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s what it looks like–the example screenshot below is taken from the documentation for &lt;a href=&quot;http://p5js.org/reference/#/p5/plane&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;plane()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/link-to-doc-source.png&quot; alt=&quot;Screenshot of linking to documentation source&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first link there is to &lt;a href=&quot;https://github.com/processing/p5.js/blob/master/src/3d/3d_primitives.js#L14&quot;&gt;view the source for &lt;code class=&quot;highlighter-rouge&quot;&gt;plane()&lt;/code&gt;&lt;/a&gt;, while the second is to &lt;a href=&quot;https://github.com/processing/p5.js/edit/master/src/3d/3d_primitives.js#L14&quot;&gt;edit it&lt;/a&gt; (yay to GitHub for providing permalinks to edit files at a specific line number!). My hope is that beginners who don’t know anything about git can fix simple typos and issue PRs for them.&lt;/p&gt;

&lt;p&gt;This was filed as pull request &lt;a href=&quot;https://github.com/processing/p5.js/pull/1248&quot;&gt;#1248&lt;/a&gt;.&lt;/p&gt;
</description>
        <pubDate>Fri, 12 Feb 2016 00:00:00 +0000</pubDate>
        <link>http://processing.toolness.org/general/2016/02/12/first-post.html</link>
        <guid isPermaLink="true">http://processing.toolness.org/general/2016/02/12/first-post.html</guid>
        
        
        <category>general</category>
        
      </item>
    
  </channel>
</rss>
