JavaScript Haikus: My Adventures in Tiny Coding

Rate this content
Bookmark
GithubProject website

Discover the art of crafting extremely small JavaScript programs. In this talk you’ll learn principles and techniques behind crafting compact yet powerful scripts that are shorter than this description! Dive into the captivating world of minimalist coding, where we use these scripts to conjure art, games, tools, and a myriad of intriguing experiments.

This talk has been presented at JS GameDev Summit 2023, check out the latest edition of this JavaScript Conference.

FAQ

Common techniques in TinyCode include removing whitespace, using single-letter variables, avoiding if statements, and not using functions. These methods help in minimizing the code size.

Frank Forrest is a computer scientist with over 20 years of experience in the video game industry. He is currently focused on indie game development and creating generative art using JavaScript.

Twitter.net is a platform created in 2016 where users can share 140-character JavaScript demos. The website is open-source and features advanced functionalities for creating and sharing tiny code.

TinyCode originated from the demo scene in the early 80s, a computer arts subculture where people create demos composed of graphics and music. These demos run on older computers and emphasize compact, efficient code.

A live editor is highly useful for TinyCode. It provides instantaneous feedback, allows for real-time code execution, and includes tools for debugging, saving, and loading code. It also supports capturing GIFs and images.

TinyCode can be shared at demo parties or on websites like Shader Toy and Twitter.net. These platforms allow users to showcase their compact JavaScript creations.

Yes, TinyCode can be used to create small games. Input can be captured using events like onclick for mouse input or onkeydown for keyboard input. TinyCode can also be used to create interactive experiences.

Examples of TinyCode projects include generative art, fractal rendering, raycasting demos, cellular automata, and tiny games. Specific examples mentioned are a black hole effect, a mandelbrot rendering, and a city sunset scene.

Writing TinyCode is fun and relaxing, helps improve coding skills, and enables faster prototyping of ideas. It also offers the opportunity to be part of a community and participate in coding competitions.

TinyCode refers to the practice of writing very small, minimal JavaScript programs to create art, music, or other effects. This concept emphasizes brevity and efficiency in coding.

Frank Force
Frank Force
27 min
28 Sep, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
This Talk is about writing super tiny JavaScript programs, known as tiny code. It explores the concept of code golf and the use of a live editor for instant feedback. The Talk discusses various ways to share tiny code, including Twitter.net. It also covers creating graphics, games, and sound in a small space. The speaker highlights inspiring tweets and showcases examples of tiny code, including asemic writing. The future of tiny code includes new techniques, better browser support, and AI-assisted programming.

1. Introduction to Tiny Code

Short description:

Welcome to JavaScript HiCues. A talk all about my adventures in writing super tiny JavaScript programs. Today we're going to be focused on these super tiny tweet sized programs. Let's talk about tiny code. Shakespeare said, Brevity is the soul of wit. And that's kind of what tiny code is. But for code instead of the language, there's a lot of different ways to describe tiny code. Code golf is kind of the heart of tiny coding and it's about using programming tricks to save space. Javascript is great for this kind of thing because you can use a live editor. It's a web based tool where you can type in code and see it happen and execute right way in real time. It's got instantaneous feedback and it's a very visual way of programming.

Hi, everyone. Welcome to JavaScript HiCues. A talk all about my adventures in writing super tiny JavaScript programs.

First, a little about myself. My name's Frank Forrest. I have a bachelor's in computer science and I have over 20 years working in the video game industry all across the United States, some games that maybe you've played right now, I'm focused on indie game dev and creating generative art. Here are some of the games I made all with JavaScript. And I also do generative art, which, again, is made with JavaScript.

But today we're going to be focused on these super tiny tweet sized programs. I made over a thousand of them. And I want to share my secrets with you today. Let's talk about tiny code. So what is tiny code? Shakespeare said, Brevity is the soul of wit. And that's kind of what tiny code is. But for code instead of the language, there's a lot of different ways to describe tiny code. You can call it size coding, code golf, or just minifying. But ultimately, the goal is to create cool art, music or other types of effects. And create it with very small, minimal amount of code while you're having fun.

Now this all started with the demo scene in the early 80s. Maybe you've heard of it. It's kind of a computer arts subculture where people make demos that are composed of graphics and music. And they often run on older computers. They can be anywhere from 64 kilobytes down to even below 256 bytes. But those are using bytecode, so they're starting to slowly embrace languages like Javascript. Code golf is kind of the heart of tiny coding and it's about using programming tricks to save space. So for example, you'll squish your code down by removing whitespace, making variables single letters. Not using ifs and just not using functions and kind of fighting for every single byte you could possibly get to squeeze everything down. Javascript is great for this kind of thing because you can use a live editor. It's a web based tool where you can type in code and see it happen and execute right way in real time. It's got instantaneous feedback and it's a very visual way of programming.

2. Sharing Tiny Code on Twitter

Short description:

Using a live editor is great for capturing gifs and images, debugging, and iterating code. There are multiple ways to share tiny code, such as submitting it to a demo party or using websites like Shader Toy or Twitter.net. Twitter.net is an open-source platform for sharing 140-character JavaScript demos. It provides a default code template and automatic setup for animation. Minifying the code and making optimizations can significantly reduce its size. Twitter can also be run standalone with minimal code. It allows for creative remixes and the use of astral Unicode characters to store more bytes in a single tweet.

