<?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 Gregory ‘Grey’ Barkans on Medium]]></title>
        <description><![CDATA[Stories by Gregory ‘Grey’ Barkans on Medium]]></description>
        <link>https://medium.com/@vapurrmaid?source=rss-450bddce104c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*56ogWmL2WZevbdDLw2pINw.jpeg</url>
            <title>Stories by Gregory ‘Grey’ Barkans on Medium</title>
            <link>https://medium.com/@vapurrmaid?source=rss-450bddce104c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:39:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vapurrmaid/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[How I Survived My First Week as A Software Developer]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/how-i-survived-my-first-week-as-a-software-developer-a6c6734809ac?source=rss-450bddce104c------2"><img src="https://cdn-images-1.medium.com/max/2600/0*gOmSDwp2KY6I15Kl" width="6435"></a></p><p class="medium-feed-snippet">Reflection, Collaboration and Humility</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/how-i-survived-my-first-week-as-a-software-developer-a6c6734809ac?source=rss-450bddce104c------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/how-i-survived-my-first-week-as-a-software-developer-a6c6734809ac?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6c6734809ac</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[work]]></category>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[personal-development]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Thu, 09 May 2019 10:34:16 GMT</pubDate>
            <atom:updated>2019-05-11T16:04:25.389Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The Need for Quality Leisure]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@vapurrmaid/the-need-for-quality-leisure-ae698f5f7679?source=rss-450bddce104c------2"><img src="https://cdn-images-1.medium.com/max/2300/0*yBsMiDqeZ0TX1jMX" width="2300"></a></p><p class="medium-feed-snippet">Utilizing Choice in A Digital World</p><p class="medium-feed-link"><a href="https://medium.com/@vapurrmaid/the-need-for-quality-leisure-ae698f5f7679?source=rss-450bddce104c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@vapurrmaid/the-need-for-quality-leisure-ae698f5f7679?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae698f5f7679</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[leisure]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[minimalism]]></category>
            <category><![CDATA[philosophy]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Tue, 30 Apr 2019 05:01:16 GMT</pubDate>
            <atom:updated>2020-03-07T13:57:55.267Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Winning In A False Meritocracy]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@vapurrmaid/winning-in-a-false-meritocracy-8a01ee8f0494?source=rss-450bddce104c------2"><img src="https://cdn-images-1.medium.com/max/2600/0*vrraQGkQgR7lzEhd" width="3264"></a></p><p class="medium-feed-snippet">Recognizing The System, Each Other and Ourselves</p><p class="medium-feed-link"><a href="https://medium.com/@vapurrmaid/winning-in-a-false-meritocracy-8a01ee8f0494?source=rss-450bddce104c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@vapurrmaid/winning-in-a-false-meritocracy-8a01ee8f0494?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a01ee8f0494</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[capitalism]]></category>
            <category><![CDATA[academia]]></category>
            <category><![CDATA[collectivism]]></category>
            <category><![CDATA[meritocracy]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 17:23:46 GMT</pubDate>
            <atom:updated>2019-03-13T19:27:31.515Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Should You Use Classes in JavaScript?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@vapurrmaid/should-you-use-classes-in-javascript-82f3b3df6195?source=rss-450bddce104c------2"><img src="https://cdn-images-1.medium.com/max/2600/0*w1S6-ay0WebIOQNT" width="5029"></a></p><p class="medium-feed-snippet">Design Expression Over Dogma</p><p class="medium-feed-link"><a href="https://medium.com/@vapurrmaid/should-you-use-classes-in-javascript-82f3b3df6195?source=rss-450bddce104c------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@vapurrmaid/should-you-use-classes-in-javascript-82f3b3df6195?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/82f3b3df6195</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Tue, 06 Nov 2018 00:47:09 GMT</pubDate>
            <atom:updated>2018-11-06T01:14:28.056Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Visual Programming & Version Control: Future Considerations]]></title>
            <link>https://medium.com/@vapurrmaid/visual-programming-version-control-future-considerations-b18c9a49c187?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b18c9a49c187</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[visual-programming]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Fri, 26 Oct 2018 11:57:06 GMT</pubDate>
            <atom:updated>2018-10-26T18:59:20.494Z</atom:updated>
            <content:encoded><![CDATA[<h4>Graphical Code Needs Visual Comparison Tools</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qt7BuO9SfxH6bR-B" /><figcaption>“Gitlab application screengrab” by <a href="https://unsplash.com/@pankajpatel?utm_source=medium&amp;utm_medium=referral">Pankaj Patel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Graphical coding techniques such as <a href="https://en.wikipedia.org/wiki/Model-driven_engineering">Model-driven development</a> (<strong>MDD) </strong>and <a href="https://en.wikipedia.org/wiki/Visual_programming_language">visual programming languages</a> (<strong>VPL</strong>) seem to come and go throughout software development communities. Even in communities that largely remain in hand-written paradigms, tools and plugins that interact with source code and/or development environments continually improve. To demonstrate this point, projects utilizing web template languages often use simple editors and a combination of tools like <a href="https://eslint.org/">ESLint</a>, <a href="https://postcss.org/">postcss </a>and <a href="https://webpack.js.org/">Webpack </a>that analyze, modify and generate from source code. On the other side, Matlab/Simulink have refined graphical models for developing embedded control systems software.</p><p>Altogether, it appears that as generative and automated tools evolve, source code and its creation is continually influenced by integrated processes. But what are the consequences of further innovations in such tools? Do they promise milestones in software productivity? Are there inevitable walls and glass ceilings in which these tools are destined to run up against?</p><p>In this piece I assert that a future consideration for these tools is their interaction with <a href="https://en.wikipedia.org/wiki/Version_control">version control systems</a> (<strong>VCS</strong>).</p><h3>Computer Aided Software Engineering — Silver Bullet?</h3><p>In the 1980s, <strong>CASE¹</strong>and <strong>4GL²</strong> arose with the ambitious intentions of automating software engineering design processes, specifically to alleviate various costs of development. However their promises remained largely unfilled: many companies that bought into these technologies left them “on the shelf” [2]. Perhaps without coincidence, it is around this time that Fred Brooks published a seminal article titled “No Silver Bullet — Essence and Accident in Software Engineering” [1-2].</p><p>In the article, Fred claims that all of the major innovations in software development have already been uncovered and then goes on to demonstrate that software has a complicated “essence” of which there exists no “silver bullet” solution(s). Of the candidate silver bullets surveyed throughout the article, Fred honed in on topics near and dear to CASE: high-level design languages, automatic programming, graphical programming and environment tools.</p><blockquote>There is no single development, in either technology or in management technique, that by itself promises even one order-of-magnitude improvement in productivity, in reliability, in simplicity.</blockquote><p>Fred did, however, predict utility in static analysis tools while carefully noting that such tools are separate from essence: syntactic analysis, linting and related aides do not unravel errors at the conceptual levels that contribute to the large costs of development. In hindsight this is not surprising as we now see widespread adoption of <strong>IDE</strong>s³ and despite their power, they do not replace an understanding of program design. However, it’s worth understanding why these have become so widely adopted in order to gain insight on what may make future innovations successful.</p><p>I believe an integral reason IDEs and related technologies are successful is because they’re comprised of a rich system of configurable, simple and most importantly <strong>cohesive </strong>plugins. Modern IDEs integrate with multiple languages, version control systems, build systems, debugging tools, and so on. Rarely is a developer locked into a specific configuration. Further, the extensive set of plugins and their accompanying support are usually a product of open source.</p><p>Altogether, it’s as if the IDEs are malleable and rather just “there” to adapt to most situations. One doesn’t feel constrained by other tools in their toolbox. If there’s no existing configuration for the task at hand, an open source solution can often be crafted.</p><p>With this information in mind while carefully re-examining Fred’s statement, the words “<strong>by itself</strong>” pop out. Indeed in the next paragraph, Fred carefully states:</p><blockquote>Skepticism is not pessimism, however. Although we see no startling breakthroughs — and indeed, I believe such to be inconsistent with the nature of software — many encouraging innovations are under way. A disciplined, consistent effort to develop, propagate, and exploit these innovations should indeed yield an order-of-magnitude improvement. There is no royal road, but there is a road.</blockquote><p>Thus, as shown in the case of IDEs, innovations in software development processes and tools are seen when a collection of efforts propagate in time. No one “magic tool” will replace everything.</p><p>Where does all of this leave graphical coding technologies such as MDD and Visual Programming Languages? Will they eventually be widely adopted? Although I refrain from offering an answer, I assert at least one major factor that will determine their success: a need for integrating with existing ecosystems and in particular, version control systems.</p><p>¹<a href="https://en.wikipedia.org/wiki/Computer-aided_software_engineering">Computer Aided Software Engineering</a><br>²<a href="https://en.wikipedia.org/wiki/Fourth-generation_programming_language">Fourth Generation Programming Languages</a><br>³<a href="https://en.wikipedia.org/wiki/Integrated_development_environment">Integrated Development Environment</a></p><h3>The Problem with Graphical Coding and VCS</h3><p>Fred’s article addressed both MDD and VPL, discussing their unlikelihood as silver bullets in software development. VPLs appear to use poor abstractions such as flowcharts which are often constrained by the literal dimensions of computer screens. MDD is potentially a useful solution methodology but it does not ease identification and specification of problems. Furthermore, the general applicability of MDD to a wide range of software systems is questionable.</p><p>However as graphical coding techniques gain momentum in academia and in specific industries, there’s a critical issue contingent upon their future: graphical coding paradigms need improved integration with VCS.</p><p>One of the major benefits of modern VCS tools is the way multiple developers can view commit histories, differences and review each others’ code. In other words, it’s not just that VCS is used to backup changes, tag commits and share code. It’s that modern VCS allows developers to effectively communicate past, present and future changes with one another. In fact, according to the <a href="https://guides.github.com/introduction/flow/">Github Flow</a> model, pull requests are meant to be opened and initiated long before they’re ready for merge. The reason is precisely for demonstrating, comparing and tracing differences alongside communication and review [3].</p><p>It is precisely these modern VCS benefits that graphical code fails to utilize, as graphical code is obscured in binary and often only able to be viewed by specific editors and/or applications.</p><h4>Case Study: UE4 Blueprints</h4><p>Recently, I started developing with the Unreal Engine (UE4) for the first time. One of the aspects within UE4 is a visual programming language called “Blueprints”, shown below.</p><p>The grey areas are comments. White pin lines represent execution flow while blue lines represent data flow. Red nodes are registered events and the green and blue nodes represent methods and functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m--frGNValTSk2okNuR5HA.png" /><figcaption>UE4’s Visual Programming Language: Blueprints</figcaption></figure><p>Although it’s not my cup of tea, I can still think of some benefits to this style of programming:</p><ol><li>It allows “wiring” of basic functionalities to be handled by a designer.</li><li>The Blueprint is bound to the entity in the IDE and thus it’s easy to see its effects. That is, the UI and the “blueprint” that directly encodes it logic are side by side. One doesn’t need to map a system of obscure .cpp files to pieces of UI.</li><li>Visuals can be easier to reason about for programs that lend themselves well to simple flow. Indeed, a developer may use similar flow constructs as a form of specification prior to coding in the first place.</li></ol><p><strong>However, there is a major drawback: tracking file changes</strong>. In UE4, Blueprints are stored as binary in .uasset files. Similarly in Matlab, models are stored as .mdl<strong> </strong>or .slx.<strong> </strong>These files not only contain the programming logic, but they also encode data about the graphical information such as the positioning and names of each of the nodes. Such information is hard to track and visualize across files.</p><p>To illustrate, if I have a clean working directory and then proceed to open a blueprint and drag any one of the nodes ever so slightly <strong>without changing logic</strong> (ie: a <em>purely</em> aesthetic change), a git status shows a dirty working directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*oQQC9d3oPWCXABitITFFaQ.png" /><figcaption>This change came about from simply moving a Node a few millimeters</figcaption></figure><p>What distinguishes this trivial aesthetic change from an actual modification to the programming logic? Well, in terms of a git diff, <strong>nothing</strong>. The sole ‘source of truth’ remains in commit messages. Contrast this with adding white space or a comment to a .cpp file. Although these are purely aesthetic changes they are very easily visualized with VCS.</p><p>As of this writing, I’ve finished the early stages of a UE4 game which includes a 3D camera attached to a mesh with moving parts, aiming UI, user input/controller logic, a main menu and a level landscape. <strong>None</strong> of those changes are traceable beyond commit messages. To see the state of the software at any one point, I’d have to checkout or reset to that specific point and open the UE4 IDE.</p><p>To me, this is a serious red flag.</p><ul><li>How do we effectively visualize and see changes to software across commits and versions?</li><li>How does one implement an effective “code review” of such graphical paradigms?</li><li>How do collaborators compare and contrast their work against their colleagues’ branches?</li></ul><p>Imagine collaborating with a team of developers over a central repository using such graphical programming tools. If a commit is made and put up for review — how do multiple people review it simultaneously in an effective manner? Must they all individually download the proposed version and open it side-by-side another version and manually inspect the blocks and scan for differences?</p><p>If methods to compare graphical code changes were to surface, how effective would they be? Comparing textual code across files using basic diff tools is quite effective and often easy to grasp depending on the number of changes. In graphical paradigms, can changes to nodes, locations and wiring be as easily interpreted as the red/green highlighting of text? Are typical screen sizes even a suitable canvas of which such differences can be rendered?</p><p>Such challenges must be embraced if graphical paradigms are to be continually pursued.</p><h3>Concluding Remarks</h3><p>Graphical code will never be a silver bullet. If there is a future entailing its widespread adoption it can only be realized through integrating with other tools and existing ecosystems.</p><p>Although graphical code and other innovative development techniques may yield benefits in constructing software solutions, a need for source maintenance and thus managing differences and versioning will not disappear.</p><p>In particular, graphical coding paradigms need intermediary plugins and tools that stand between them and VCS in order to clearly visualize changes and comparisons. Furthermore these tools need to facilitate collaboration and design review.</p><h4>References</h4><p>[1] Brooks, Frederick P., “No Silver Bullet: Essence and Accidents of Software Engineering,”. <em>Computer</em>, vol. 20, no. 4, April 1987, pp. 10–19. <br>[<a href="http://www.cs.nott.ac.uk/~pszcah/G51ISS/Documents/NoSilverBullet.html">Available here</a>]</p><p>[2] Glass, Robert L. “‘Silver Bullet’ Milestones in Software History.” <em>Communications of the ACM</em>, vol. 48, no. 8, Aug. 2005, pp. 15–18.</p><p>[3] Chacon, Scott. “GitHub Flow”. 2011. [Online]. Available: <a href="http://scottchacon.com/2011/08/31/github-flow.html">http://scottchacon.com/2011/08/31/github-flow.html</a></p><p>My name is Grey, aka @vapurrmaid. I’m a software student and programming enthusiast. I don’t use social media, but I’d like to connect on <a href="https://github.com/vapurrmaid">Github</a>:</p><p><a href="https://github.com/vapurrmaid">vapurrmaid - Overview</a></p><p>Here’s a previous article you may enjoy:</p><p><a href="https://medium.com/@vapurrmaid/code-something-weekly-how-and-why-44640d279ca1">Code Something Weekly: How and Why</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b18c9a49c187" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Reasons Why Grades Are Bullshit]]></title>
            <link>https://medium.com/@vapurrmaid/3-reasons-why-grades-are-bullshit-212f07804e30?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/212f07804e30</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[academia]]></category>
            <category><![CDATA[college]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Thu, 27 Sep 2018 13:02:34 GMT</pubDate>
            <atom:updated>2018-09-27T16:14:09.137Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I Learned This In One Day</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0NXIW9iqJCI4zNC7" /><figcaption>“empty chairs in theater” by <a href="https://unsplash.com/@nate_dumlao?utm_source=medium&amp;utm_medium=referral">Nathan Dumlao</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Preamble</h3><p>I recently started up a new college software program in order to improve my resume and set of credentials. I already have a B.Sc. and have various computer science and engineering courses under my belt. As a result, I was able to start the program in year “2.33” (out of 3), essentially allowing me to grab a few advanced courses and an opportunity to intern as a co-op student.</p><p>It’s a pretty awesome deal, and I’m happy with how things are going.</p><p>That is except for an exemption for an introductory Java course that didn’t go through due to a painfully tiny detail.</p><blockquote>Life has a funny way of adding in side quests — especially when you’re motivated to finish a chapter of the main story.</blockquote><p>If you’ve ever been stuck in a course that’s <strong>very clearly</strong> too introductory for your skill set, then you know that your chances of getting an A+ in that course are often lower than if you didn’t know any of the material. There’s no desire to engage, and further, you come to the subject with real-world knowledge that often conflicts with the theoretical friction-less land of an introductory course. You’re no longer able to be effectively molded into a contrived framework idealized for the model student.</p><p>Between being forced to use incorrect information, implement anti-patterns in order to “learn the concepts” and sit through lectures that you’ve heard a thousand times, it’s an excruciatingly painful experience.</p><p>I wrote this piece during a lecture of that very class in order to reduce the chance of bashing my head against the wall.</p><h3>A Tale of Two Characters — Speaker vs Teacher</h3><p>Today I had the pleasure of seeing the disparity between the “real-world” and academic bubble first-hand. A senior software engineer from a public research organization gave a presentation aimed towards students applying for a co-op position. The central thesis of the presentation demonstrated that extracurricular passion vastly outweighed academic study.</p><p>In contrast, a teacher later on in the day instructed me to knowingly implement an anti-pattern in an assignment citing that “the class isn’t there yet” (with regards to the technique I employed through my own extracurricular knowledge).</p><p>These events led me to reflect on the meaninglessness of marks and grades.</p><h4>1. Real Assignments Need To Be “Correct”</h4><p>In their presentation, the senior software engineer outlined the importance of</p><ul><li><strong>passion: </strong>for learning new (read: not taught in school) material</li><li><strong>engagement: </strong>building side projects</li><li><strong>correctness: </strong>implementing work assignments thoroughly and correctly</li></ul><p>To quote the speaker</p><blockquote>We find we often have to de-studentize them. We ask them to take a week to implement a requirement, and they’re eager to get it done by the next day as if it were a test. And maybe they got it 90% right. That’s a great mark on an assignment — but we want you to take the entire week and get it 100% right.</blockquote><p>Academia is usually unforgiving with deadlines. The smorgasbord of courses, each of which think they’re the only one in existence, set arbitrary deadlines and schedules. Students are forced into habitually crunching around deadlines or mapping their time strategically in order to get grades.</p><p>But in doing so, where does the focus go? Do we fall into patterns of completing tasks at a level that’s “good enough”?</p><p>If we don’t intend on doing tasks “for real”, then do we really learn? Is it not the extra ~5–10% of edge cases only discovered through thoroughness that really solidify our grasp?</p><p>In the world beyond academia, deadlines are more consistent. You aren’t balancing 5–7 courses competing for your focus with irregular timing. Instead, your time is narrowed in towards finishing a given work assignment (for example, a scrum sprint). However, with the extra time and focus there’s an accompanying requirement to be meticulous. You don’t get to sail from assignment to assignment on “B” grades.</p><h4>2. You Don’t Always Get Right/Wrong Feedback In The Real World</h4><p>Imagine you’re the aforementioned speaker: a senior developer. Failure to do your job well will likely get you fired. Products released under your direction will hold a reflection of your competence.</p><p>But what about most daily work tasks such as code commits and code reviews? Is someone always watching you sign off on commits telling you that it was the correct thing to do?</p><p>Do you have a “model solution” to grade your designs against? Will someone be sitting there giving you “A”s or “B”s and telling you if you’re doing things correctly?</p><p><strong>No</strong>.</p><p>No one is sitting there telling you that everything is “right” or “wrong”.</p><blockquote>It’s all fucking gr(e|a)y.</blockquote><p>In the real world, you need to learn to evaluate your own work and more importantly, your own knowledge and understanding. This only arises through honesty and self-accountability. Not through the holding-hand of an instructor.</p><p>I think it’s fair assessment that we have all at some point felt we were trying to ‘convince’ an instructor into giving us the mark (particularly on test questions we were unsure of). Imagine approaching a commit during code review with the same attitude. The person(s) reviewing the work don’t have the “model” solution. Further, they may not be able to assess the work with the same integrity as the person that authored it. The author shouldn’t be trying to merely convince the reviewers to let it through. There has to be more conviction in the commit. The author has to know what they do <em>and</em> don’t know.</p><p>Thus it’s about actually knowing you know the damn thing, and being able prove it to yourself. Others won’t always catch your errors, even during reviews and edits.</p><h4>3. Academia Doesn’t Usually Care What You Actually Know</h4><p>In the introductory course I was given a <a href="https://medium.com/@vapurrmaid/javafx-reusable-fxml-component-26f6716bce18">rudimentary assignment</a> whereby I went above-and-beyond expectations. I didn’t do this for marks . In fact I very well knew that any extra effort I put in wouldn’t be graded. Rather, I the extra work solely so I could use the time to learn and find some value in the experience. Additionally, after years of constantly trying to <em>improve</em> coding habits and design, I find it extremely counterproductive to knowingly implement poor practices and anti-patterns.</p><p>I met with the instructor before class to show them my designs as a “heads up” and I was met with some hilarious gems. For those privy to Java:</p><ul><li>“using a constructor isn’t a part of this assignment — you lose encapsulation of getters and setters” (<strong>W.T.F?!? — I straight out argued this because it’s just plainly wrong)</strong></li><li>“I don’t want to see public — make everything private (in response to me defining an enumerated type for consumers to use in order to ensure parameter safety). How arbitrary. Nothing proves you understand encapsulation and access modifiers like following a contrived heuristic.</li><li>“static is not allowed. The class hasn’t learned that yet” (in response to me saving memory/efficiency by declaring a proper constant) [ps: nothing in the assignment mentioned that was/wasn’t allowed]. I refuse to use anti-patterns for the sake of academia. Proper constants, should be proper fucking constants. Most IDEs will even warn you about this!</li></ul><p>Will I get the A grade this project deserves? Probably not by the sounds of it. Do I care at this point? Not a fucking chance.</p><p>The worst part isn’t that my effort to utilize proper design practices was being shut down. It’s that this is merely an instance of how the academic system operates at large.</p><p>Real-world topics are vast and complex. It’s rather arbitrary that we have a system that claims any and every topic can be easily broken down into approximately 12 discrete, separate modules of study. Further it seems unlikely that most modules can even truly be “graded” in isolation.</p><blockquote>To use Java as an example once again — to isolate “getters and setters” as a unit of understanding and grading separate from object-oriented class design as an entire topic is seemingly useless. One doesn’t actually understand “getters and setters” without context.</blockquote><p>Additionally, academic material often abstracts complexities and uses contrived paradigms solely for teaching. As an example, consider chemistry from grade 9 until about 2nd year university. After each successive year the course always starts off with the same disheartening message: “so everything you learned so far isn’t quite correct”.</p><p><strong>Then why is it taught?</strong></p><p>Why do we in academia constantly treat students as if they’re incapable of understanding complexities? Worse, why do we assume it’s any easier to learn by creating a friction-less land.</p><p>The point is that grades often don’t represent what you <strong>DO </strong>know about the real-world and its complexities. All they represent is how someone perceives your progression within a codified little model world with “ideal” student physics.</p><h4>Value Self Assessment Instead</h4><p>The good news is that it largely doesn’t matter. If you’re passionate, I’d find it hard to believe you’re getting absolutely terrible grades anyways. And that passion is utterly more valuable than grades can ever be. After all, they’re often merely hoops to step through.</p><p>The real skill to develop is self-assessment. <strong>It’s better to assess and admit to what you don’t know than to rely on others to perceive it.</strong> Such assessment is exactly what will motivate you to fill in your gaps and explore.</p><p>If you find yourself wondering if “there’s got to be a better design” or “this solution feels a little too ad hoc” or “why does this work”, don’t dismiss them. These thoughts will lead you to a more fulfilling understanding. At a minimum, they’ll help you spot your deficiencies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=212f07804e30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaFX: Reusable Components and Observables]]></title>
            <link>https://medium.com/@vapurrmaid/javafx-reusable-fxml-component-26f6716bce18?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/26f6716bce18</guid>
            <category><![CDATA[fxml]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[javafx]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 19:45:20 GMT</pubDate>
            <atom:updated>2018-09-27T03:50:37.716Z</atom:updated>
            <content:encoded><![CDATA[<h4>1 Model + 1 Controller + 1 Template=Multiple Objects</h4><p>This article assumes basic familiarity with JavaFX. For those that are completely new to JavaFX there are helpful introductory documents provided by Oracle.</p><p><a href="https://docs.oracle.com/javase/8/javafx/get-started-tutorial/index.html">JavaFX: Getting Started with JavaFX Release 8 - Contents</a></p><blockquote>The goal of the article is to create an fxml template with an associated controller and model that can be instantiated multiple times.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*4Pr4UjepeCBPEex0cludQQ.png" /></figure><p>All of the code for the entire project is found on Github:</p><p><a href="https://github.com/vapurrmaid/SlotMachineExample">vapurrmaid/SlotMachineExample</a></p><p>This past week I was forced to plow through a typical (read mundane) computer science assignment. Create a <a href="https://en.wikipedia.org/wiki/Plain_old_Java_object">POJO</a> “model”, and use it in a separate “view” class (aka a Scanner System.in/System.out loop).</p><p>Let’s be honest, if you’ve been programming for 5 years (3+ with Java) and the only thing holding you back at this point is a piece of very expensive paper to prove it, this task doesn’t exactly excite you.</p><p>I find working within the confines of a strict grading scheme is sometimes more of a constraint than those elicited in the real-world. Quite simply, these assignments are hardly bound by the outcome of a unique solution space; rather they’re bound to a specific implementation that’s easy to grade.</p><p>The goal then is to make the grader dislike giving you the A, as they will have to actually read and understand code that is far from a cookie-cutter solution.</p><p>Enter a conniving plan:</p><ul><li>A model that can be used plainly yet also observed</li><li>Implement a JavaFX GUI with a reusable FXML and Controller for the model</li><li>Implement the required System/Scanner loop running in a separate thread — changes manually typed here will update the GUI and vice-versa</li></ul><p>The last requirement, although odd, provides an exciting additional challenge.</p><h4>Model</h4><p>The model in the assignment is a transit ticket-vending machine. For the purposes of this article, I’ll only explore a single property: s<strong>electing a transit route</strong>.</p><p>Below we see that there’s an enumerated type ROUTES as well as a member variable selectedRoute. The type SimpleStringProperty is from the javafx.beans package and is used in order to allow a property to be observed. However, observable properties are <strong>agnostic</strong> of JavaFX and as we see, a standard getter is defined that returns a plain String.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*-sni8oqThTkOP8s_kSQYcg.png" /></figure><p>Further, <a href="https://en.wikipedia.org/wiki/Plain_old_Java_object#JavaBeans">the model is actually a common POJO</a> pattern called a ‘JavaBean’, which is a very standard design pattern. JavaFX packaged its own ‘beans’ as an improvement on the existing one, but it is not tied to JavaFX. One could use javafx.beans in another GUI framework (ex Swing).</p><p>There are a few helpful discussions talking about these points on SO:</p><ul><li><a href="https://stackoverflow.com/a/42181376/8954866">JavaFX 8: Separation of model/domain from view</a></li><li><a href="https://stackoverflow.com/questions/23522130/javabean-wrapping-with-javafx-properties">JavaBean wrapping with JavaFX Properties</a></li></ul><h4>Model Implementation</h4><p>Below is full implementation of this model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c472947eb56efd290063e7a3cb9d1a0/href">https://medium.com/media/8c472947eb56efd290063e7a3cb9d1a0/href</a></iframe><p>There’s really only two things to note here:</p><ul><li>setSelectedRoute is privately overloaded for convenience</li><li>Properties use get and set methods to assign values</li></ul><h4>View</h4><p>The point of this article isn’t to dive into FXML or CSS — Instead I want to demonstrate how to create multiple Objects from the preceding Model that all use one template and one controller.</p><p>The design will be extremely simple: A TabPane with 2 Tabs. Each tab is a view for a separate ticket vending machine (ie: a SlotMachine).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*yGIO-PNVDwjbwGLqFpW8DA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48a82bd9021055e8296f0c9e34e00ceb/href">https://medium.com/media/48a82bd9021055e8296f0c9e34e00ceb/href</a></iframe><p>Things to note about the FXML:</p><ul><li>fx:id&#39;s are assigned to buttons and text that will be bound to model data</li><li>A controller isn’t included in the template — we’ll set that up explicitly</li></ul><h4>Controller</h4><p>Creating a controller for the above view and model is relatively straight forward. Importing javafx.fxml.FXML allows for use of @FXML annotation, which binds to an fx:id as follows:</p><blockquote>@FXML Text txtSelectedRoute ← variable name <strong>must match fx:id</strong></blockquote><p>The SimpleStringProperty is then used to “listen” to changes in the model:</p><pre>getSelectedRouteProperty()<br>  .addListener((obs, oldRoute, newRoute) -&gt; {<br>    // update text here<br>});</pre><p>Button event handlers will update the model:</p><pre>btnRoute1.setOnAction(<br>  e -&gt; model.setSelectedRoute(...);<br>);</pre><p>Given that the fields annotated with @FXML are injected at runtime, a clever reader may ask “are they accessible in the constructor”? The answer is no, and for that reason, an FXMLLoader is used to “wire up”controllers to their views. This loader will inject the proper references,<strong> and afterwards </strong>call an initialize() method.</p><p>Therefore the initialize() method is where the above listeners and action handlers will be implemented.</p><p>For more information, here’s a helpful thread:</p><p><a href="https://stackoverflow.com/a/34785707/8954866">JavaFX FXML controller - constructor vs initialize method</a></p><h4>Controller Implementation</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c1ff80b2a89ef6a69f3cdbfe7b5b413/href">https://medium.com/media/4c1ff80b2a89ef6a69f3cdbfe7b5b413/href</a></iframe><h4>Binding Everything Together</h4><p>At this point there’s a model, view and controller. All that’s required is to setup a scene with everything glued together properly. However, there is a gotcha with respect to resource loading. It will also become clear why the controller was not included directly in the FXML template.</p><p>An FXMLLoader is used to load fxml templates and bind controllers. Given that the controller class in this example accepts a model in its constructor, care has to be taken regarding the order of operations.</p><ol><li>Instantiate models</li><li>Instantiate controllers with reference to models</li><li>Load FXML with respective controller</li></ol><p>Here’s some pseudo Java code doing the above:</p><pre>Model mOne = new()<br>Model mTwo = new()</pre><pre>Controller ctrlOne = new(mOne)<br>Controller ctrlTwo = new(mTwo)</pre><pre>FXMLLoader loader = new (&quot;view.fxml&quot;)</pre><pre>Tab tab1 = new()<br>loader.setController(ctrlOne)<br>tab1.setContent(loader.load())</pre><pre>Tab tab2 = new()<br>loader = new(&quot;view.fxml&quot;)<br>loader.setController(ctrlTwo)<br>tab2.setContent(loader.load())</pre><p>Did you notice the big “gotcha”? <strong>The loader was not re-used</strong> <strong>but instead re-instantiated</strong>. Failing to take this step will leave a nice compilation error about how “the root was already set”.</p><p>An important call to note is loader.setController(). This call explicity allows one to bind specific controller instances to specific instances of a template. Hence why the controller was not referenced directly in the FXML template.</p><p>In this example only two components were created. In more advanced cases (for example many components), FXMLLoader offers a method setControllerFactory, which is documented below:</p><p><a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#setControllerFactory-javafx.util.Callback-">FXMLLoader (JavaFX 8)</a></p><h4>Separate I/O Thread</h4><p>This last step is kind of quirky and only arose from me “bending” around the rules of the original assignment. I will demonstrate how to invoke a separate thread running a command-line interface <strong>that works with the same models as in the GUI</strong>.</p><p>The code for the CLI is found <a href="https://gist.github.com/vapurrmaid/ab5a1e68f44ccf0745f8e39f0f366cec">here</a>, and is outside the scope of the article.</p><p>In the main class, after the JavaFX code is rendered, start a <em>daemon</em> thread. The documentation states:</p><blockquote>The Java Virtual Machine exits when the only threads running are all daemon threads.</blockquote><p>which means that if the GUI is closed, the application (and CLI) will also exit.</p><p>Below a thread invokes the method runCommandLine from the MainCLI class.</p><pre>MainCLI cli = new MainCLI(smOne, smTwo);<br>Thread cliThread = new Thread(cli::runCommandLine);<br>cliThread.setDaemon(true);<br>cliThread.start();</pre><p>The result is a model synchronized between I/O and GUI events:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KZbGB3zVuJiovkHVqkRlIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdcVhqCsnGesMts6h9LlCQ.png" /></figure><h3>Wrap Up</h3><p>This article demonstrated how to “wire up” a reusable MVC component with JavaFX. It also demonstrated how to work with the very same models used in the MVC component on a separate input/output thread.</p><p>The major topics discussed where:</p><ul><li>JavaBeans Properties</li><li>Observing a JavaBean Property</li><li>Explicitly binding a controller to a template with FXMLLoader</li></ul><p>The entire source for this project lives on Github. There’s also an executable jar of the example that can be downloaded <a href="https://github.com/vapurrmaid/SlotMachineExample/tree/master/bin">here</a>.</p><p><a href="https://github.com/vapurrmaid/SlotMachineExample">vapurrmaid/SlotMachineExample</a></p><p>I write articles regarding explorations in computer science and web development on a ~weekly basis. Read Code Something Weekly: How and Why for more information:</p><p><a href="https://medium.com/@vapurrmaid/code-something-weekly-how-and-why-44640d279ca1">Code Something Weekly: How and Why</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26f6716bce18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Express Servers — RUN__ON Part 3]]></title>
            <link>https://medium.com/@vapurrmaid/creating-an-express-server-run-on-part-3-f5e1dc7c6570?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5e1dc7c6570</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Mon, 03 Sep 2018 13:01:02 GMT</pubDate>
            <atom:updated>2018-09-03T16:49:18.001Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Express Servers — RUN__ON Part 3</h3><p>CS Weekly 8 — RUN_ON Part 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6ZYklYD8JV2nov5v1QEoA.png" /></figure><p>This is Part 3 of a mini-series that discusses several topics in creating a full-stack web application called <a href="https://github.com/vapurrmaid/run__on"><strong>RUN__ON</strong></a>.</p><ul><li>Part 1 — <a href="https://medium.com/@vapurrmaid/getting-started-with-travis-npm-linting-and-greenkeeper-run-on-part-1-7a2a1a228d3a">Setting up CI and Project Infrastructure</a></li><li>Part 2 — <a href="https://medium.com/@vapurrmaid/getting-started-with-heroku-postgres-and-pgadmin-run-on-part-2-90d9499ed8fb">Setting up Heroku Postgres</a></li><li>Part 3 — Creating an Express Application <strong>(You Are Here)</strong></li></ul><p>This mini-series is apart of an effort called CS Weekly, a manifesto towards committing oneself to weekly programmatic explorations in an article found here:</p><p><a href="https://medium.com/@vapurrmaid/code-something-weekly-how-and-why-44640d279ca1">Code Something Weekly: How and Why</a></p><h3>Server Application Architecture</h3><p>As with most languages, defining a simple entry-point into a program is useful. In Java, one has a class with the function main() and often has an application entry file dedicated to simply calling this main function.</p><p>Although this is purely convention and not a constraint, defining an entry in a Node application called index.js (analogous to index.html) is a very common practice. The idea is to execute minimum configurations and make top-level imports. The file shouldn’t export anything nor should it contain definitions (such as functions or constants to be used elsewhere).</p><p>I often see developers importing and configuring express in the index.js entry file. Personally, I don’t like this practice and instead designate express configuration to a file called app.js. To me it creates a clearer separation of concerns, as index.js actually creates a server from Node’s http class using an express configuration. That is to say, one can define an express application without creating an HTTP server.</p><p>Thus, the server architecture, omitting sub-directories, should look as follows:</p><pre>root<br>|_ .gitignore<br>|_ .travis.yml<br>|_ app.js<br>|_ index.js<br>|_ package.json</pre><h3>Adding Debug</h3><p>Before writing any code, let’s add a neat little package called debug.</p><p><a href="https://www.npmjs.com/package/debug">debug</a></p><pre>npm install --save debug</pre><p>This package gives us the ability to see different types of console statements depending on environment variables.</p><p>The typical use is as follows:</p><pre>const debug = require(&#39;debug&#39;)(&#39;project_name::file&#39;)</pre><p>It exports a function that takes a string parameter. This string parameter is the <strong><em>name </em></strong>of the debugger. There can be multiple named debuggers through a project or even a single file. I recommend <em>one per file</em>.</p><p>These debuggers are used much like console.log:</p><pre>debug(&#39;error %O&#39;, err)</pre><p>Throughout the application I’ll use the them as follows:</p><pre>// eslint-disable-next-line no-unused-vars<br>const debug = require(&#39;debug&#39;)(run__on::server::&lt;file&gt;)</pre><p>The // eslint-disable... comment tells <a href="https://eslint.org/">ESLint</a> checkers that if the variable on the next line isn’t used, don’t throw an error. That’s because debuggers are often commented out, and I don’t want red lint errors lighting up as a result.</p><p>The reason the debugger name is prefixed with run__on:: is so that one can do the following (note the wildcard, *):</p><pre>export DEBUG=run__on::* &amp;&amp; npm run server</pre><p>This runs every single debugger named in the project.</p><p>If only concerned about a specific file, export just that debugger:</p><pre>export DEBUG=run__on::foo.js</pre><p>Now the console will show debug statements <em>only </em>from that specific file.</p><h3>Application Entry: Creating a Server</h3><p>A simple HTTP server in node can be written in very few lines. Thus I think it’s best to share those lines and then discuss their meaning:</p><pre>// eslint-disable-next-line no-unused-vars<br>const debug = require(&#39;debug&#39;)(&#39;run__on::server::index.js&#39;)</pre><pre>// dependencies<br>const http = require(&#39;http&#39;)</pre><pre>// dynamically set PORT<br>const port = process.env.PORT</pre><pre>// internals<br>const app = require(&#39;./app&#39;)()</pre><pre>const server = http.createServer(app)<br>server.listen(port)<br>debug(&#39;listening on port %d&#39;, port)</pre><p>First, the only dependencies so far are:</p><ul><li>http — A Node module (<a href="https://nodejs.org/api/http.html#http_http">docs</a>)</li><li>app (the express application, see next section)</li></ul><p>The line:</p><pre>const port = process.env.PORT</pre><p>dynamically sets the variable port to the environment variable called PORT. A port is just one of the many connection endpoints for a server. <a href="https://stackoverflow.com/questions/4822965/what-does-localhost8080-mean">There’s a helpful StackOverflow thread for those interested in reading more</a>. In production, the PORT is set by Heroku — we have no control over it, and its value will change on successive starts.</p><p>In development, a script will start the server and the PORT environment variable can be explicitly defined. This will be shown towards the end of the article.</p><p>The rest is taken care of by express, as shown here:</p><pre>const server = http.createServer(app)<br>server.listen(port)</pre><p>Essentially, an express application configures details about how an HTTP server should respond to requests.</p><p>And that’s it — a rather simple entry into the application. Invoke top-level dependencies (for now this is just app.js, though in time a database import will be made) and start a server listening on a specific port for requests.</p><h3>Express Applications</h3><p>Express isn’t needed in order to configure an HTTP Server. However, the interface Node exposes is low-level. For common functionalities such as defining endpoints, Express provides a nice framework to work with. In their own words Express is a:</p><blockquote>Fast, unopinionated, minimalist web framework for <a href="https://nodejs.org/en/">Node.js</a></blockquote><p><a href="https://expressjs.com/">Express.js · Node.js web application framework</a></p><p>To get started:</p><pre>npm install --save express</pre><p>Everything else written in this section will be located in app.js. Before any code is written, let’s have a quick discussion on what app.js should export.</p><h4>Exporting a Function</h4><p>As seen in index.js, the express import is some kind of Object:</p><pre>const server = http.createServer(app)</pre><p>Given that express is just a configuration, it seems clear to me that it’s possible to configure various express applications for multiple servers on different ports. Perhaps in the future one might want to add parameters when importing. Therefore, I believe it’s ideal to actually export a function:</p><p><strong>app.js:</strong></p><pre>module.exports = function () {<br>  return app<br>}</pre><p><strong>index.js:</strong></p><pre>const app = require(&#39;./app&#39;)()</pre><blockquote><strong>Note:</strong> an es6 fat arrow could be used in place of the function keyword.</blockquote><p>Now we’re ready to explore what Express is.</p><h4>How Express Works: A Stack of Middleware</h4><p>Express applications are remarkably simple once you start writing them. Most express applications can be honestly boiled down to two items:</p><ul><li>Set some configurations .set()</li><li>Add a series of functions (called middleware) .use()</li></ul><p>All of the middleware functions (from hereon ‘middleware’) are invoked in <strong>the order they are specified</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*nncpTfI-k6elgzM50ffhWg.png" /><figcaption>An Express Application</figcaption></figure><h4>Express Configurations</h4><p>What kinds of things would be configured for an express application?</p><ul><li>Key/Values (ex ‘port’)</li><li>Register paths (ex ‘views’)</li><li>Register engines (ex ‘handlerbars’)</li></ul><p>At this stage in the application, we’ll do a few things:</p><ul><li>Set the ‘Port’ value:</li><li>Enable &#39;trust proxy&#39;</li><li>Set a ‘views’ directory and ‘view engine’</li></ul><h4><strong>Setting Port</strong></h4><p>We need to do 2 things:</p><ol><li>Pass the port from index.js to the Express Application</li><li>Set the Express Application port from a parameter</li></ol><p><strong>index.js</strong></p><pre>const app = require(&#39;./app&#39;)({ port })</pre><p><strong>app.js</strong></p><pre>module.exports = function ({ port }) {<br>  const debug = require(&#39;debug&#39;)(&#39;run__on::server::app.js&#39;)<br>  const express = require(&#39;express&#39;)<br>  <br>  const app = express()<br>  if (port) {<br>    debug(&#39;setting port to %d&#39;, port)<br>    app.set(&#39;port&#39;, port)<br>  }<br>}</pre><h4>Enabling Trust Proxy</h4><p>Examination of the <a href="https://devcenter.heroku.com/articles/http-routing#routing">Heroku documentation</a> demonstrates that requests are forwarded to the application through a load balancer. In other words, by using Heroku your application sits behind their proxies.</p><p>Thus, we have to specify that we trust headers containing x-Forwarded, which is accomplished by a simple line:</p><pre>app.enable(&#39;trust proxy&#39;)</pre><p>From the Express documentation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*HCpR1n0Af6js4I28XyWlKw.png" /><figcaption><a href="https://expressjs.com/en/4x/api.html#app.set">https://expressjs.com/en/4x/api.html#app.set</a></figcaption></figure><h4>Setting Views (to Pug)</h4><p>Server side view engines are used to render HTML on the server. In other words, an application <em>doesn’t need </em>Vue or React or any fancy front-end JavaScript frameworks. For simple applications, one could just send server-side rendered HTML using a template language of their choice (ex: handlebars, pug).</p><p>However, as stated in <a href="https://medium.com/@vapurrmaid/getting-started-with-travis-npm-linting-and-greenkeeper-run-on-part-1-7a2a1a228d3a">Part 1</a>, a Vue client will be used down the line.</p><p>Then why bother setting a server-side template engine? Specifically for one, super simple purpose: an error fallback view. In the case that for whatever reason a request cannot resolve by sending the Vue client, a generic Error page can be shown.</p><p>Pug is an extremely minimal (read simple) template engine. We can avoid writing HTML tags and all sorts of annoying syntax, which is desirable given that the only thing we’re using this for is to show a generic error page.</p><p><a href="https://pugjs.org/api/getting-started.html">Getting Started</a></p><pre>npm install --save pug</pre><p>Set the view engine with:</p><pre>app.set(&#39;view engine&#39;, &#39;pug&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*W6XZXKnC4m0PvYOhn48Sag.png" /><figcaption><a href="https://expressjs.com/en/4x/api.html#app.set">https://expressjs.com/en/4x/api.html#app.set</a></figcaption></figure><p>Then, tell express where these pug files are located so that paths can be omitted when rendering from these templates:</p><pre>app.set(&#39;views&#39;, path.join(__dirname, &#39;views&#39;))</pre><p>Thus, the Express Application so far is:</p><pre>module.exports = function ({ port }) {<br>  const debug = require(&#39;debug&#39;)(&#39;run__on::server::app.js&#39;)<br>  const express = require(&#39;express&#39;)<br>  const path = require(&#39;path&#39;)<br>  <br>  // Configuration ----------------/<br>  debug(&#39;configuring express application&#39;)</pre><pre>  const app = express()</pre><pre>  // set the port<br>  if (port) {<br>    debug(&#39;setting port to %d&#39;, port)<br>    app.set(&#39;port&#39;, port)<br>  }</pre><pre>  // res.render calls use pug templates in views directory<br>  app.set(&#39;view engine&#39;, &#39;pug&#39;)<br>  app.set(&#39;views&#39;, path.join(__dirname, &#39;views&#39;))</pre><pre>  // for use behind Heroku proxy<br>  app.enable(&#39;trust proxy&#39;)</pre><pre>  return app<br>}</pre><h4>Creating An Error View</h4><p>All we are going to do is render a bare-bones HTML document with a title, body and &lt;h1&gt; tag. This is quite easily accomplished with a few lines in pug.</p><pre>mkdir views<br>touch views/error.pug</pre><p><strong>error.pug</strong></p><pre>html<br>  head<br>    title= title<br>  body<br>    h1= message</pre><p>In the above, title= and h1= designate template variables. When we want to render this error.pug file, it will expect to receive a title and a message in its parameters.</p><h4>Express Middleware</h4><p>The application so far has a few basic configurations. Now, we have to add the middleware functions — <strong>in order</strong>.</p><p>What kinds of middleware functions would an express application use?</p><ul><li>Incoming request modifiers</li><li>Request verification</li><li>Request handlers</li><li>Response handlers</li><li>Error handlers</li></ul><p>At this stage, we’ll do the following (in order):</p><ul><li>Setup basic security</li><li>Setup a rate limiter</li><li>Setup a router</li><li>Setup an error handler</li></ul><p>Everything we add will be <strong>after</strong> the prior configuration:</p><pre>module.exports = function ({ port }) {<br>  const debug = ...<br>  const express = ...<br>  <br>  app.set(...)</pre><pre>  // MIDDLEWARES HERE<br>}</pre><h4>Basic Security with Express Helmet</h4><p>Straight from the Express documentation, Helmet is listed as a security best practice.</p><p><a href="https://expressjs.com/en/advanced/best-practice-security.html#use-helmet">Security Best Practices for Express in Production</a></p><p>Straight from Helmet:</p><blockquote>Helmet helps you secure your Express apps by setting various HTTP headers. <em>It’s not a silver bullet</em>, but it can help!</blockquote><p>The beauty is, it’s super simple to use for most cases.</p><pre>npm install --save helmet</pre><p><strong>within app.js</strong></p><pre>const helmet = require(&#39;helmet&#39;)<br>  <br>app.use(helmet())<br></pre><p>There are optional configurations to set with Helmet, and Helmet offers a nice table to show exactly what it’s doing and how to configure each setting:</p><p><a href="https://helmetjs.github.io/">Helmet.js</a></p><h4>Express Rate Limiter</h4><p>Rate limiting monitors the number of requests being made by a particular address over a window of time. It essentially blocks malicious scripts from spamming requests to your server.</p><pre>npm install --save express-rate-limit</pre><p><a href="https://www.npmjs.com/package/express-rate-limit">express-rate-limit</a></p><p><strong>within app.js:</strong></p><pre>const RateLimit = require(&#39;express-rate-limiter&#39;)</pre><pre>app.use(new RateLimit({<br>  // 10 minutes<br>  windowMs: 10 * 60 * 1000,<br>  // 1000 requests per 10 mins<br>  max: 1000,<br>  delayMs: 0<br>}))</pre><p>Here I’ve set some arbitrary values: every 10 minutes, a client can make 1000 requests. This is very small and will definitely change in the future, but it’s a nice value to start with and can be verified with tests.</p><h4>Add Routes To Middleware Stack</h4><p>Express Routing will be covered in a future article. For now, I’ll demonstrate just exactly where it goes in the middleware stack, but note that we won’t be actually creating a Router just yet.</p><p>Create a routes directory with an index.js:</p><pre>mkdir routes<br>touch routes/index.js</pre><p>Inside <strong>app.js</strong> instead of explicitly calling app.use(), we’ll pass app to the router which will be responsible for setting things up:</p><pre>require(&#39;./router&#39;)(app)</pre><p>Inside <strong>routes/index.js</strong>, we’ll just create some boilerplate:</p><pre>const debug = require(&#39;debug&#39;)(&#39;run__on::server::routes/index.js&#39;)</pre><pre>module.exports = (app) =&gt; {<br>  debug(&#39;configuring express application router&#39;)<br>}</pre><p>In the future, this file will use app.use() to add Express.Router configurations.</p><h4>Middleware Functions</h4><p>The first thing to note is that middleware are callback functions, denoted cb:</p><pre>app.get(&#39;...&#39;, cb1, cb2, ..., cbn)</pre><p>It’s desirable to define callback functions somewhere else and import them, rather then defining them in-line. The reason is that they can’t be tested or used again if they’re defined anonymously in-line.</p><p>Thus, let’s create a directory for middlewares:</p><pre>mkdir middleware</pre><p>There are two types of middleware functions</p><ul><li>‘regular’</li><li>‘error’</li></ul><p>Regular middleware functions utilize 3 parameters:</p><ul><li>req — short for Request. This contains an HTTP request Object with all sorts of information about the request made by a client</li><li>res — short for Response. This contains methods for the express application to send HTTP response Objects back to clients.</li><li>next — Calls the next middleware in the stack. Either takes no arguments or a single argument.</li></ul><p>Error middlewares receive an additional argument err as the first argument, then everything else: req, res, next.</p><p>The term ‘middleware’ is ambigious — there could be many different middleware functions:</p><ul><li>security</li><li>validation</li><li>response handling</li><li>error handling</li></ul><p>This is optional, but I like to place these functions in files that match their purpose, then import them all into a single file middleware/index.js.</p><pre>touch middleware/index.js</pre><p>The reason is rather simple: one can import any middleware by doing the following:</p><pre>const { internalError } = require(&#39;./middleware&#39;)</pre><p>The actual file where the function lives doesn’t have to be included in the require path. In the end, index.js will just contain an Object of every middleware function. Separating them out into files just makes them easier to maintain.</p><blockquote><strong>Note:</strong> given that middleware are callbacks which could just as easily be defined in-line, they’re suitable for fat-arrow functions. In other words a first-class function with closure isn’t needed.</blockquote><h4>Adding An Error Middleware</h4><p>The last middleware to add for now is a catch-all error handler.</p><pre>touch middleware/errors.js</pre><p>A scaffold for a first error middleware is:</p><pre>const internalError = (err, req, res, next) =&gt; {<br>  // handle error here<br>}</pre><p>Recall earlier that a pug view named error.pug was created, containing a title and a message. Well, this error handler will only be called when something goes wrong, and thus we can do two things for now:</p><ol><li>console.log/debug print the error</li><li>Render the error.pug view with a basic message</li></ol><p>In order to do the latter, res.render() can be used. Recall earlier that both views and view engine where set in the application configuration. This allows us to simply send a string of the <em>name of the file</em> (omitting the ‘pug’ extension), as well as an object mapping each template variable to a value:</p><pre>res.render(&#39;error&#39;, {<br>  title: &#39;...&#39;,<br>  message: &#39;...&#39;<br>})</pre><p>Thus, a complete error middleware is as simple as:</p><pre>const debug = require(&#39;debug&#39;)(&#39;run__on::server::middelware/error.js&#39;)</pre><pre>const internalError = (err, req, res, next) =&gt; {<br>  debug(&#39;internal error %O&#39;, err)<br>  res.render(&#39;error&#39;, {<br>    title: &#39;Error status 500&#39;,<br>    message: &#39;Internal Server Error&#39;<br>  })<br>}</pre><pre>module.exports = {<br>  internalError<br>}</pre><blockquote><strong>Note: </strong>If you use middleware/index.js, make sure to import/export this function there as well.</blockquote><h3>Final Touches and Testing</h3><p>So far, we’ve done the following:</p><ul><li>create an HTTP server using an Express Application configuration</li><li>Create an Express Application to trust proxies, use pug views located in a ‘views’ directory,</li><li>Add security and rate-limiting middlware functions</li><li>Initialize an empty Router</li><li>Add an error middleware</li></ul><h4>Setting PORT through environment</h4><p>At the beinning of the article I said we’d need to invoke the server with a PORT environment variable. The last step is to add a script in the package.json that does exactly this. Furthermore, I suggest installing nodemon as a development dependency as will become clear shortly:</p><pre>npm install --save-dev nodemon</pre><p><strong>package.json</strong></p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node index.js&quot;,<br>  &quot;server&quot;: &quot;cross-env PORT=3000 nodemon index.js&quot;,<br>  &quot;test&quot;: &quot;npm run lint&quot;,<br>  &quot;lint&quot;: &quot;standard&quot;<br>}</pre><p>The reason nodemon is used in development is that it hot-loads changes. Without it, the server process has to be manually killed and restarted in order to see changes. nodemon automatically restarts the server process after each save.</p><p>cross-env was downloaded in the prior tutorial. If you omitted that step, I suggest installing it now:</p><pre>npm install --save-dev cross-env</pre><p>It allows a common api to list environment variables regardless of operating system.</p><p>In order to start everything AND see the debug logs, use:</p><pre>export DEBUG=run__on::server* &amp;&amp; npm run server</pre><p>I get the following pretty logs (note that the debug package uses a different color for each named debugger!):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*55pdZNv_IYEAVPkjQYfx9A.png" /><figcaption>debug for the win!</figcaption></figure><blockquote><strong>NOTE: </strong>If using Git Bash for Windows and there’s trouble seeing the colours, try re-installing and allowing true type font. Furthermore, adding export FORCE_COLOR=true in ~/.bashrc may help.</blockquote><h4>Testing The Error View</h4><p>Currently, if you open up a browser to localhost:3000 (or whatever PORT you used), you should see:</p><pre>Cannot GET /</pre><p>But I thought we added error middleware to handle these things, what’s going on?</p><p>Well recall the middleware parameters: error, req, res, next.</p><p>The way the middleware gets called is from another middlware function:</p><pre>some_function = (req, res, next) =&gt; {<br>  next()<br>}</pre><p>next doesn’t call the error middleware <strong>unless you add an argument.</strong> Otherwise, next calls the next regular middleware in the stack (<strong>order matters!!!!!</strong>).</p><p>So without explaining how routing works, let’s just test this out. We’ll add another middleware before the error one, and demonstrate how ‘next’ works:</p><pre>app.use((req, res, next) =&gt; {<br>  res.send(&#39;foo&#39;)<br>})</pre><p>Then, right under require(&#39;./routes&#39;)(app), create a GET request handler:</p><pre>app.get(&#39;*&#39;, (req, res, next) =&gt; {<br>  next()<br>})</pre><p>Here’s how the code should look:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a853525d7a5e2051e855bb063bf03f9c/href">https://medium.com/media/a853525d7a5e2051e855bb063bf03f9c/href</a></iframe><p>Refresh or visit localhost:3000 (or your PORT) now, and you’ll see a blank page with ‘foo’ on it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*5CwIlQa-ITz3-nEyUnOnaw.png" /></figure><p>You can create other middlware functions and change their order in the stack:</p><pre>app.get(&#39;*&#39; ...)<br>app.use((req, res, next) =&gt; {<br>  res.send(&#39;bar&#39;)<br>})<br>app.use((req, res, next) =&gt; {<br>  res.send(&#39;foo&#39;)<br>})</pre><p>In the case of above, you’ll get a message ‘bar’ appearing in the browser.</p><p>However, if you change the GET handler to call next with an argument:</p><pre>app.get(&#39;*&#39;, (req, res, next) =&gt; {<br>  next(&#39;boom&#39;)<br>})</pre><p>You’ll see that the regular middleware are skipped and instead the error middleware is called:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*RfvO8twsbWZvBfggn9dsbQ.png" /></figure><blockquote><strong>Note:</strong> next() <strong>without </strong>an argument will <strong>never </strong>reach the error middleware. You’ll simply get a cannot GET / message if there is no further middleware.</blockquote><h3>Wrap Up</h3><p>Entry files should contain minimum calls and configuration. A suitable server entry file involves creating a server using Node’s http.createServer method with an express application and binding to a PORT specified by the environment.</p><p>Express applications consist of an initial configuration and a series of functions called middleware. Middleware is divided into regular and error-handling, the latter receiving 4 arguments err, req, res, next while the former only receiving only req, res, next. The order of middleware matters and the next function calls the next middleware defined in the stack. To reach an error middleware, next is called with an argument.</p><p>The code for the entire project <strong>RUN__ON </strong>is on Github:</p><p><a href="https://github.com/vapurrmaid/run__on">vapurrmaid/run__on</a></p><p>And the code for this specific article is in a pull request:</p><p><a href="https://github.com/vapurrmaid/run__on/pull/3">Initialize Express Server by vapurrmaid · Pull Request #3 · vapurrmaid/run__on</a></p><h3>Resources</h3><ul><li><a href="https://expressjs.com/en/guide/writing-middleware.html">Express Middleware</a></li><li><a href="https://expressjs.com/en/advanced/best-practice-security.html#use-helmet">Express Best Security Practices</a></li><li><a href="https://helmetjs.github.io/">Express Helmet</a></li><li><a href="https://www.npmjs.com/package/express-rate-limit">Express Rate Limiter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5e1dc7c6570" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Heroku, Postgres and PgAdmin - RUN__ON Part 2]]></title>
            <link>https://medium.com/@vapurrmaid/getting-started-with-heroku-postgres-and-pgadmin-run-on-part-2-90d9499ed8fb?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/90d9499ed8fb</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 13:01:02 GMT</pubDate>
            <atom:updated>2018-08-27T15:35:21.019Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with Heroku, Postgres and PgAdmin — RUN__ON Part 2</h3><p>CS Weekly 7 — RUN_ON Part 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6ZYklYD8JV2nov5v1QEoA.png" /></figure><p>This is Part 2 of a mini-series that discusses several topics in creating a full-stack web application called <a href="https://github.com/vapurrmaid/run__on"><strong>RUN__ON</strong></a>.</p><ul><li>Part 1 — <a href="https://medium.com/@vapurrmaid/getting-started-with-travis-npm-linting-and-greenkeeper-run-on-part-1-7a2a1a228d3a">Setting up CI and Project Infrastructure</a></li><li>Part 2 — Setting up Heroku Postgres (<strong>You are here)</strong></li></ul><p>This mini-series is apart of an effort called CS Weekly, a manifesto towards committing oneself to weekly programmatic explorations in an article found here:</p><p><a href="https://medium.com/@vapurrmaid/code-something-weekly-how-and-why-44640d279ca1">Code Something Weekly: How and Why</a></p><h3>Working With Databases Locally and Remotely</h3><p>I’m not going to lie, this topic is a bit challenging to approach in an elegant manner. I’ll attempt to outline the problems of working with various databases and an opinionated method to manage everything using pgAdmin and Heroku.</p><p>When developing an application that makes heavy use of a database(s), one can imagine that <em>at least 3</em> databases exist:</p><ul><li><strong>Production database</strong> — live on a server somewhere, containing the application data</li><li><strong>Development database</strong>(s) — either locally on each developer’s computer, or hosted centrally somewhere else</li><li><strong>Test database</strong>(s) — like the development databases, for use in continuous integration and running tests.</li></ul><p>Given these various versions, one can run into issues making sure the schemas and data are consistent across the board. Imagine for a second that there’s a minor unnoticed inconsistency somewhere between the development and production databases. Code running on the development database seems to work, but might not work as expected live.</p><p>It’s thus desirable to avoid the possibility of inconsistencies and therefore a streamlined mechanism to synchronize everything is rather valuable.</p><h4>Working with Heroku Datastores</h4><p>Thankfully, there are ways to create database dump files which contain all of the information to reproduce a database. Furthermore, <a href="https://devcenter.heroku.com/articles/heroku-postgres-import-export">Heroku offers ways to both import and export databases by using such dump files</a>.</p><p>The problem with the <a href="https://devcenter.heroku.com/articles/heroku-postgres-import-export#import-to-heroku-postgres">import method</a> is that it requires saving a dump file somewhere with a publicly accessible http URL (ie: it cannot be done through Heroku dashboard, unfortunately). They quickly add:</p><blockquote>For security, we recommend obscuring the filename and also removing the file once the import has completed.</blockquote><p>But I’m not going to lie, this doesn’t sit well with me. At all. They recommend setting up an Amazon S3 account to mitigate risks etc, but for a simple API this is yet another hoop to step through and manage, particularly as a solo developer.</p><p>Imagine accidentally leaving a dump file with sensitive information sitting somewhere. Yea, not the most pleasant of thoughts.</p><p><strong>Thus, I’ve justified to myself working in a rather opposite/non-intuitive manner: I create changes to the Heroku production database and export them locally.</strong></p><p>In practice, this pipeline looks as follows:</p><ul><li>Import the production database locally</li><li>Play around with proposed changes</li><li>Run the new SQL in production</li><li>Re-sync local databases</li></ul><p>Given everything, it’s important to start getting set remotely from the start, before development spirals out of control. If there’s anything learned from both parts of this series thus far, it’s that big projects require a lot of infrastructure and thought. Diving head-first into code is great for prototyping, but is not ideal and will most certainly cause a need to backtrack when actually attempting to get everything working in harmony.</p><h3>Setting Up Heroku Postgres</h3><p>Sign into Heroku/create an account and then go to the apps dashboard <a href="https://dashboard.heroku.com/apps">https://dashboard.heroku.com/apps</a>.</p><ul><li>new &gt; create new app</li></ul><h4>Installing the CLI</h4><p>Heroku warns against installing with npm as unlike using other installers it doesn’t expose autoupdates.</p><p>Check the page below and use the appropriate installer for your system:</p><p><a href="https://devcenter.heroku.com/articles/heroku-cli#download-and-install">The Heroku CLI</a></p><p>Once done, optionally add the heroku-pg-extras <a href="https://github.com/heroku/heroku-pg-extras">plugin </a>as follows:</p><pre>heroku plugins:install heroku-pg-extras</pre><h4>Adding Postgres</h4><p>From the application dashboard on Heroku, go to the ‘resources’ tab and search for postgres. Provision it and use the free option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rS0wAD5j6NTaZI0ob2KJtQ.png" /><figcaption>Adding Heroku Postgres</figcaption></figure><p>There’s now a clickable link to the Datastore associated with your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VtkoxeWQmxDeveXUqwmtaw.png" /><figcaption>Clickable link to the Datastore</figcaption></figure><p>Go ahead and open the link to your datastore, and take note of exactly how to get here again. Go to the settings tab and notice an option to reveal credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rm_xi_sUAiI0rCfxyd-BwQ.png" /><figcaption>The URI information to connect to your database</figcaption></figure><p>It’s important to know how to find these credentials as they’ll be needed to communicate with the heroku database locally.</p><h4>Installing Postgres/pgAdmin locally</h4><p>If you don’t have postgres locally, download it along with pgAdmin:</p><p><a href="https://www.postgresql.org/download/">Downloads</a></p><p>As stated on the downloads page, the installer should include pgAdmin (among various other clients). Ensure that this is the case and that these options are checked during installation.</p><p>It’s easy to verify if postgres exists by simply just running one of the clients</p><pre>createdb --version</pre><p>If for some reason you have postgres installed but not pgAdmin, you can add it separately:</p><p><a href="https://www.pgadmin.org/download/">Download</a></p><h4>Accessing Remote Databases Locally</h4><blockquote><strong>Note: </strong>For the following, keep your Heroku Postgress datastore credentials open in a tab, as we’ll be using them to connect.</blockquote><p>pgAdmin is a GUI for postgresql databases that can be used to access and modify databases that not only exist locally, but also remotely.</p><p>For a fresh install of pgAdmin, the dashboard likely contains only one server. This is your local server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*WuQRDYLqWI1J4zERwfBIEw.png" /><figcaption>PostgreSQL 10 is the default local server on my version of pgAdmin</figcaption></figure><p>Expanding it reveals local databases, existing on your physical device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*PYtKt3BKHTTHEsjXhvj11A.png" /><figcaption>ps I wrote about MyMusic in a previous CS Weekly article</figcaption></figure><p>However, as one might intuit, there are different credentials when connecting to a remote server. Thus we have to actually configure a new server with those credentials.</p><ul><li>right click server(s) &gt; create &gt; server …</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*c_JV2YBVltrfI6Vs1tprGg.png" /></figure><p>Fill out the following:</p><ul><li><strong>Name</strong>: This is solely for you. Name it whatever you want, I chose ‘Heroku-Run — On’</li><li>Under the connection tab: <strong>hostname/address. </strong>If you go back to your datastores ‘reveal credentials’, this is the <strong>host</strong> credential. It should look like **-**-**...amazonaws.com</li><li>Keep the <strong>port </strong>at 5432, unless your credentials list otherwise</li><li><strong>Maintenance database</strong> — this is the <strong>database</strong> field in the credentials</li><li><strong>Username</strong> — this is the <strong>user</strong> field in the credentials</li><li><strong>Password</strong> — the <strong>password</strong> field in the credentials. I highly advise checking <strong>save password</strong> so that you don’t have to copypasta this every time you want to connect.</li><li>In the SSL tab, mark <strong>SSL mode</strong> as <strong>require</strong></li></ul><p>At this point, if we were to hit ‘save’ (<em>please don’t</em>), something very strange would happen. You’d see hundreds if not thousands of databases appear in pgAdmin. This has to do with how Heroku configures their servers. You’ll still only have access to your specific database, not those of others. In order to avoid parsing so many databases (don’t believe me, check out the image below), we have to white list only those databases we care about.</p><ul><li>go to the Advanced tab and under <strong>db restriction </strong>copy the database name (it’s the same value as the <strong>Maintenance database</strong> field filled earlier).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*0Y2_-fNQjtpZV74cwlYdJA.png" /></figure><p>Failure to white list your database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*GxzEvw2OnAFGuu45vgq3Wg.png" /></figure><h3>Preliminary Schema</h3><p>At this point we have:</p><ul><li>A Heroku application provisioned with Postgres</li><li>A connection to the production database</li></ul><p>The next step is to start creating the first version of a schema and syncing everything with the development and test environments.</p><p>Since the point of this article isn’t database design, let’s just quickly consider what data we’re likely to want to store in such an application:</p><ul><li>Users — id, name, picture, joined</li><li>Stories — id, title, author, story, created, edited</li></ul><p>While it’s true that Stories could be broken out into phrases, I think it will suffice to keep things simpler for now.</p><h4>Creating Users Table in pgAdmin</h4><ul><li>Expand database &gt; database &gt; schemas &gt; public &gt; Tables</li><li>Right click &gt; create &gt; table…</li><li>General tab, fill in the name <strong>users</strong>. I keep mine lowercase, otherwise the generated SQL will use quotation marks. Ensure <strong>owner </strong>matches your user credential, the schema is <strong>public</strong>. Additionally I like to set the tablespace to <strong>pg_default</strong>, which is just indicating how things are stored on disk.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZiQ_plt2ggiSpbzhxz5Jg.png" /></figure><p>Under Columns, add</p><ul><li>id: serial, not null, primary key</li><li>name: varchar, length 20, not null</li><li>picture: text</li><li>joined</li></ul><p>Use the ‘edit’ icon to the left for the joined column, as we’ll need to specify some extra details. A menu should open up. Click the ‘definition’ tab of which can be used to specify a default value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cluLChUSYa1WGvDKQYxpQ.png" /><figcaption>Giving the timestamp a default value</figcaption></figure><p>Re-click the edit icon to leave the menu. The column definitions look as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bnD152bPMyKsok1f7h_I5Q.png" /><figcaption>A First Version of the User Columns</figcaption></figure><p>Now this next step is entirely optional, but I think it’s worth doing just to demonstrate pgAdmin functionality.</p><ul><li>Go the Constraints tab and the Unique sub-tab</li><li>Add a unique constraint for the ‘name’ column, which means that users cannot share the same username.</li><li>Give the constraint a name and optionally a comment in the ‘general’ tab. This is mosly for your own housekeeping.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Whw7DTxWL5LWTVOxwZfjA.png" /><figcaption>Username constraint</figcaption></figure><ul><li>Finally in the Definition tab, list the appropriate column</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJOqllZU_f0fvuC_rzNoXg.png" /></figure><p>Before clicking ‘save’ and thus creating the table, there’s one last thing to do. Checkout the SQL<strong> </strong>tab to see the SQL statements that were generated from filling in all of the above. Ensure everything looks as expected, then hit save!</p><h4>Creating Stories Table</h4><p>Alright, we’re pros at using pgAdmin now so I’ll fast-forward a bit.</p><p>The columns should look as follows. Note the jsonb type for the <strong>story</strong> column and the integer type for the <strong>author </strong>column. Make sure the <strong>created</strong> and <strong>edited</strong> columns have the default value filled out as done previously in the users table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFw2QLuqckuUwcXb7bI08A.png" /></figure><p>The reason the <strong>story</strong> is of type jsonb will become clear in the future, but essentially we can represent a single story as a custom defined Object, rather than storing separate Text/String phrases or a massive String.</p><p>Next we have to associate the <strong>author</strong> as a foreign key to the users table.</p><ul><li>Constraints tab &gt; Foreign Key sub-tab</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZxQ_8XcAh0aPRvVqsFXgg.png" /></figure><p>Skip over to the columns tab. Fill out the information and <strong>very importantly, once it’s entered hit the little ‘plus’ sign hiding to the right</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8G1zW7lYxxjWpIMRPeCVxw.png" /></figure><p>Finally, head to the Action tab and set update/delete to cascade. For those unfamiliar with cascading, it’s just to keep the referenced Author up to date with the Story. In the case of an Author being deleted from the application, their stories will cascade delete.</p><blockquote>Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new values of the referenced columns, respectively.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0KXFZqq_0ce71Yssxhe7Fw.png" /></figure><h4>Editing Data with pgAdmin</h4><p>pgAdmin can not only run SQL scripts, but also provides a visual way to edit data. Using the visual editor, quickly verify the tables work as expected.</p><ul><li>Right click users &gt; view/edit data &gt; all rows</li></ul><p>Fill in an id and a name, then hit save. If the created column was properly set to use a default value, the current timestamp should automatically be inserted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*2HVfq8Z_HObMyPz7C5rQog.png" /><figcaption>Nice, an automatically created timestamp</figcaption></figure><p>Next, test out the stories table. Add an id, title, author with the same id as the created user, some placeholder JSON and click ‘save’. The created and edit timestamps should automatically update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*a8xvQ6yUU8f3SZIulGJ2tg.png" /></figure><p>Now test deleting the user to see the cascade in action.</p><ul><li>Head to the users table, click the leftmost ‘1’ in order to highlight the row, then hit the delete button at the top.</li><li>Head back to the stories table tab. You might still see the row there, but hitting the refresh button (the lightning symbol at the top) should now no longer show the previously created row, since the user was deleted!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*ZvlBZ4twtCs1RfaavfWyYg.png" /><figcaption>the execute/refresh button</figcaption></figure><h4>Adding an Update Trigger Function in pgAdmin</h4><p>We have the nice edited column in the stories table, but it won’t actually do anything if you edit the data (verify this for yourself). Instead, we need to actually implement a trigger function.</p><ul><li>trigger functions &gt; right click &gt; create &gt; trigger function…</li></ul><p>We’re going to create a trigger function that can be used for any table that has an edited column. Quite simply, a trigger function is some function to run on a specified event. The function is declared separately from the events that trigger it.</p><ul><li>in the general tab, give it a name. I called mine <strong>edited</strong></li><li>(optionally) leave a comment — I wrote “Updates edited column timestamp”</li><li>In the definition tab, add the following code</li></ul><pre>BEGIN<br>  NEW.edited := NOW();<br>  RETURN NEW;<br>END;</pre><ul><li>In the options tab, select <strong>volatile</strong> (means that this value can change during scans, which is true if a user rapidly sends post requests to the same resource)</li></ul><p>Creating a trigger function was simple enough, but as stated prior events have to be associated to it. Back to the stories table:</p><ul><li>expand stories &gt; right click triggers &gt; create &gt; trigger…</li></ul><p>Give it a useful name and comment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*TPaorVvr6ssFxn4TpYkdXg.png" /></figure><p>Associate it to the proper trigger function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*sXmjK9pfL_zhVqOvMkrcuA.png" /></figure><p>In the Events tab, indicate to run this function on table updates. Furthermore, specify only the title and story columns, as we don’t really care if the Author changes their name and I sure as hell hope the id and created columns aren’t changing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*SFNRs7Lg6fyWxLw-ZcDGSQ.png" /><figcaption>We only trigger on update of title and story columns</figcaption></figure><p>Optionally, inspect/verify the SQL tab to see what will be generated.</p><p>Finally — test things out. Play around with the story data as before, noting that the edited tab should update automatically if and only if the story and/or title columns change values.</p><blockquote><strong>NOTE: </strong>While verifying your trigger function, if you hit ‘save’ and notice the edited column didn’t change, that’s because you need to then re-fetch the data using the ‘execute/refresh’ button (lightning symbol).</blockquote><h3>Exporting Remote Database for Local Development</h3><p>We’ve done a lot.</p><ul><li>Created a remote Heroku Postgres database</li><li>Configured a connection to the remote database in pgAdmin</li><li>Added a users and stories tables</li><li>Configured constraints (unique user.name and foreign key stories.author)</li><li>Added a trigger function (update()) and a trigger event</li></ul><p>Finally, let’s discuss how to clone this environment locally and setup ways to do this easily in the future. Lastly, we’ll look at how to recreate the database for CI testing purposes.</p><p>There are two steps to clone a database from heroku</p><ul><li>Create a dump file from the remote</li><li>Restore local database from a dump file</li></ul><p>Additionally, we’ll look at how to download a backup of our remote database</p><h4>Creating a Dump File</h4><p>One of the clients accompanying a download of postgres is pg_dump.</p><p>Running pg_dump --help, we see some useful options:</p><ul><li>--data-only — dump only the data, not the schema</li><li>--clean — clean db objects before recreating</li><li>--create — include commands to create database in dump</li><li>--no-owner — skip restoration of object ownership</li><li>--schema-only — dump only the schema, no data</li><li>--no-privileges — doesn’t grant owner privileges`</li><li>--if-exists — add IF EXISTS when dropping objects</li></ul><p>Furthermore, we’re given connection options:</p><ul><li>--dbname, --host, --port, --username</li></ul><p>Thus, we can actually use pg_dump with a combination of these options (and a few other handy ones) to create a local dump of a remote database.</p><p>For testing and development purposes and depending on the API, we most likely don’t want the data. The --schema-only option allows us to get the tables, constraints, trigger functions etc, but without any of the table data. Instead, development and testing seeds can be used to fill tables as necessary.</p><p>--no-owner and — no-privileges are a life saver in that they remove the ownership and grants from the username created by Heroku. Instead we can use an owner of our preference when we import the schema locally, such as postgres or runon. --clean is used to remove existing objects when creating from the dump file. Thus we don’t have to manually destroy a development database, tables will be cleaned and re-created.</p><p>Because there’s so much going on with all of these options, I elected to create a simple script. This is entirely cosmetic/optional:</p><blockquote><strong>Note:</strong> I add a newline for each pg_dump option just to improve readability. In the actual script, those are all in one line.</blockquote><pre>#!/bin/bash</pre><pre>echo -n &quot;dbname &gt; &quot;<br>read dbname</pre><pre>echo -n &quot;host &gt; &quot;<br>read host</pre><pre>echo -n &quot;port &gt; &quot;<br>read port</pre><pre>echo -n &quot;username &gt; &quot;<br>read username</pre><pre>echo -n &quot;create file with name &gt; &quot;<br>read filename</pre><pre>pg_dump <br>--dbname=$dbname<br>--host=$host<br>--port=$port<br>--username=$username<br>--file=$filename<br>--verbose<br>--clean<br>--no-owner<br>--schema-only<br>--no-privileges<br>--if-exists</pre><pre>echo &quot;done&quot;<br>exit 0</pre><p>Depending upon your setup, you can greatly simplify things by storing your credentials as environment variables. If like me you went the lazy route of just inputting the credentials for each access, do note that you don’t have to open your browser. There’s actually a nice way to access your credentials from the command line:</p><pre>heroku pg:credentials:url --app [name]</pre><p>If the above gives you any trouble, just verify that you’re logged in heroku login and that the app name you’re supplying matches the application you’ve created.</p><p>Another tip is that in most bash shells that I’ve ever worked with, you can simply highlight a line and ‘right-click’ to copy. Successive right clicks at an empty prompt will paste.</p><h4>Heroku Backups</h4><p>There is a built-in way to not only create a backup on the Heroku server, but download it. The reason I don’t use this method to generate a dump file, however, is that the API offers <strong>no</strong> control over options for pg_dump. Sometimes we might want to export only a specific schema, for example, pg_dump can dump specific schemas or tables.</p><p>However, it is quite clearly desirable to backup production data.</p><p>To create a backup, use:</p><pre>heroku pg:backups:capture --app [name]</pre><p>To download a backup, use:</p><pre>heroku pg:backups:download --app [name] --output [filename]</pre><p>I combined these into a script:</p><pre>#!/bin/bash</pre><pre>name=latest_backup.dump</pre><pre>if [[ $1 == &quot;&quot; ]]; then<br> echo &quot;requires app name&quot;<br> exit 1<br>fi</pre><pre>if [[ $2 != &quot;&quot; ]]; then<br> name=$2<br>fi</pre><pre>name=&quot;.data/backups/$name&quot;</pre><pre>echo -e &quot;creating heroku backup for app $1 called $name \n\n&quot;</pre><pre>heroku pg:backups:capture --app $1<br>heroku pg:backups:download --app $1 --output $name</pre><pre>echo &quot;done&quot;<br>exit 0</pre><h4>Restoring A Database from a Dump File</h4><p>There’s a postgres client that does the inverse operation of pg_dump called pg_restore.</p><p>However, if you take a look at the dump that was created earlier from running pg_dump with those exact options, it’s actually a plain-text SQL file. Since this is the case, we actually use psql.</p><p>Again, let’s examine the command line options:</p><ul><li>--file=FILENAME — the dump file</li><li>--echo-all — echo all SQL commands executed</li><li>--echo-errors — echo any errors encountered</li><li>--dbname, --host, --port, --username</li></ul><p>So, in a very similar manner, let’s create a script that produces a development database using psql from a dump file.</p><pre>#!/bin/bash</pre><pre>dbname=runon_dev<br>username=postgres<br>port=5432<br>host=localhost</pre><pre>if [[ $1 == &quot;&quot; ]]; then<br> echo &quot;provide path to dump file&quot;<br> exit 1<br>fi</pre><pre>echo -e &quot;Restoring database from $1 \n\n&quot;</pre><pre>psql<br>--dbname=$dbname<br>--file=$1<br>--echo-all<br>--echo-errors<br>--host=$host<br>--port=$port<br>--username=$username</pre><pre>echo &quot;done&quot;<br>exit 0</pre><blockquote><strong>Note:</strong> You need to run createdb or use PgAdmin for the first time, just to create the local database. Optionally you can run dropdb and createdb after each restore, it’s entirely up to you.</blockquote><h3>Creating Database in Travis Tests</h3><p>In the previous section, I was adding dumps and backups to a directory .data from root. This directory is ignored from source control.</p><p>However, we’re going to want to source control specific dumps that can be used for Travis testing.</p><p>From root:</p><pre>mkdir sql</pre><p>Now run (from root):</p><pre>./scripts/createdump</pre><p>supplying a filename of sql/create-tables.sql</p><p>Then, in .travis.yml add to the existing before_script and just call this file with psql:</p><pre>before_script:<br>  - psql ...<br>  - psql ...<br>  - psql --dbname=$DB_NAME --file=sql/create-tables.sql</pre><h3>Wrap Up</h3><p>Working with multiple databases both remotely and locally presents a challenge. This article demonstrated a workflow using postgres databases both remotely via Heroku and locally. A connection with pgAdmin was used to create and modify the remote database. Tables, constraints, triggers and trigger functions were all examined. Dump files and psql were used to generate local and testing databases for continuous integration.</p><p>The code for the entire project is available on Github:</p><p><a href="https://github.com/vapurrmaid/run__on">vapurrmaid/run__on</a></p><p>The code <strong>specific to just this article</strong> is found in a pull request:</p><p><a href="https://github.com/vapurrmaid/run__on/pull/2">Add Postgres by vapurrmaid · Pull Request #2 · vapurrmaid/run__on</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90d9499ed8fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are There Video Games That Can Actually Be ‘Play’ed?]]></title>
            <link>https://medium.com/@vapurrmaid/are-there-video-games-that-can-actually-be-played-97263699d6b8?source=rss-450bddce104c------2</link>
            <guid isPermaLink="false">https://medium.com/p/97263699d6b8</guid>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[virtual-reality]]></category>
            <category><![CDATA[play]]></category>
            <category><![CDATA[psychology]]></category>
            <dc:creator><![CDATA[Gregory ‘Grey’ Barkans]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 01:27:20 GMT</pubDate>
            <atom:updated>2018-08-24T01:47:43.336Z</atom:updated>
            <content:encoded><![CDATA[<h4>The Importance of Simplifying Games to be ‘Play’able</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SzH7Tuc5SLrp1CT2" /><figcaption>Photo by <a href="https://unsplash.com/@taylorjamesphotos?utm_source=medium&amp;utm_medium=referral">Taylor Harding</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the fascinating things in the modern age of gaming is how sophisticated all of the game data is becoming. Online play, massive worlds, leader boards, statistics, achievements, objectives, levels, quests and more.</p><p>Without a doubt, data-centric models and internet connectivity enrich the gaming experience through many realms. There are greater possibilities, more thorough/fine-tuned experiences and greater competition.</p><p>Yet, there is a shadow of obsessiveness that accompanies such models.</p><p>Have you ever felt that after a certain point during a run of Skyrim, Fallout or similar quest-based games, the experience was ruined by an underlying urge to do everything in a precise, systematic manner?</p><p>In quest-based games I spend an endless amount of time organizing all of the items I find throughout the world, placing them in special containers. With Fallout 4’s ability to customize settlements, I get distracted trying to cope with how to reason about things correctly. It’s not that I’m an artist spending hours making a wonderful creation. Rather, it’s that I can’t cope with the ambiguity and enormous number of options to make a “proper” (read optimal) settlement.</p><p>When I venture out questing I get distracted from the story. Instead, my focus tunes in on collecting, often making various fast travels to place items in their proper containers mid-quest. Often, I forget the reason I’m on the quest. Rarely do I witness the intended story cues or even incoming enemies, as I’m usually distracted searching bodies or nearby containers.</p><p>I need to find everything. <br>I need to bring order to chaos.<br>I need to do things ‘properly’.</p><p>Whenever a ‘rare’ item is found that would without a doubt help me advance, I get too scared to use it and just let it sit in inventory for the entirety of the game. Never is it “the right time” to use the item. Never.</p><p>In Dark Souls, I have to get my stats to certain levels, find certain items and craft all possible soul-based items. I have to run through events in an exact order. I spend countless hours farming, planning and ultimately worrying. There are times that I yearn to play as another class or more freely, but I can’t because it’s not optimal.</p><p>In Halo, I was so concerned about my online stats — that someone was literally watching my gamertag, making fun of every change to my kill/death ratio and rank — that I got angry playing with friends who I thought would put me at a disadvantage. I’d pressure them to win and do better, removing any element of ‘fun’.</p><p>MMR became the obsession for HotS and League. Initially both games were meant to be played with partner(s) and friends, but things turned into grudges and group divisions based off of MMR and rank.</p><p>When I played Hearthstone, I’d get sweaty with anxiety before queuing into ranked matches, sometimes even getting into a panicked bout of breathing.</p><p>With Xbox Live, I get mad at myself when others have more gamer points or achievements in certain games and get frustrated spending countless hours hunting rare achievements just to appease non-existent onlookers.</p><p>I spend so much time organizing, collecting, hoarding, planning, redoing challenges and ultimately lamenting, that I never actually <strong><em>play</em></strong>.</p><blockquote>Full disclosure, I am on the spectrum and thus am more likely to exhibit such patterns and behaviours. But I also objectively think that too many games are too data-centric and competitive, distracting from the elements of ‘play’.</blockquote><p>But what are the elements of ‘play’?</p><h3>A Quick Word On Play</h3><p>In an intriguing TED talk, professor Stuart Brown discusses the importance of play. He outlines how in the study of mass murderer Charles Whitman, the element of play was a factor that shaped psychopathic behaviour.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.ted.com%2Ftalks%2Fstuart_brown_says_play_is_more_than_fun_it_s_vital&amp;url=https%3A%2F%2Fwww.ted.com%2Ftalks%2Fstuart_brown_says_play_is_more_than_fun_it_s_vital&amp;image=https%3A%2F%2Fpi.tedcdn.com%2Fr%2Ftalkstar-photos.s3.amazonaws.com%2Fuploads%2Fe296f49a-2e04-427a-913d-ee7f1bc069b5%2FStuartBrown_2008P-embed.jpg%3Fh%3D421%26w%3D560&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=ted" width="560" height="421" frameborder="0" scrolling="no"><a href="https://medium.com/media/d00ca2f6ac962677399a987cfac53f35/href">https://medium.com/media/d00ca2f6ac962677399a987cfac53f35/href</a></iframe><blockquote>And our committee, which consisted of a lot of hard scientists, did feel at the end of that study that the absence of play and a progressive suppression of developmentally normal play led him to be more vulnerable to the tragedy that he perpetrated. And that finding has stood the test of time</blockquote><p>Later, he asserts that a lack of play is by definition <strong>depression</strong>.</p><blockquote>…the opposite of play is not work, it’s depression. And I think if you think about life without play — no humor, no flirtation, no movies, no games, no fantasy… The basis of human trust is established through play signals. And we begin to lose those signals, culturally and otherwise, as adults. That’s a shame. I think we’ve got a lot of learning to do.</blockquote><p>Thus, play is quite clearly important for brain function and socializing, but what defines play? How does it look? Aren’t we “playing” video games?</p><p>Not all play looks the same. Stuart outlines a few elements:</p><ul><li>Physical play — bodily movement. Spontaneous. Dancing.</li><li>Object Manipulation — for example tinkering with electronics or Lego</li></ul><blockquote>The human hand, in manipulation of objects, is the hand in search of a brain; the brain is in search of a hand; and play is the medium by which those two are linked in the best way.</blockquote><ul><li>Rough and Tumble play — play fighting, like one might have done as a child or with a pet</li><li>Spectator play, ritual play — when watching a sports team in the championship, spectators and players can be seen as in this unified, immersive state of play</li><li>Imaginative play — crafting narratives and stories</li></ul><blockquote>We all have an internal narrative that’s our own inner story. The unit of intelligibility of most of our brains is the story.</blockquote><p>In addition, he outlines that play involves curiosity and exploration, but <strong>does so in a safe space</strong> for exploration.</p><h3>Can Video Games Be ‘Play’ed ?</h3><p>The games that aren’t massive worlds or competitive among players tend to have either open or competitive environments. For example, consider Cuphead or Life Is Strange.</p><p>Cuphead has one of the most outrageous difficulty curves I’ve ever encountered. After the first boss or two, you’ll find yourself dying 20+ times in a row and cursing at yourself. Furthermore, your performance after each fight is graded. Ultimately, this doesn’t feel like ‘play’ but rather a challenge.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZWOAb-IEvcE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZWOAb-IEvcE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZWOAb-IEvcE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/31926a5fec142f1492560b041bd1f455/href">https://medium.com/media/31926a5fec142f1492560b041bd1f455/href</a></iframe><p>Although Life Is Strange is without a doubt one of the more manageable games, it still has a sort of openness to it, with side focuses:</p><ul><li>collecting ‘rare’ photographs</li><li>multiple side-actions that have tertiary effects on the story</li></ul><p>There’s also not an adequate number of chances to shape the story or the outcomes in a safe way. In fact, the game is quite traumatizing:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2vZQNYyUmGo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2vZQNYyUmGo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2vZQNYyUmGo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/823ae713785e63a85934f8f83964ee49/href">https://medium.com/media/823ae713785e63a85934f8f83964ee49/href</a></iframe><p>Whether it’s levels, difficulty, tasks for achievements or so-called “side-quests”, it seems like even the less data-centric of the top gaming titles cannot simply “be played”.</p><p>Thus I’m led to ask, what would a game that could just “be played” look like? Would it be fun? Would it defeat the psychology that draws us to gaming in the first place, rendering nothing but digital boredom? Is it <em>possible?</em></p><p>As a thought exercise, imagine the following:</p><ul><li>neither excessively ‘leveled’ nor excessively ‘open’</li><li>either infinte ammo/inventory items or an extremely ephemeral inventory that changes without forming attachment</li><li>options are aesthetic/stylistic, personal preference and have little-to-no overall impact on gameplay/story/performance</li><li>difficulty is either modular or auto-adjusts and has no statistical meaning</li><li>limited or preferably no achievements, quests, scoreboards, leaderboards or competition modes</li><li>no collecting or organizing or storing in-game objects</li><li>either immersive story or limited story</li><li>Ability to create/explore, but without so many in-game options that things are overwhelming</li><li>Any social aspects are inherently safe and non-competitive, rather they facilitate play-like behaviour</li></ul><p>What do you imagine?</p><p>Most importantly, is it <strong><em>play</em></strong>able?</p><p>For one, we note that there is great potential, especially with emerging VR and graphics to use dance and body movement based games for play. But they need to be stripped of scoring, leader boards and achivements etc. They also need to allow more creative aspects, as opposed to learning a pre-determined mapping.</p><p>But what’s more challenging is to imagine video games that can be <strong><em>play</em></strong>ed through pure object manipulation. Perhaps the closest we’ve come to date is Minecraft, and it’s worth noting just how popular it is.</p><p>In a progressively digital world whereby gaming is considered a ubiquitous fun and social activity, we need to focus on how to create games that facilitate the true elements of play.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97263699d6b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>