<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Flanagan on Medium]]></title>
        <description><![CDATA[Stories by David Flanagan on Medium]]></description>
        <link>https://medium.com/@__davidflanagan?source=rss-70b3d287f497------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1zpjtmlA96onhTVD.jpeg</url>
            <title>Stories by David Flanagan on Medium</title>
            <link>https://medium.com/@__davidflanagan?source=rss-70b3d287f497------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:45:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@__davidflanagan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React hooks: context state and effects]]></title>
            <link>https://medium.com/@__davidflanagan/react-hooks-context-state-and-effects-aa899d8c8014?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa899d8c8014</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 23:51:40 GMT</pubDate>
            <atom:updated>2019-04-01T23:51:40.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45iMjFgUMOphJSci3qMpyQ.png" /></figure><h3>React Hooks: context, state and effects</h3><h4>A case study</h4><p>More than one website I’ve worked on has suffered from a problem that is common for sites that allow user logins. When a user is logged in, the server produces customized output for the user. It does this most obviously by displaying the user’s profile picture instead of a “Sign in” link. For users who are not logged in, the server does no customization and serves up the same page every time. This means that we can use a CDN to serve static pages to logged-out users faster than we can serve customized pages to logged-in users. We’d like more users to log in, and rewarding them with a slower site seems wrong.</p><p>My current team is working to fix this on our site. Instead of making user-specific customizations (such as displaying a profile picture) on the server, we plan do those customizations on the client side, with JavaScript. This will allow us to serve the same static pages, via CDN, to all users. Once those pages load, client-side JavaScript can query the server to find out whether the user is logged in and (if so) what the URL to their profile photo is. When the response to this query arrives, the client-side JavaScript can either insert the user’s photo into the page or insert a “Sign in” link if the user is not logged in.</p><p>There are a number of different ways to do this kind of client-side customization. We’ve chosen to use the React framework because of its ubiquity (we’re betting that this will make it easier to find contractor to help us with our work) and its robust and relatively mature ecosystem of tools.</p><p>I began the profile picture customization work shortly after React 16.8 was released. 16.8 was an important release for the React team because it defines a powerful new way to define components, using a mechanism known as <em>hooks</em>. The use of React’s new hooks feature is entirely optional, and there is no need for React developers to convert their existing components to use them. But because I was beginning a new project, I chose to use hooks and found that I really liked this new model of React programming. My work to move the profile picture customization from the server to the client allowed me to use hooks to manage context, state and effects, and I think that makes it an interesting case study to share with readers who use React.</p><h3>Introduction to Hooks</h3><p>Simple React components can be written as functions that take a properties object as its input and return a string or a JSX element to be rendered. For example:</p><pre>function Link({href, children}) {<br> return &lt;a href={href}&gt;{children}&lt;/a&gt;;<br>}</pre><p>Before the introduction of hooks in React 16.8, however, functional components were quite limited: they could not define local state variables, and they could not perform side effects when first rendered (or “mounted”) or when re-rendered. In order to create components that could do those things, we had to define them as classes that inherit from React.Component. The render() method of such a class would take a properties object as its input and would return the content to be rendered. In addition, however, this render() method could use the properties of the this.state object to customize its output. React components defined as classes inherit a setState() method from the superclass. If the render() method outputs HTML elements with event handlers, one of those handlers might call setState() to alter the this.state object and cause the component to be re-rendered in its new state. Finally, class-based components can define “lifecycle methods” such as componentDidMount() (called by React after the first render) and componentDidUpdate() (called by React after subsequent renders). A componentDidMount() method could be used to register global event handlers or to request data with a fetch() call, for example.</p><p>In React 16.8, hooks allow us to use state and define lifecycle effects in functional React components. Hooks are just functions–imported from the React module–that you call within your component. By convention hook functions have names that begin with use: in this blog post we’ll describe the useContext(), useState(), and useEffect() hooks. There are also important conventions (the React documentations calls them “The Rules of Hooks”) that govern how you can call hooks: you can only use them within functional React components, not class-based components. And they must be called at the top-level of your component functions: you cannot use them within conditionals, loops, or nested functions.</p><p>The idea that you can call the useState() function to somehow introduce local state variables into your functional component is deeply counterintuitive, and React has to do some magic behind the scenes to make it work. I typically frown on APIs that rely on behind-the-scenes magic, but I do have to admit that once I got used to them, I’ve found hooks to be quite satisfying to use in practice. So let’s peek behind the curtain to develop a bit of intuition about how hooks work: the key thing to realize is that when you define a functional React component, your function will only be called in a very specific and controlled way, when React is building or updating its tree of components. So even though a functional component does not have an associated instance the way a class-based component does, each invocation of your functional component is, in fact, associated with a specific node in the tree that React is building. Hooks give us a way to associate things (like context, state and effects) with the nodes in that internal React data structure.</p><p>That’s a hand-wavy explanation, but hopefully it is a plausible enough explanation of why hooks work. With class-based components, each instance of the component is its own private data structure within the larger tree that React is building. With functional components, hooks let us insert data–in very specific and controlled ways–directly into that tree, and component instances are no longer needed. If you find this explanation convincing enough, then there is no need to think more deeply about how hooks work, and I recommend that you simply embrace the magic of these special use-prefixed functions.</p><p>Hooks are best explained by example, so we’ll return now to my desire to display user profile pictures on the client side instead of the server side. The sections that follow introduce the useContext(), useState() and useEffect() hooks.</p><h3>useContext()</h3><p>React’s context mechanism is a way to make important data available to any component in the rendered tree without having to pass that data from parent to child down through the entire tree as a property. A canonical use-case for contexts is to make UX theme data available to all components in the tree. For my profile picture work I chose to make user data (including the profile picture URL) available through the React context mechanism because I expect that we’ll be adding more user data on which to base customizations. If, in the future, we allow users to specify a preferred theme, for example, then many components may need to be aware of that user preference.</p><p>Working with contexts in React involves using a context “Provider” component high up in the component tree and passing the context data to that component as a prop. When a class-based React component needs to access the context data, it renders a context “Consumer” component with a function as its only child. React invokes that function with the context data as its argument, and then that function behaves like a render method returning the elements to be displayed. This is an awkward bit of indirection that has always made the React context mechanism seem complicated. Fortunately, hooks do away with the need to render a context consumer, and make it very easy to create components that use context data. As an example, here is a simplified version of my Login component that uses the context mechanism to get data about the current user:</p><pre>import { useContext } from &#39;react&#39;;   // Import the useContext hook</pre><pre>// Import the module that defines the user context<br>import UserProvider from &#39;./user-provider.jsx&#39;;</pre><pre>export default function Login() {<br>  // Get data about the current user by calling useContext()<br>  const userData = useContext(UserProvider.context);</pre><pre>  if (!userData) {<br>    // If we don&#39;t have the user data yet, don&#39;t render anything<br>    return null;<br>  } else if (userData.isAuthenticated) {<br>    // If we have user data and the user is logged in, render      <br>    // the user&#39;s profile pic<br>    return (<br>      &lt;img width=48 height=48<br>        src={userData.gravatarUrl.small}<br>        alt={userData.username}<br>      /&gt;<br>    );<br>  } else {<br>    // Otherwise, show a login prompt<br>    return (<br>      &lt;a href={`/users/github/login/?next=${<br>                  window.location.pathname<br>                }`}&gt;<br>        Sign in<br>      &lt;/a&gt;<br>    );<br>  }<br>}</pre><p>Line 1 of this code imports the useContext() hook from the React module. Line 4 imports the UserProvider module that defines the context object we want to use. (We’ll see the code in this module later in this blog post). And line 8 calls the useContext() hook passing the UserProvider.context object to specify which context we want to use. The return value of this useContext() call is whatever data the context provider provides.</p><p>The rest of the code listing shows how this (simplified) Login component uses the context data. There are three possible cases. In the first case, there is no user data available at all, probably because it has not been fetched yet. In that case the Login() function returns null, rendering nothing. Otherwise, if the userData object is non-null and shows that the user is logged in, then the component renders the user’s profile picture. And finally, if we have userData, but it shows that the user is not logged in, then the component renders a “Sign in” link.</p><p>You can see that the useContext() hook makes it really easy for my Login component to access and use information about the current user. But where does that context data come from? Here’s an excerpt from the top-level index.jsx file that kicks off the React rendering process:</p><pre>ReactDOM.render(<br>  &lt;DocumentProvider&gt;<br>    &lt;UserProvider&gt;<br>      &lt;Page /&gt;<br>    &lt;/UserProvider&gt;<br>  &lt;/DocumentProvider&gt;,<br>  document.getElementById(&#39;react-container&#39;)<br>);</pre><p>In this React-based version of site that I’m working on, a page is rendered by a Page component, inside a UserProvider component which is itself inside a DocumentProvider component. The UserProvider component is responsible for setting up the user context object and providing the appropriate data for that. (DocumentProvider does something similar for the content of the page, and is also responsible for client-side navigation among pages on the site, but that is a topic for another blog post.)</p><p>So, when an page is rendered, the UserProvider component sets up a context object for sharing data about the user, and provides that data. Then it renders its child, the Page component. The Page component renders a Header component (which we haven’t discussed here) which in turn renders the Login component. The Login component uses the useContext() hook to get access to the context data that the UserProvider context defined.</p><p>Here’s a <em>very</em> simplified version of how the UserProvider component is implemented:</p><pre>import { createContext } from &#39;react&#39;;</pre><pre>const context = createContext(null);</pre><pre>export default function UserProvider({ children }) {<br>  return (<br>    &lt;context.Provider value={null}&gt;<br>      {children}<br>    &lt;/context.Provider&gt;<br>  );<br>}<br>UserProvider.context = context;</pre><p>This code imports React’s createContext() function and uses that function to create a context object for sharing user context with other components. It then defines an exported UserProvider component, and tacks the context object onto the UserProvider component so that it is exported, too. The way the React context API works is that every context object has a Provider property whose value is a React component. To set the value of a context, you render this &lt;context.Provider&gt; component, setting its value prop to the context data to be shared with consumers. The UserProvider component defined above tries to hide some of this complexity: it renders the context.Provider component, hardcoding a value of null, and then renders its own children inside of that provider.</p><p>I’ve shown this code here to demonstrate how React context providers work. Note, however, that this version of UserProvider is completely useless, because it always provides the value null. In order to actually provide meaningful data, we need to introduce the useState() and useEffect() hooks.</p><h3>useState()</h3><p>React components use state when they want to change their appearance based not on properties passed in to them, but instead based on something that has happened to them. If you were implementing a dropdown menu with React, for example, you might use a state variable to keep track of whether the menu is opened or closed. The component’s rendering code would be written to render the menu in its open or closed state based on the value of the state variable. And the rendered menu would have mouse event handlers that would set the state variable depending on where and when the user clicked the mouse. One of the key things to understand about state in React components is that when the state changes, React re-renders the component. So in a dropdown menu component, a user’s mouse click might cause the component’s open state variable to change from false to true. This state change causes the menu to be re-rendered. The render code looks at the value of that open variable and renders the open form of the menu instead of the closed form of the menu.</p><p>Most often when a React component uses state, state changes are caused by mouse or keyboard events. But state can also changes based on timer or network events. It is network events that we’re interested in for the UserProvider component. When the page first loads, the UserProvider will be in its initial state: it won’t have any data about the user, and the context value will just be null. But we’ll ask the server to tell us about the current user (which it can do based on the user’s session cookie). And when we get a response to that query, the UserProvider will be in a new state: the state where it knows about the user.</p><p>Here’s a version of the UserProvider component that uses the useState() hook to define and manage it state:</p><pre>import { createContext, useState } from &#39;react&#39;;</pre><pre>const context = React.createContext(null);</pre><pre>export default function UserProvider({ children }) {<br>  const [userData, setUserData] = useState(null);<br>  return (<br>    &lt;context.Provider value={userData}&gt;<br>      {children}<br>    &lt;/context.Provider&gt;<br>  );<br>}</pre><pre>UserProvider.context = context;</pre><p>This version of UserProvider imports the useState() hook, and then calls it to define a state variable. The argument to useState() (in this case null) is the initial value of the state. The return value of useState() is an array of two elements. The first is the current value of the state variable, and the second is a function that you can use to set a new value for the variable. It is conventional to use destructuring assignment into a matched pair of names (like userData and setUserData) as we have done here.</p><p>Our call to useState() returns the current value of the state variable and stores it in the userData constant. On the next line, we use userData as the value of the context provider component. This means that any descendant components (like our Login component) that call useContext(UserProvider.context) will have access to the value of that userData state variable.</p><p>When this UserProvider component is first rendered, the useState() is called for the first time, and its null argument is used as the initial state value, and as the first element of the returned array. If setUserData() were to be called, the argument to that function would become the new value of the state variable. The state change would cause the component to be re-rendered. In that new render, useState() is called a second time. But this time, the null argument is ignored and the new current value is returned as the first element of the array. (As noted in the introduction to hooks above, this is the magical and non-intuitive part of hooks. If you’re feeling confused right now you might want to go re-read that section.)</p><p>In our case, there isn’t anything that ever calls setUserData(), so the state never changes, and this UserProvider always provides the same useless value null. We need to ask the server for information about the user, and to do that we need the useEffect() hook.</p><h3>useEffect()</h3><p>The useEffect() hook takes a function as its first argument and, by default, runs that function after every render. Used with one argument like this, it is similar to a class-based component that defines componentDidMount() and componentDidUpdate() methods. If the effect you want to achieve is something like registering a global event hander, then you may need cleanup code to remove the event handler when it is no longer needed. If your effect function returns a function, React will remember that function and invoke it before the next invocation of the effect function, and also when the component is unmounted. I won’t be using that feature in this blog post, but it is worth remembering that effects registered with useEffect() have a cleanup option.</p><p>For our UserProvider component, the effect we want is to fetch user data from the server. But we only need to do this on the first render. We don’t expect the data to change, so we don’t want to re-fetch it on subsequent renders. useEffect() takes an array as an optional second argument. If you pass an array, then the values in it are used as a kind of cache key, and your effect function is only called on the first render, or when the values in the array change.</p><p>Suppose you are writing a component that has three properties and two state variables. The component will be rerendered if any of those five values changes. But suppose that it uses the useEffect() hook to register an effect function that only depends on two of those five values and does not need to be re-run when any of the other three values change. In that case, you can simply pass an array of those two relevant values as the second argument to useEffect(). Your effect function will only be invoked on the first render, and then on any subsequent render when the array of values is different than the array passed previously.</p><p>Notice that this means that if you pass an unchanging constant array as the second argument, then the effect function is only invoked once, and we get something similar to componentDidMount() for class-based components. When this is what you want, it is normal to pass the empty array as the second argument, and that is what you’ll see in the updated version of the UserProvider component below:</p><pre>import { createContext, useState, useEffect } from &#39;react&#39;;</pre><pre>const context = createContext(null);</pre><pre>export default function UserProvider({ children }) {<br>  // The useState() hook defines a state variable.<br>  const [userData, setUserData] = useState(null);</pre><pre>  // The useEffect() hook registers a function to run after render.<br>  useEffect(() =&gt; {<br>    fetch(&#39;/api/v1/whoami&#39;)        // Ask the server for user data.<br>      .then(response =&gt; response.json()) // Get the response as JSON<br>      .then(data =&gt; {                    // When data arrives...<br>        setUserData({                    // set our state variable.<br>          username: data.username,<br>          isAuthenticated: data.is_authenticated,<br>          timezone: data.timezone,<br>          gravatarUrl: data.gravatar_url<br>        });<br>      });<br>  }, []);  // This empty array means the effect will only run once.</pre><pre>  // On the first render userData will have the default value null.<br>  // But after that render, the effect function will run and will<br>  // start a fetch of the real user data. When the data arrives, it<br>  // will be passed to setUserData(), which changes state and<br>  // triggers a new render. On this second render, we&#39;ll have real<br>  // user data to provide to any consumers. (And the effect will not<br>  // run again.)<br>  return (<br>    &lt;context.Provider value={userData}&gt;<br>      {children}<br>    &lt;/context.Provider&gt;<br>  );<br>}</pre><pre>UserProvider.context = context;</pre><p>In this final version of UserProvider, the useEffect() and useState() hooks are intertwined: the useEffect() hook triggers a network request for user data after the first render, and when that data arrives, the effect function passes it to the setUserData() function that was returned by the useState() hook. This change to the state variable causes the component to be re-rendered, which updates the context provider with the newly-received user data. And this means that functions like the Login component elsewhere in the tree can access that data with the useContext() hook.</p><h3>Further Reading</h3><p>The Login and UserProvider components I’ve described here were fun to work on, and it was particularly satisfying to see how useContext(), useState(), and useEffect() all came together to make them work. If you are a React developer, I hope I’ve passed on my enthusiasm for the new hooks API. If so, here are some ways you can learn more:</p><ul><li>If you’d like to take a closer look at the (non-simplified versions of the) Login and UserProvider and related components, you can find them <a href="https://github.com/mozilla/kuma/tree/master/kuma/javascript/src">on GitHub</a>. (That link is valid at the time of this writing, though UserProvider is actually called CurrentUser. Our React-based code is experimental and changing fast, so it is likely that the code will move and this link will quickly go stale.)</li><li>A key feature of the UserProvider component described in this post is that it uses client side JavaScript to dynamically request data from the web server. If you are not already comfortable with the fetch() function used to make the network request, you can find <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">comprehensive documentation on MDN</a>.</li><li>Finally, if you’d like to read more about hooks in React, the <a href="https://reactjs.org/docs/hooks-intro.html">documentation from the React project</a> is quite good.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa899d8c8014" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bannon Must Go!]]></title>
            <link>https://medium.com/@__davidflanagan/bannon-must-go-c89e9a2a8573?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/c89e9a2a8573</guid>
            <category><![CDATA[alt-right]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[bannon]]></category>
            <category><![CDATA[2016-election]]></category>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Mon, 14 Nov 2016 21:54:47 GMT</pubDate>
            <atom:updated>2016-11-14T22:03:04.529Z</atom:updated>
            <content:encoded><![CDATA[<p>Our tax dollars should not pay for a white nationalist in the White House.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*qSRQPMeTnl8FzQa3sH5IDg.jpeg" /></figure><p>Donald Trump has hired Steve Bannon to be his “Chief Strategist and Senior Counselor”, a position said to be an “equal partner” with his Chief of Staff. As is clear from the job title, Bannon will have the President’s ear. Here’s what is known about this man:</p><ul><li>Until he joined the Trump campaign, Bannon was the head of the right-wing website <em>Breitbart News</em> and called it “a platform for the alt-right”. The alt-right is a movement that aims to destroy multi-culturalism and longs for an imperial apartheid “<a href="http://www.motherjones.com/politics/2016/09/alt-right-makes-its-main-stream-debut">homeland for all Europeans</a>.”</li><li>It is apparently a matter of debate within the alt-right movement whether European Jews would be welcome in this white homeland, but it <a href="http://www.nydailynews.com/news/election/trump-campaign-ceo-bannon-complained-jews-daughters-school-article-1.2767615">appears clear</a> that Bannon himself is an anti-Semite who objected to his daughters attending school with Jews.</li><li>Bannon is a <a href="http://nymag.com/thecut/2016/11/what-steve-bannon-thinks-of-women-and-minority-groups.html">misogynist</a> who has called feminists “a bunch of dykes”.</li><li>In 2014, Bannon <a href="http://www.thedailybeast.com/articles/2016/08/22/steve-bannon-trump-s-top-guy-told-me-he-was-a-leninist.html">explained his politics</a> like this: “Lenin wanted to destroy the state, and that’s my goal too. I want to bring everything crashing down, and destroy all of today’s establishment.”</li></ul><p>Bannon is a radical with extreme-right views that are well outside of America’s consensus about who we are as a nation. He apparently does not hold it to be self evident that we are all created equal, and his intolerance and bigotry should have no place in the White House. We can’t control who Trump talks to, but as taxpayers and citizens, surely we have a say in who draws a government salary and who has an office in the West Wing.</p><p>We should demand that Trump fire Bannon immediately. I think this is a fight we should take up now, and I think we can win it:</p><ul><li>In his victory speech, Trump said he’d be “president for all Americans”, and then in one of his first official acts as President-elect he’s named Bannon as his top aide. Trump had a chance to show that his administration would be different than his campaign and he’s signaled just the opposite. Bannon’s appointment is a specific, concrete act that we can protest. Protesting Trump’s election itself seems futile to me. But protesting this extremist appointment gives us a clear demand — fire Bannon — and a goal to focus on.</li><li>Political action over presidential advisors is not unusual. South Korea is currently experiencing its <a href="http://www.nytimes.com/2016/11/13/world/asia/korea-park-geun-hye-protests.html?_r=0">largest protests in decades</a> because of public outrage about who their president has been getting advice from. The Koreans are going straight to the top, however, and are calling on their president to step down.</li><li>Remember what the right did to Obama’s green jobs czar Van Jones and Clinton’s surgeon general Joycelyn Elders. Administrations will drop appointees when the controversy becomes more trouble than it is worth. We need to learn to make trouble for the Trump administration. Let’s start practicing on Bannon.</li><li>Trump’s transition must surely be in an unstable stable right now with multiple factions vying for power in the administration. Bannon presumably has enemies within some of those factions, and an immediate hard push from the left combined with pressure from the inside could be enough to remove him.</li><li>We must always remember that there are more of us than there are of them. Clinton won the popular vote by a wide margin, and not all of Trump’s voters approve of overt white nationalism, anti-Semitism and misogyny in the White House.</li><li>If we can mobilize large enough protests against Bannon, we can win either way. If Trump fires him, we win. If not, then we’ve forced Trump to double-down on his embrace of the alt-right, and we’ve highlighted to America what a dangerous radical will soon be taking the oath of office.</li></ul><p>Here are some people and organizations that have already condemned Bannon:</p><ul><li>The <a href="https://twitter.com/JGreenblattADL/status/797984801248673792">Anti-Defamation League</a></li><li>The <a href="https://www.splcenter.org/news/2016/11/14/splc-bannon-must-go">Southern Poverty Law Center</a></li><li><a href="https://twitter.com/sahilkapur/status/797987628809273344?lang=en">Senator Harry Reid</a> of Nevada</li><li><a href="https://www.merkley.senate.gov/news/press-releases/merkley-denounces-appointment-of-white-nationalist-to-top-white-house-post">Senator Jeff Merkley</a> of Oregon</li><li><a href="https://twitter.com/RonWyden/status/798272981290119169">Senator Ron Wyden</a> of Oregon</li><li>Former Republican strategist <a href="https://twitter.com/ananavarro/status/797917812819955712">Ana Navarro</a></li><li>John Kasich’s chief strategist <a href="https://twitter.com/JWGOP/status/797915707199680512">John Weaver</a></li></ul><p>If you’ve got others to add to this list, please leave comments. Please call your senators, if you haven’t already, and ask them to condemn Bannon.</p><p>I’d love to see US corporations speaking out against this un-American appointment, though I confess that I don’t really know how we can pressure them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c89e9a2a8573" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inquisitive Programming]]></title>
            <link>https://medium.com/@__davidflanagan/inquisitive-programming-3a765cc98655?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a765cc98655</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[stem]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[computational-inquiry]]></category>
            <category><![CDATA[inquisitive-programming]]></category>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Thu, 29 Sep 2016 23:26:29 GMT</pubDate>
            <atom:updated>2016-10-11T18:50:05.977Z</atom:updated>
            <content:encoded><![CDATA[<p>There have been many calls in recent years for the introduction of computer science into the US K12 school system. <a href="https://code.org/">Code.org</a> is one of the well-known organizations advocating for computer science in our schools. They describe themselves like this:</p><blockquote><em>Launched in 2013, Code.org® is a non-profit dedicated to expanding access to computer science, and increasing participation by women and underrepresented students of color. Our vision is that every student in every school should have the opportunity to learn computer science. We believe computer science should be part of core curriculum, alongside other courses such as biology, chemistry or algebra.</em></blockquote><p>President Obama, in his <a href="https://www.whitehouse.gov/the-press-office/2016/01/12/remarks-president-barack-obama-%E2%80%93-prepared-delivery-state-union-address">2016 State of the Union address</a>, said:</p><blockquote><em>We agree that real opportunity requires every American to get the education and training they need to land a good-paying job…. [T]ogether, we’ve increased early childhood education, lifted high school graduation rates to new highs, boosted graduates in fields like engineering. In the coming years, we should build on that progress, by providing Pre-K for all and offering every student the hands-on computer science and math classes that make them job-ready on day one.</em></blockquote><p>The Computer Science Teachers Association (a division of the ACM, a professional society for computer scientists and software engineers) has this to say about <a href="https://csta.acm.org/Curriculum/sub/CurrFiles/ExecSummCSS.html">computer science in K12 education</a>:</p><blockquote><em>Over the past few decades, computers have transformed both the world and the workforce in many profound ways. As a result, computer science and the technologies it enables now lie at the heart of our economy and the way we live our lives. To be well-educated citizens in a computing-intensive world and to be prepared for careers in the 21st century, our students must have a clear understanding of the principles and practices of computer science. No other subject will open as many doors in the 21st century as computer science, regardless of a student’s ultimate field of study or occupation.</em></blockquote><p>I chose these three particular quotes not to single out code.org or the Obama administration or the CSTA, but because they seem representative of our current national discourse about computers in schools. There is a lot to unpack and critique in the quotes, but first, for readers who are not themselves computer scientists, let’s define some terms.</p><h3>Some Definitions</h3><p><em>Computer science</em> is not actually a science like physics, biology or psychology. At the undergraduate level, computer science is primarily an engineering discipline, and at the graduate level it is also a field of applied mathematics. Some working computer scientists do a lot of computer programming, and some spend very little time actually programming.</p><p><em>Software engineering</em> is the professional practice of programming computers to create robust, high-quality computer software that is embedded in products, installed on servers, used by customers, or otherwise “deployed” out into the world. Software engineers have often studied computer science, but this is not required and many enter the profession without formal training in computer science.</p><p><em>Coding</em> is an informal synonym for computer programming. Both programming and coding describe the craft of translating ideas into “code”–a set of instructions, expressed using the formal syntax of a computer programming language, that make a computer perform the desired computations. Coding is the primary daily activity of software engineers, but this craft of writing computer programs is also useful in other fields to crunch data, model systems, and perform repetitive or complicated calculations. An astrophysicist, for example, might use coding to simulate the lifecycle of a star, a social scientist might use coding to perform a statistical analysis on data, and a mathematician might use coding to numerically test a conjecture. (These are all examples of coding for <em>computational inquiry</em>, a term that I’ll be using much more later in this essay.)</p><h3>The Cult of Computer Science</h3><p>With those terms defined, let’s take a closer look at the proposals quoted above for integrating computer science into K12 education. Code.org says “computer science should be part of core curriculum, alongside other courses such as biology, chemistry or algebra”. It makes sense for high schools to offer at least one actual computer science class for college-bound students who are planning to study computer science. But code.org also says that “every student in every school should have the opportunity to learn computer science”. So they’re not just interested in high schools, and since it doesn’t make sense to teach college-prep classes in elementary and middle school, code.org obviously isn’t talking about actual computer science. It is pretty clear from their online offerings (and from their very name) that what they really mean is coding. They’d like every student at every school to have the opportunity to learn to code. That’s great, and I agree, but let’s not call it “computer science” when it is not.</p><p>President Obama also advocates for computer science in schools, but he calls it “hands-on computer science” by which I think he can only mean coding. But he goes on to say that this is about being “job-ready”, so perhaps he is actually advocating for software engineering in our schools. The sentiment is a good one, but the idea that K12 education can educate “job-ready” students for professional software engineering jobs is a pipe dream. The most advanced programming class in today’s high schools is typically the AP Computer Science class, which teaches students to write program fragments; sadly, most graduates of AP CS would be hard-pressed to actually write a computer program. Professional programming skills are developed over time and there are simply not enough hours in the school day or days in the school year to teach these skills. That is like asking the high school marching band to train musicians who are ready for professional orchestra jobs. Exceptionally dedicated young people who spend thousands of hours outside of school working on programming (or music!) may be job-ready by the time they graduate from high-school. Within our schools, however, there is no place for software engineering except perhaps in the context of vocational-technical programs that serve specialized niches in the tech industry.</p><p>President Obama also called for math classes along with “hands-on computer science” as a way to make students “job ready” upon graduation. He’s obviously not suggesting that high school grads be ready for jobs as mathematicians, so I think he’s not suggesting that they be ready for software engineering jobs either. Instead, I believe he’s suggesting that students who graduate from high school with math and coding skills will be better prepared for the modern workplace. I’m not sure that many jobs that require coding skills will be available without a college degree, but I more-or-less agree with President Obama and will argue below that coding skills are a necessity for STEM jobs, even those unrelated to computer science and software engineering. Again, however, let’s use precise language and not confuse the craft of coding with the academic discipline of computer science. If I can belabor this point a bit, it is also true that 21st century jobs require strong written communication skills. This does not mean that we need more literature classes in high school; it means that we need to teach students the craft of writing.</p><p>Code.org and President Obama misuse the term “computer science” when they really seem to mean coding, but if we switch the words around then what they’re proposing seems pretty reasonable. The quote from the CSTA, however, is a different matter. It begins with an obviously true statement: “computers have transformed both the world and the workforce in many profound ways”, but from there, the CSTA launches into pure hyperbole, and I’d like to take the time to rebut the next three sentences:</p><p><em>As a result, computer science and the technologies it enables now lie at the heart of our economy and the way we live our lives.</em></p><p>It is true that our society is utterly dependent on computers today. And without computer scientists, software engineers and other professionals in the “tech industry” it might all come crumbling down. But our society is just as dependent on the electrical grid, the transportation network, medicine, agriculture, refrigeration and water supply and sewer systems, and if we lost all of our civil engineers or farmers or power grid operators society would break down just as quickly. No one is arguing for the addition of civil engineering, power engineering or agriscience to the K12 educational system. What makes computer science more essential, more valuable, than these other professions?</p><p><em>To be well-educated citizens in a computing-intensive world and to be prepared for careers in the 21st century, our students must have a clear understanding of the principles and practices of computer science.</em></p><p>This is just an insult to well-educated citizens everywhere. If all educated people must understand the principles and practices of computer science, then they must also understand the principles and practices behind our other essential infrastructure. I understand how internal combustion engines and refrigerators work, but I have only a fuzzy understanding of the principles of thermodynamics behind those technologies. I can discuss the vulnerability of our electrical grid to solar flares, and explain the differences between primary, secondary and tertiary treatment at sewage treatment plants, but I certainly don’t know the principles and practices of power engineering or civil and sanitary engineering. Does that mean I am not a well-educated citizen?</p><p><em>No other subject will open as many doors in the 21st century as computer science, regardless of a student’s ultimate field of study or occupation.</em></p><p>Computers have changed our society in profound ways (as did the automobile and television in the last century). And our educational system should certainly adapt in response. But this idea that there is a single subject called “computer science” that we can just tack on to the K12 curriculum is absurd. One obvious question is what do we take out of the curriculum to make room for this new subject? Music? Literature? Geography? Long division? But more fundamentally, we need to recognize that the societal impacts of any technological revolution lie primarily outside of the discipline that created the revolutionary technology. To be well-educated citizens in a world transformed by computers, we don’t need to study the math and science and engineering behind the computers; we need to study the transformations they have caused:</p><ul><li>Computers have transformed our modes of formal communication, and schools have adapted by teaching students to type, to send email, to use word processors, to create presentations and even to edit video.</li><li>The internet and social media have transformed our social networks and our modes of informal communication. Some schools have adapted by hosting assemblies each year to teach students about cyberbullying online safety.</li><li>The advent of digital photography and creation of powerful photo editing software have transformed the relationship between photographs and reality. Schools should adapt by updating their health curricula to cover the impact of Photoshop and fashion magazines on teen body image.</li><li>The digitization and computerization of our communication networks have made our phone calls easier to intercept and record in bulk and the adoption of digital encryption has made our secrets easier to conceal. Schools should adapt to these changes by revising their civics curricula to include discussions of privacy, the fourth amendment and surveillance.</li></ul><p>These are all important educational responses to the computer revolution, but none of them is computer science.</p><h3>The Value of Coding</h3><p>Once we reject the misguided clamor about computer science, we’re still left with many well-intentioned proponents of and proposals for exposing school children to coding. I’m one of those proponents, and for me, there are four primary reasons that schools should teach basic programming skills:</p><p>First, computers and networks have become essential infrastructure for modern society. Computers are complex enough, however, that without educational intervention they will just be mysterious and ubiquitous black boxes. So I believe that we should teach students about computers for the same reasons that we take students on field trips to farms and water treatment plants: so that they learn about the infrastructure that our civilization rests upon. And furthermore, I believe that the best way to demystify computers, to teach students what they really do, is to show students how to control them with code.</p><p>Second, students who go to work in STEM fields (or study those fields in college) will likely need to write simple computer programs as part of their work. We should not teach programming as job training or because we anticipate a need for more professional software engineers, but because a large sector of the future workforce will need basic programming skills for their daily work. Just as word processing is a skill needed by most white collar workers today, coding is a skill that will be needed by most STEM workers in the future.</p><p>Third, teaching programming enables powerful new approaches for teaching math and science through computational inquiry<em>,</em> and enables students to understand these topics in new ways. I’ll have much more to say about computational inquiry below, but my essential point is that teaching students to program will open important new avenues to learning in other fields.</p><p>Finally I’m convinced that programming teaches and develops our capacity for rigorous, analytical, algorithmic thinking, and does so with an intensity that other disciplines do not. That is: learning to program requires students to learn and practice an important and valuable mode of thinking. I believe, for example, that an exposure to computer programing will help lawyers be better lawyers, doctors be better doctors, and scientists be better scientists. And more generally, I believe that students who have access to this focused, rigorous, analytical mode of thinking will be better citizens. In my experience, computer programming is a particularly effective way to provide that access. This is a controversial idea however (one that computers-in-education pioneer Seymour Papert <a href="http://worrydream.com/#!/MeanwhileAtCodeOrg">explicitly rejected</a>) and the main points of this essay stand, even if you reject this final reason for teaching programming in our schools.</p><h3>Code for Code’s Sake</h3><p>Any discussion of coding in schools should start with the realization that teachers already have a full school year of material mandated by state educational standards, and there is simply not time to add entirely new topics, except in the form of for cursory, one-off exercises like an annual “hour-of-code”. Even if we accept that programming teaches thinking and that coding is good in and of itself, I don’t believe that it is an effective use of teacher’s time to teach coding in isolation. Unfortunately, the most accessible programming curricula today tend to teach code for code’s sake.</p><p>Here’s code.org’s elementary school “<a href="https://studio.code.org/s/course2/stage/6/puzzle/12">code studio</a>” programming environment, for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NMTeTaJJBxbEV0wa." /></figure><p>The student’s task is to write a program in this visual programming language to guide the zombie to the sunflower while avoiding the zombie-eating plant. This is a very common approach for teaching young students about instruction sequences and loops in code. But this exercise is purely about the mechanics of the code: the student has to figure out the puzzle of how to position the code “blocks”, but does not learn anything about geometry, for example. And because it is a purely mechanical exercise, and not intrinsically interesting in its own right, the programming environment tries to keep the student’s interest by making creepy zombie sounds when she runs the program.</p><p>Apple makes a learn-to-program app for iPads that also takes this approach of asking a student to write a program that will navigate a character through a maze or puzzle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*7HOmwL13sQ9qCcoj." /></figure><p>Like the code.org example, this is code for code’s sake. It is a lesson in conditionals and boolean operators, which is necessary in any coding curriculum, but there is nothing larger here for the student to learn. Presumably the student remains engaged because of the sophisticated graphics and gameplay, not because there is anything engaging about the code itself.</p><p>Note that in both of these labyrinth puzzle examples, the programming is completely divorced from computation. Students are not learning that computers are for computing things. The programming environment (where simple commands move complicated graphics around the screen) is so abstract that it must be hard for students to see much connection between what they type and what appears on the screen in response.</p><p>Khan Academy’s learn-to-program environment looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*yw1tT6un-9kOgmah." /></figure><p>The student is challenged here to modify an existing program to use a symbolic name for the diameter of the bunny’s eyes. This example includes lots of numbers and satisfyingly concrete geometric objects, which is an improvement over the puzzle exercises, but it is still code for code’s sake.</p><p>It may seem unfair to criticize Khan academy and Apple and code.org for these examples. If we want to teach programming, we have to teach variables and conditionals and loops, as these examples are doing. At some level, code for code’s sake is required because we have to teach the syntax of the underlying programming language. But if we look at how these curricula develop as the student progresses we’ll see that they are just coding exercises that lead to more advanced coding exercises. Students learn that coding is just a series of puzzles to solve, not a problem-solving skill with a purpose.</p><h3>Code for Computational Inquiry</h3><p>The computer revolution has radically transformed the practice of science and engineering (and mathematics to a lesser extent). The massive computational power of today’s computers allows scientists and engineers to collect, analyze and visualize huge amounts of data and to model complex systems with unprecedented precision. These are the sorts of tasks that I call <em>computational inquiry</em>. Schools have not kept up with this transformation. Graphing calculators, decades out of date, are one of the only signs of the computer revolution visible in our math and science classes. Students can use those calculators for simple computational inquiries in math classes, but that is a far cry from what is possible with modern computers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*aKrUWhpB3m3lvjU3hcu8kQ.png" /><figcaption>A prototype computational inquiry</figcaption></figure><p>Computational inquiry is not just for working scientists–it has revolutionary applications in the classroom as well. Elementary school students are often asked to repeatedly roll a pair of dice, adding the numbers that appear on the dice and drawing a histogram to show the frequency of each sum. If a student does this 25 times she’ll have a blocky-looking histogram that might look something like a bell curve. With computational inquiry, though, she could simulate 100 dice rolls, or 1000, or 100,000 and see how that affects the shape of the histogram. She could modify the program to roll 10 dice at a time, or to roll 12-sided dice. The figure shows a rough prototype of what this inquiry might look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*Hqu0d3KVaYImVRuVhSClpg.png" /><figcaption>Computational inquiry in physics</figcaption></figure><p>Another obvious use for computational inquiry is for simulation of physical systems like projectiles and planetary orbits. Typically, a careful exploration of systems like these is deferred until students are studying calculus so that they can do the required math symbolically. This pedagogical approach is out of date, however, since we can now use computational inquiry and simulate the systems numerically. (Inquiries like these can also be done as <a href="https://docs.google.com/spreadsheets/d/1qhL7RgrVTCB4cZwUae-_RpTGizGLe0O3zP1vgWbuJIw/edit#gid=0">a spreadsheet</a>.)</p><p>A final example of a computational inquiry is Bret Victor’s essay <a href="http://worrydream.com/LadderOfAbstraction/">Up and Down the Ladder of Abstraction</a>. This is a beautiful and professionally done inquiry that involved significant programming effort to create the custom visualizations involved. I include this here as an inspirational example of computational inquiry only–the ability to create dynamic documents this complex is beyond the scope of what I’m proposing here.</p><p>In order to perform computational inquiries, teachers and students have to be able to express their inquiries using code (even if they start with spreadsheet formulas as their code). This is a mundane skill that scientists and engineers use daily, and students should learn this skill so that they can learn science the way it is actually practiced. Schools teach students to type and to use word processing software because those tools help them to craft effective written documents. Schools teach students to use presentation software like PowerPoint because it is a tool for organizing their thoughts and enhancing their oral presentations. In exactly the same way, schools should teach students to use coding software as a tool for computational inquiry in their math and science classrooms. This is the context that is missing from current coding initiatives. By teaching coding in math and science classes we avoid the trap of code for code’s sake.</p><h3>Let Teachers Teach</h3><p>Note that these the coding exercises from code.org and Apple and Khan Academy are designed for students to complete on their own, with no teacher required. This may be perfect for advanced students who need classroom enrichment, or for learners who are teaching themselves outside of the classroom, but it isn’t a curriculum that we can expect teachers to adopt for their entire class since there is no teaching for them to do.</p><p>Our current generation of teachers were not taught to code when they were in school, and we can’t expect them to teach coding for coding’s sake. Coding without context means coding without teachers. But if we teach coding as a tool for computational inquiry in math and science, then every coding lesson is in context and the teacher has something to teach.</p><p>If we want students to learn to code, we need teachers to teach them. And if we want teachers to teach coding, we need them to learn to code themselves. But what busy teacher has the time to learn a new skill when the only purpose of that skill is to navigate an annoyingly noisy zombie through a series of mazes? Instead, let’s show teachers that coding can be a tool for eliciting deeper understanding of math and science concepts from their students. If we do that, I believe that teachers will engage and be much more motivated to learn coding themselves because they will want to design computational inquiries of their own and use them confidently in the classroom.</p><p>I’ve been criticizing code.org a lot in this essay, so I should point out that code.org’s <a href="https://code.org/curriculum/science/files/Code.org_MS_Science_Program_two_pager.pdf">“CS in Science” curriculum</a> does just what I’m advocating here: teaches coding in the context of middle-school science classes.</p><h3>Inquisitive Programming</h3><p>I used a word processor analogy above: schools teach students to use word processors because they are important tools for written communication, and they should teach students to use coding software because it is an important tool for mathematical and scientific inquiry. In the world of software engineering, we use the term IDE or “integrated development environment” instead of “coding software”. An IDE is an application (like a word processor or spreadsheet), specially designed for coding. I envision an IDE–let’s call it <em>Inquire</em>–developed for use in schools and and designed not for general purpose coding, but specifically for computational inquiry. In this final section I want to describe my vision for this <em>Inquire</em> application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hjZm5dvlA7t6IHtn3rt1qw.png" /><figcaption>A computational inquiry in a prototype of coding environment</figcaption></figure><p>An IDE for use in schools has to satisfy some strict design constraints:</p><ul><li>Different schools have different types of computers, so our IDE must be <strong>cross-platform</strong>, so it can run on any kind of computer.</li><li>Schools districts often have security policies that make it difficult to install new software on school computers, so our IDE must be <strong>zero-install</strong>: that is, it must not require software installation. In practice, this means that it must be web-based (just as code.org and Khan Academy’s offerings are).</li><li>Teachers must be able to run student code safely without fear that the code can harm their computer in any way. In programming terms, we say that the code must be sandboxed, so that it cannot do things like create or delete files. JavaScript code that runs in web browsers is sandboxed, so by making the IDE web-based and running code in the browser, we guarantee that the the IDE is <strong>safe</strong>.</li><li>School districts never have as much money as they like, so the IDE should be <strong>free</strong>. This means that it should also be open-source software so that volunteers are willing to contribute to its development.</li><li>Since this IDE is aimed at programming novices, it should be <strong>easy</strong> to use. The goal is not to enable software engineering, but to support computational inquiry with real coding. As a first approximation to making the IDE easy to use it must be simple, with a minimal set of features. Students should not have to learn a complex new program while they’re also trying to learn the syntax of a new programming language. Note also that although this IDE must be web-based, it is not a goal to enable web programming (which is anything but easy).</li></ul><p>It is straightforward to think about the design of an IDE for schools and to come up with a list like the one above. It is more difficult, however, to design an IDE for computational inquiry because computational inquiry is not a programming paradigm that most software engineers are very familiar with. In order to make it clear that we are, in fact, talking about a new programming paradigm here, I’m going to go ahead and propose a name: <em>inquisitive programming</em>. My thinking about inquisitive programming is influenced by other systems and paradigms:</p><ul><li><strong>The web:</strong> documents on the world-wide web are public by default and are shareable across the globe. Inquisitive programming should adopt this shareable, document-centric approach. Programs (or “inquiries”) should be web documents automatically saved in the cloud and assigned a unique URL so that users can access, edit and run them from any computer in the world, and can share them with others simply by sharing the URL. Websites like <a href="https://jsfiddle.net/">jsfiddle.net</a> and <a href="http://codepen.io/">codepen.io</a> have pioneered this “shared programs in the cloud” approach for web programming, and I’d like to follow their lead with inquisitive programming.</li><li><strong>Literate programming</strong>: computer programming languages always have some kind of “comment” syntax for including arbitrary prose within a program. The idea is that programmers can use comments to document and explain their program, making it easier for others to understand, modify and maintain. In the 1980s, software pioneer Donald Knuth proposed a programming paradigm he called “literate programming” that inverted this relationship between code and comments. In Knuth’s system, the explanatory prose is primary and there is a special syntax for including arbitrary code within the prose. This has always seemed like a brilliant idea to me, and I consciously chose the term “inquisitive programming” to echo Knuth’s “literate programming”. The point of computational inquiries is to ask questions, to explore and explain complex systems in an educational context, and this is not possible with code alone. When a student writes a program to simulate a physical system, for example, we need prose to tell us what the system being simulated is, to justify the choice of constants and initial conditions, to enumerate the system’s state variables and to explain how those variables will be updated over time. And just as importantly, when the program produces visualizations, we need prose to explain what those visualizations show and to draw appropriate conclusions. In a very important sense, inquisitive programming is a form of technical communication. An IDE that puts explanatory prose first and embeds code within that prose seems ideal for this kind of programming.</li><li><strong>Interactive notebooks</strong>: the professional math application <em>Mathematica</em> and the web-based <em>Jupyter</em> software have pioneered a new form of programming that is growing increasingly popular for scientific computing. This style of programming is interactive, so that instead of typing and then running a complete program, the user can type a single command and see the results of that command immediately. And it uses the organizing metaphor of a lab notebook in which all previous commands and results are retained on the page so that you can scroll back and see what computations you performed in the past. Another key feature of these notebook-based systems is that they include powerful graphical tools for visualizing the results of your computations. Notebooks are popular with professionals and at the university level, but I believe that they are too complicated for K12 use. There are two features of notebook-based programming that I would like to borrow for inquisitive programming, however. The first is the visualizations. When coding for computational inquiry, the numeric results of the computation rarely stand on their own. For understanding and insight, those numbers must be visualized graphically. So an IDE for inquisitive programming must have rich and intuitive visualization features built-in. The second, more fundamental feature that I’d like to borrow from the notebook paradigm is the idea that code and the results of running that code can and should be interleaved. In traditional programming a program and the output it produces are two entirely separate things. In notebook-based programming and in inquisitive programming, the code accompanies the results. That code may be secondary to the explanatory prose and visualizations that accompany it, but it is still a critical part of the inquiry, and must be included in the document that is the finished work product of a computational inquiry. The process of coding transforms complex ideas into a sequence of simple, universal computational steps; code is the distilled essence of the coder’s thought process. Code can be checked for correctness and it can be re-run to replicate computations. Code is the ultimate form of “show your work” and I believe that both students and practicing scientists should all be held to a “show your code” standard in their documents and publications.</li></ul><p>To summarize, I’m proposing a free, open-source web-based programming environment called <em>Inquire</em> that empowers science and math teachers and their students to create code-based computational inquiries. A program, or <em>inquiry, </em>in this environment combines prose, code, and the visual results of running that code into a single document that can be shared on the web. Further, I’m proposing that we use this environment and the new paradigm of inquisitive programming to teach coding and to modernize the teaching of math and science in US middle schools and high schools.</p><p>I’ve posted a very early stage prototype of <em>Inquire</em> <a href="https://github.com/davidflanagan/Inquire">on github</a> and you can see and experiment with example inquiries <a href="https://davidflanagan.github.io/Inquire/?url=examples/marble.inq">here</a> and <a href="https://davidflanagan.github.io/Inquire/?url=examples/sat.inq">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a765cc98655" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About that programming language tweet]]></title>
            <link>https://medium.com/@__davidflanagan/about-that-programming-language-tweet-20bfc355d0fd?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/20bfc355d0fd</guid>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Tue, 03 Jun 2014 17:50:11 GMT</pubDate>
            <atom:updated>2014-06-03T18:05:29.737Z</atom:updated>
            <content:encoded><![CDATA[<h4>More thoughts on Swift, etc.</h4><p>Yesterday I <a href="https://twitter.com/__DavidFlanagan/status/473567643371573248">tweeted</a> this:</p><blockquote>Next-gen programming languages:</blockquote><blockquote>Mozilla: Rust</blockquote><blockquote>Google: Dart, Go</blockquote><blockquote>Facebook: Hack</blockquote><blockquote>Apple: Swift</blockquote><blockquote>Only Rust was developed in the open.</blockquote><p>This was retweeted more than 400 times, which is more attention than any of my tweets has ever gotten, so I figure I ought to be a little less glib and respond to the many thoughtful comments I’ve received. In no particular order, here are some more thoughts about this:</p><ol><li>I didn’t mean anything in particular by “next-gen” other than language with cool modern features like type inference.</li><li>I was limiting the list to languages developed by a corporation (or in the case of Rust, with primary backing from a corporation). Languages like Scala, D, and many others aren’t on the list because they don’t have the corporate connection. Languages like Java and C# aren’t on the list because they aren’t “next-gen”.</li><li>I didn’t put TypeScript and F# on the list for Microsoft because I’d forgotten about them (or maybe never heard about F#)</li><li>I didn’t put ES6 (the next version of JavaScript) on the list because it is being developed cooperatively and is not owned by any one tech company. And, as much as I love the new features that browser vendors are adding, it doesn’t feel like ES6 has enough of those new features to meet my vague “next-gen” criterion. Maybe we’ll get there with ES7.</li><li>One of the points of my tweet was basically “hey isn’t it weird how all these tech companies are developing their own programming languages?”. It occurred to me later that of course C was the same way: the research arm of a big tech company saw the need for a new programming language so they created one. Go and Rust seem like they’re following that venerable model and are breaking important new ground by targeting the challenges of concurrent programming. I’m not sure about Dart, Hack, and Swift, however. Do we really need all these new languages? Are these indeed “vanity languages”? Or worse, (in the case of Swift) are they tools for developer/ecosystem lock in?</li><li>One of my other points, not really expressed, but responsible for any snarky tone that came through in the tweet, is that WWDC is a conference where you expect new hardware surprises to be announced, and we’re used to secrecy surrounding new hardware. The fact that Apple treats a new programming language as a WWDC surprise, says a lot about Apple’s culture, I guess. If I wrote software targeting Apple hardware (or managed people who did) I don’t think I’d be happy at all about having a new language dropped on me from the blue—here’s the new language you’ll be using from now on… go learn it right away!</li><li>The main point behind my “developed in the open” comment is that Apple’s developer community has no way to assess the maturity of Swift. There aren’t public mailing lists and bug trackers showing the evolution of the language. There is not an existing code base showing examples of the language in use. Languages usually start with a small community and then grow. Apple is throwing this new language at the world and seems to expect developers to abandon Objective C and start using Swift at scale. But developers don’t have any reason to believe that the compiler isn’t still riddled with bugs!</li><li>And yes, I know that the Rust project has been going on forever and hasn’t even reached 1.0 yet. Its kind of like an academic language in that way. But they’re getting close to 1.0, and when they do get there, I will know that lots of smart people have thought really hard about the final syntax and semantics of the language, and that those features have been tried out on a large project (the Servo rendering engine).</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20bfc355d0fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[For the Record]]></title>
            <link>https://medium.com/@__davidflanagan/for-the-record-7645a4bf8a2?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/7645a4bf8a2</guid>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Fri, 04 Apr 2014 23:20:06 GMT</pubDate>
            <atom:updated>2014-04-11T16:26:16.943Z</atom:updated>
            <content:encoded><![CDATA[<h4>and The Tragedy of Mozilla</h4><p>The last two weeks at Mozilla, starting with Brendan Eich’s elevation to CEO and ending with his resignation yesterday have played out like a Greek tragedy. I mean that literally: as an employee at Mozilla, this feels tragic to me. And before I can get back to work, I feel I need to write something about it.</p><p>I’ll begin with the obligatory disclaimer: <em>I fully support marriage equality</em>. And I’ll add that anyone who wants to attack Mozilla from the right is even more wrong than those who were attacking from the left.</p><p>One of the things that is most painful to me about this is the sheer volume of misinformation out there. We all know that people are <a href="https://xkcd.com/386/">wrong on the internet</a> all the time. It is probably hopeless to fight that, but for the record, these are the facts as I understand them, along with my interpretation of those facts. My information is based on public and private statements from Mozilla employees, officers and board members. I do not know Brendan personally at all. I have been an employee of Mozilla for about three years. In that time I have spoken with him no more than five times. I have had a few email exchanges with him, but have not worked closely with him on any projects.</p><p>0) Brendan was one of the founders of Mozilla and was the technical leader of the project from the beginning. Without Brendan there would have been no Mozilla. Without Mozilla, there would have been no Firefox, and the internet would be very different today. [Updated April 6 with a minor clarification]</p><p>1) In 2008, Brendan donated $1000 in support of California’s Proposition 8, a political initiative campaign that succeeded in denying the right of marriage to same-sex couples. In 2008 52% of voters supported Proposition 8. Proposition 8 has since been overturned in the courts, same-sex marriage is now legal in California, and mainstream public opinion on the issue also seems to be changing.</p><p>2) Under California law, Brendan’s private donation is a matter of public record. Anyone who wants to go full McCarthy (“I have here in my browser a list…”) can <a href="http://www.latimes.com/includes/projects/img/prop8/prop8contributions.zip">download the list</a> of supporters and opponents.</p><p>3) California law requires donors to name their employer, and that information is included as part of the public record. Therefore, the record of Brendan’s private donation includes Mozilla as his employer. This does not mean, however, that the donation was made in Mozilla’s name.</p><p>4) In April 2012, when Brendan was CTO at Mozilla someone (unknown to me, possibly known to others) noticed Brendan’s name on that list and publicized it. As I recall, there was some confusion at the time about the fact that Mozilla was listed as Brendan’s employer and the fact that it was a private donation needed to be clarified. [April 7: corrected the date]</p><p>5) Mozilla <a href="https://blog.mozilla.org/blog/2014/03/29/mozilla-supports-lgbt-equality/">officially supports LGBT rights</a> and this has been and continues to be true before, during, and after Brendan’s brief tenure as CEO.</p><p>6) I cannot speak for my LGBT colleagues, but I think that the consensus is that in practice Mozilla is and has always been a very gay-friendly workplace.</p><p>7) I have not heard any allegations that Brendan’s behavior was anything other than completely professional toward all employees and contributors regardless of sexual orientation. Brendan was a founder and leader of Mozilla for 16 years. He worked closely with LGBT employees and apparently kept his personal beliefs against marriage equality to himself in all of his public interactions.</p><p>8) Mozilla has <a href="http://www.mozilla.org/en-US/about/governance/policies/participation/">policies in place</a> that explicitly and precisely explain how we deal with conflicts between personal beliefs and community inclusiveness. Section (i) of these “Community Participation Guidelines” is directly relevant to Brendan’s situation, and I quote it in its entirety. If you want to understand what has happened at Mozilla, it is absolutely necessary to understand this:</p><blockquote><strong>(i) Inclusion and Diversity</strong></blockquote><blockquote>The Mozilla Project welcomes and encourages participation by everyone. It doesn’t matter how you identify yourself or how others perceive you: we welcome you. We welcome contributions from everyone as long as they interact constructively with our community, including, but not limited to people of varied age, culture, ethnicity, gender, gender-identity, language, race, sexual orientation, geographical location and religious views.</blockquote><blockquote>Mozilla-based activities should be inclusive and should support such diversity.</blockquote><blockquote>Some Mozillians may identify with activities or organizations that do not support the same inclusion and diversity standards as Mozilla. When this is the case:</blockquote><blockquote>(a) support for exclusionary practices must not be carried into Mozilla activities.</blockquote><blockquote>(b) support for exclusionary practices in non-Mozilla activities should not be expressed in Mozilla spaces.</blockquote><blockquote>(c) when if (a) and (b) are met, other Mozillians should treat this as a private matter, not a Mozilla issue.</blockquote><p>9) Brendan’s donation in support of Proposition 8 indicates that he identifies “with activities or organizations that do not support the same inclusion and diversity standards as Mozilla”. But he scrupulously followed conditions (a) and (b). By paragraph (c), therefore, Brendan’s donation was “a private matter, not a Mozilla issue”.</p><p>10) Many Mozillians were uncomfortable with the situation, but most were willing to abide by paragraph (c) and treat this as a private matter. Left to ourselves, I believe we could have worked through the discomfort (as we did when Brendan’s donation was first revealed in 2011) and moved on with our mission.</p><p>[<strong>Update</strong> April 11: <a href="https://blog.mozilla.org/blog/2014/04/05/faq-on-ceo-resignation/">Mozilla’s official FAQ </a>about Brendan’s resignation has been updated and includes a more detailed timeline than the one I include in the points that follow.]</p><p>11) On March 27th, a small number of Mozillians tweeted variants of “I am an employee of <a href="http://twitter.com/mozilla">@mozilla</a> and I’m asking <a href="http://twitter.com/brendaneich">@brendaneich</a> to step down as CEO”. These tweets were reported by the tech press, and my perception is that this was the start of the media firestorm. Most (or perhaps all) of the Mozillians who tweeted this were employed by the Mozilla Foundation, not the Mozilla Corporation which means that they report to the executive director of the foundation and not to the CEO. As foundation employees, they did not share the same org chart as Brendan.</p><p>12) On March 28th, the Wall Street Journal reported that three Mozilla Corporation board members had resigned. The article incorrectly implied that the resignations were in protest of Brendan’s selection. It did not imply that the resignations were in protest of Brendan’s Proposition 8 donation, though apparently many interpreted it that way. (ABC News’s reporting on Brendan’s resignation yesterday implied that the board resignations were related to Proposition 8, for example). The truth is that two of the board resignations were entirely unrelated to Brendan, and that one was related to Brendan’s leadership abilities but not to his Proposition 8 donation. I do not know who gave this inaccurate story to the Wall Street Journal, but the implied vote of no confidence in Brendan really could not have come at a worse time.</p><p>13) Dating website OkCupid and activist organization CREDO Mobile organized online boycotts of Firefox. It is not clear to me that those behind those actions understood Mozilla or were aware of our Community Participation Guidelines.</p><p>14) On April 3rd, Brendan sent the following email:</p><blockquote>All,<br>I have decided to resign from the position of CEO effective today, and to leave Mozilla. An announcement will be made shortly.<br>Our mission is bigger than any one of us, and under the present circumstances, I cannot be an effective leader for Mozilla.<br>I have confidence in the team I’ve been leading — with everyone working together, I know that Mozilla can achieve its goals.<br>I will be taking time before I decide what to do next.<br>Mitchell will have more details to share on the transition plan.<br>/be</blockquote><p>I believe that this was Brendan’s own decision and he was not pressured by the board or leadership to make it. [Updated April 6 to add text of Brendan’s email.]</p><p>15) Brendan was encouraged by the board to remain at Mozilla in some other capacity, but Brendan felt that for the good of the project it was necessary to completely sever ties. This means the Brendan is no longer an employee of Mozilla at all and receives no money from Mozilla. Since Mozilla is “owned” by a non-profit foundation there is no stock. Brendan now has no financial ties of any kind to Mozilla.</p><p>16) Brendan remains a “module owner” and “peer” of several important <a href="https://wiki.mozilla.org/Modules">modules</a>. This means that he can choose to play an important role in the ongoing governance and technical direction of the open-source Mozilla project. It remains to be seen how active or inactive he will be in the project.</p><p>17) Brendan has converted his <a href="http://twitter.com/BrendanEich">@BrendanEich</a> Twitter account so that his tweets are “protected” and not publicly visible. [<strong>Update:</strong> On April 4 the account appeared to be deleted, and I reported that here. On April 5th, the twitter account is live, but Brendan’s tweets are protected.]</p><p>18) Brendan’s most recent <a href="https://brendaneich.com/">blog</a> post indicates that he is going to be taking some time off.</p><p>So, in the Tragedy of Mozilla, Brendan is our larger-than-life protagonist, Inventor of JavaScript, Hero of the Open Web. As in all tragedies, though, he has a <a href="http://en.wikipedia.org/wiki/Hamartia">tragic flaw</a> that will be his undoing, even though he plays by the rules. The chorus of our Greek tragedy are the “I am an employee of <a href="http://twitter.com/mozilla">@mozilla</a>” tweeters who sparked the media firestorm. And the antagonists, in my mind, are the person who leaked the inaccurate board resignation story to the Wall Street Journal, and the impatient activists at Ok Cupid and CREDO Mobile who stoked the fire without seeking to understand us or giving us time to sort it out internally.</p><p>And the real tragedy here is that Mozilla would have sorted this out satisfactorily if it hadn’t been sensationalized by the media and turned into an internet witch hunt. Anyone who wrote a news story, posted to their blog, or tweeted about Brendan without understanding paragraph (i)(c) of the <a href="http://www.mozilla.org/en-US/about/governance/policies/participation/">Community Participation Guidelines</a> was part of the mob that brought Brendan down.</p><p>For more than 16 years, Brendan fought for openness and freedom on the web, and led many of the people who built that open and free web. This week, in a senseless, vicious convulsion, the web turned on him.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7645a4bf8a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[No Tuxedo Required]]></title>
            <link>https://medium.com/@__davidflanagan/no-tuxedo-required-c2e98ff4b5ec?source=rss-70b3d287f497------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2e98ff4b5ec</guid>
            <dc:creator><![CDATA[David Flanagan]]></dc:creator>
            <pubDate>Wed, 18 Dec 2013 21:55:25 GMT</pubDate>
            <atom:updated>2013-12-18T21:55:25.401Z</atom:updated>
            <content:encoded><![CDATA[<h4>One Geek’s Thoughts on Charitable Giving</h4><p>I’ve got an amazing job. I get paid lots of money to do challenging work that I feel good about. Its a great life!</p><p>The downside, for me, of programming and of the high tech world in general, is that it is so easy to get sucked into the marvels of it all, and spend all of my time immersed in code. So at this time of year, I try to force myself to look away from the beautiful devices and apps I work on and remember that most people do not live in the same shiny world that I do, and that for many of them, the world can actually be pretty sucky.</p><p>This year, I’m reminding myself of this out loud in case anyone else needs or wants the same reminder: those of us blessed enough to be in a position to help others ought to at least make the time to write some checks.</p><p>It is only in recent years that I’ve started being even semi-serious about charitable giving. It never really occurred to me to give very much before. I guess I thought that giving was something for people who owned tuxedos and went to benefit galas and operas and stuff. I’ve learned, though, that donating a day’s salary to a local charity will put me on their list of big ticket donors and get me a personal thank you note from the executive director. Its not much to me, but it makes a huge difference to these organizations and the people they serve. And I don’t have to buy a tuxedo!</p><p>This year, about 2/3rds of my giving is to to be in my home town, divided between the food bank, an organization that is part of the <a href="http://waterkeeper.org/">Waterkeeper Alliance</a> and is fighting against a proposed coal export terminal and two smaller non-profits that work with the victims of domestic violence and child abuse.</p><p>I’ve picked national and international charities for the remaining third. This year’s picks:</p><ul><li><a href="http://feedingamerica.org/">Feeding America:</a> Hunger is one of my pet peeves, so this donation goes along with my donation to my local food bank. Feeding America is a national clearinghouse for food donations that are then distributed to a national network of local food banks. If you look Feeding America up on <a href="http://charitynavigator.org/">Charity Navigator</a> you’ll see that they have a huge budget with very low overhead and an insanely high percentage going to program services. I suspect this is because so much of their income is in the form of food donations from corporate food manufacturers. They send me way too many solicitations (though this year’s donation form has an opt out check box, which is nice). And their executive director is paid $400k a year, which seems excessive. But they serve a unique niche and if they were not around, I suspect that hunger would be a much bigger problem than it already is in communities all around the country.</li><li><a href="http://350.org/">350.org</a>: This organization was founded by <a href="https://twitter.com/billmckibben">Bill McKibben</a> who started sounding the climate change alarm a long time ago with the publication of his book <em>The End of Nature</em>. The “350″ in the name refers to their goal of reducing carbon dioxide in the atmosphere to 350 parts per million. The seem to be doing really innovative work and are spearheading fossil fuel divestment campaigns on university campuses, in churches, and even in local governments. This is the first time I’ve given to 350.org and I don’t know what has taken me so long. The fossil fuel divestment movement reminds me my own university activism for South African divestment, so maybe it is Nelson Mandela’s death that has spurred me to donate.</li><li><a href="http://www.heifer.org/">Heifer International</a>: this is a great organization that combats malnutrition and poverty in the developing world by giving livestock (like Heifers and dairy goats) to needy families, and backing the gifts up with appropriate training in caring for the animals. The bonus here is that kids love it. We’re going to let our kids choose what kind of animal to give with their share of the donation.</li></ul><p>There are so many good causes out there. I wish I was also giving for civil liberties, peace, reforestation, disaster relief and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2e98ff4b5ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>