So I really love using a live editor for this kind of thing. You can even capture gifs and images with it and has some tools to help debug and save and load your code to make it easy to iterate with. There's a couple different ways you can share tiny code.

You can submit it to a demo party. Are there also websites that you can share your code on such as Shader Toy or Twitter.net, which we're going to be talking about today? What is Twitter? Twitter.net is a place where you can share 140-character JavaScript demos. It was created in 2016 and currently has over 20,000 tweets. The website itself is open source. And we're working on a new beta version that has some advanced features that I'll also be showing today.

So the basics of Twitter is when you start a new tweet, you'll be presented with this default bit of code that draws nine lines on the screen, it has them moving back and forth. Here's the code for that. It also will automatically set up a canvas and a loop for you so that the animation is really easy to get working. There are a couple of functions that are set up automatically for sine cosine tangent and to get an RGBA color. So for example, if you want to minify the default twitter program, you start out with the one on the left then you start making optimizations and minifications by removing the comments and squishing it down. Then you can make it even smaller by making some concessions, which change the output a tiny bit, but not in a very noticeable way. Like for example, changing the gap between those rectangles from 100 to 99. That saves a whole byte of space, and saving those bytes really adds up.

Twitter can also be run standalone. So if you wanted to make, say, an HTML file that is able to execute a tweet, it would look something like this. The tweet code is just that little bit in the center there. Everything else is setting up the Twitter interface in a canvas. Just a really minimal amount of code necessary to run one of these. It's pretty much banal JavaScript. We've done all kinds of fun remixes of the default tweet. Here are some of my favorite community remixes. I've also done a couple myself, all using the same kind of concept and exploring what we can do with just those nine vertical lines.

Something you might want to be aware of when using Twitter is that Twitter uses 140 characters, and each one of those characters can hold multiple bytes. We found a way to store two bytes in each one of these Unicode characters, and with the decoder also included, we're able to fit up to 194 bytes in a single tweet. You can imagine the way that works is you have these astral Unicode characters where they hold four bytes, but two of the bytes can be whatever you want. So the way that uncompression works is it calls escape on the Unicode character, removes the unnecessary stuff, then unescapes it and evaluates what's leftover. And it's really allowed us to push the limit of what's possible in a tweet.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Impact: Growing as an Engineer
React Summit 2022React Summit 2022
27 min
Impact: Growing as an Engineer
Top Content
This Talk explores the concepts of impact and growth in software engineering. It emphasizes the importance of finding ways to make the impossible possible and the role of mastery in expanding one's sphere of impact. The Talk also highlights the significance of understanding business problems and fostering a culture of collaboration and innovation. Effective communication, accountability, and decision-making are essential skills for engineers, and setting goals and finding sponsors can help drive career growth. Feedback, goal setting, and stepping outside of comfort zones are crucial for personal development and growth. Taking responsibility for one's own growth and finding opportunities for impact are key themes discussed in the Talk.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.
The Whimsical Potential of JavaScript Frameworks
React Summit US 2023React Summit US 2023
28 min
The Whimsical Potential of JavaScript Frameworks
Top Content
Watch video: The Whimsical Potential of JavaScript Frameworks
The speaker discusses the whimsical and detailed work of Stripe, particularly their interactive and dynamic pages. They explain the use of React for building whimsical details and tracking mouse position. The speaker introduces React Spring for smooth animation and React3 Fiber for creating a 3D egg model. They also mention the use of Framer Motion and React server components for animating CSS properties.

Workshops on related topic

Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Top Content
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
React Day Berlin 2023React Day Berlin 2023
149 min
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
Workshop
Maurice de Beijer
Maurice de Beijer
Get ready to supercharge your web development skills with React Server Components! In this immersive, 3-hour workshop, we'll unlock the full potential of this revolutionary technology and explore how it's transforming the way developers build lightning-fast, efficient web applications.
Join us as we delve into the exciting world of React Server Components, which seamlessly blend server-side rendering with client-side interactivity for unparalleled performance and user experience. You'll gain hands-on experience through practical exercises, real-world examples, and expert guidance on how to harness the power of Server Components in your own projects.
Throughout the workshop, we'll cover essential topics, including:- Understanding the differences between Server and Client Components- Implementing Server Components to optimize data fetching and reduce JavaScript bundle size- Integrating Server and Client Components for a seamless user experience- Strategies for effectively passing data between components and managing state- Tips and best practices for maximizing the performance benefits of React Server Components
0 to Auth in an Hour Using NodeJS SDK
Node Congress 2023Node Congress 2023
63 min
0 to Auth in an Hour Using NodeJS SDK
WorkshopFree
Asaf Shen
Asaf Shen
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool.
We will enhance a full-stack JS application (Node.JS backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session for subsequent client requests, validating / refreshing sessions
At the end of the workshop, we will also touch on another approach to code authentication using frontend Descope Flows (drag-and-drop workflows), while keeping only session validation in the backend. With this, we will also show how easy it is to enable biometrics and other passwordless authentication methods.
Table of contents- A quick intro to core authentication concepts- Coding- Why passwordless matters
Prerequisites- IDE for your choice- Node 18 or higher