what are some other tutorials for implementing a toy version of a hard thing in a short amount of time? Like https://implement-dns.wizardzines.com or https://raytracing.github.io

I’m especially interested in the “in a short amount of time” aspect, I think nand2tetris is extremely cool but you definitely can’t do it in 3 days.

If possible I'd love to hear about a project you personally did and how long it took you.

Implement DNS in a weekend

of course “500 lines or less” has lots of examples https://aosabook.org/en/
The Architecture of Open Source Applications

@b0rk
This is a great resource!

Reminds me of a class I'm taking, where we are building a programming language. The Selene language from that class is less than 500 lines, but it takes eight weeks of class time to replicate it.
https://github.com/classpert/bapl2-class-language/blob/master/lesson-8/interpreter.lua

As the aphorisms go, brevity can be more time consuming. https://news.ycombinator.com/item?id=770109

bapl2-class-language/interpreter.lua at master · classpert/bapl2-class-language

Code for the Selene language developed during Classpert's Building a Programming Language course (cohort 2) - bapl2-class-language/interpreter.lua at master · classpert/bapl2-class-language

GitHub
@Aradayn Yeah, I've been thinking a lot about how "500 lines of code" isn't necessarily short in terms of the time it takes to understand it.
@b0rk @Aradayn You can spend a lifetime analyzing a sonnet…
@b0rk I believe this is where @gvwilson comes in.
@mhoye @b0rk Hey, I just do what she does, only slower.

@b0rk I’ve been following a “write Doom using Python” series, and it’s shocking. Those videos and you could have a passable Doom renderer, reading from WAD, in an afternoon or two. It’s a really great series, going step by step. (2.5d helps a bit.)

https://youtu.be/XV-cSvFM3ak

It’s almost like “anyone can write a ray-tracer/caster teapot/sphere/plane demo” (fun challenge: write one in PostScript) but a game feels more… tangibly “useful”? (Edit: practical?)

Recreating DOOM in Python. Ep1 - WAD DATA

YouTube

@b0rk Here's a tutorial for implementing a toy disassembler in at most a few hours:

https://briancallahan.net/blog/20210407.html

It's actually the first in a series of posts on demystifying programs that create programs. It further teaches how to code an assembler and linker, which may be weekend projects.

Brian Robert Callahan

@b0rk I teach my students IoT electronics in CircuitPython. Raspberry Pi Pico W are $7, you can link in Adafruit IO, and so fun things like animate lights, move servos, move a crude robot. Here are some links. https://bit.ly/pico-tutorials. Not sure if that fits your criteria but the students who start with no prior code see this as magic. Good luck!
Raspberry Pi Pico / Pico W Tutorials

Used in Prof. John Gallaugher's Physical Computing Course for New-to-Engineering / Coding Undergraduates. For more information, see: https://gallaugher.com/p...

YouTube

@b0rk For a more personal example, with notes… I read HTTP: The Definitive Guide in a night (yes… I speed read) then the next day wrote a more functionally complete HTTP/1.1 server in pure Python than I was able to find in Python. (Mine did chunked requests and responses, not just responses.)

The protocol bits compile to 191 opcodes.
Hybridises async and threaded execution.
And survives C10K consuming ~11MB of RAM.

https://github.com/marrow-legacy/server.http/blob/develop/marrow/server/http/protocol.py

Benchmark: https://gist.github.com/amcgregor/707936 (13 years ago)

server.http/protocol.py at develop · marrow-legacy/server.http

A simple development HTTP/1.1 server for WSGI 1 and prototype WSGI 2 applications in both Python 2.x and 3.x. - server.http/protocol.py at develop · marrow-legacy/server.http

GitHub
@alice thanks, this is great -- I want to write an "implement HTTP” tutorial and I've been struggling a bit with figuring out which edge cases from the spec to cover. Definitely going to look through this.
@b0rk @alice A simple HTTP cache doesn't take long.

@b0rk You can see from mine that I’m handing off request processing (the WSGI API side of things) to a Futures thread pool. From the benchmark, you can then run multiple processes sharing the same listening socket to let the kernel itself distribute incoming connections between them. All communication happens asynchronously within the main thread of a given process.

HTTP: The Definitive Guide is an incredibly good resource. Chunked transfer, header trailers, and some TCP–specific quirks…

@michaell @b0rk I often use that, or my 1.9 million DRPC/second pure Python implementations as counter-examples to cries of “Python is slow”. I even micro-optimised these things.

Split? Partition?
Partition is WAY faster.

Uppercase or lowercase a mostly lower-case string?
Always faster the fewer characters require replacement; lowercase.

&c. https://gist.github.com/amcgregor/405354

Then there are the examples where Python is faster than C. My web server contains one. (But also malloc elimination, inlining…)

Python timeit benchmarking for realistic optimizations.

Python timeit benchmarking for realistic optimizations. - gist:405354

Gist

@alice @b0rk And then there are the new not-quite-ready-for-prime-time subinterpreters in 3.12:

“Snow's own initial experiments with subinterpreters significantly outperformed threading and multiprocessing. One example, a simple web service that performed some CPU-bound work, maxed out at 100 requests per second with threads, and 600 with multiprocessing. But with subinterpreters, it yielded 11,500 requests, and with little to no drop-off when scaled up from one client.”

@michaell

Sub-interpreters. 😐 I get 38,775 generations/second (Python 2.7) or 45,679 (Pypy) or 55,385 (CPython 3.8) without any additional magic. And yup, cinje (my template engine pseudo-DSL) is cross-compatible back to Python 2 without code modification. (Not like that matters any more, but it's demonstrative of a few points.)

That HTTP service C10K test, under Python 2.6, and with an overwhelming 10,000 concurrency, netted 6K r/sec again, like, 13 years ago. It'd be far faster today.

@b0rk

@alice @b0rk But you’re just talking about the HTTP plumbing, not the app or service that runs behind it. That’s where subinterpreters could make a big difference — especially if that app or service makes blocking calls.

@michaell

We can then agree to disagree.

I'm talking about baseline performance; it can only get slower from there. How you manage blocking activity is up to the application; I'm a fan of thread-based Futures pools for most long-duration activities; even just enqueueing e-mail deliveries. (Also used for long-duration HTTP requests for data acquisition and processing for scheduled ingest.)

Though admittedly, my dynamic scaling thread pool is FAR more efficient than the built-in.

@b0rk

@michaell

The HTTP service test is performing the full WSGI pipeline, using a thread pool within each primarily async process to execute the WSGI endpoint, if you look very closely. (And kernel-level socket sharing for pre-fork/multi-process.) Very hybrid. 😜

And the template performance is based on the "de-facto standard" "Bigtable" test, that is, rendering a 100-column, 1000-row HTML table.

Django renders 2/second.

Two.

Insert "come at me bro" Monster (muppet drummer) GIF here. 😝

@b0rk

@michaell The “template render” being an example blocking process you might perform on each of those requests. But by being faster than the HTTP processing machinery, it’s the plumbing that’s performance restrictive, not actually the blocking process.

@b0rk

@b0rk I love “The Super Tiny Compiler” project.

Learn how to implement a compiler in a few hours: https://github.com/jamiebuilds/the-super-tiny-compiler

GitHub - jamiebuilds/the-super-tiny-compiler: :snowman: Possibly the smallest compiler ever

:snowman: Possibly the smallest compiler ever. Contribute to jamiebuilds/the-super-tiny-compiler development by creating an account on GitHub.

GitHub
@yosh this looks awesome, thanks!
Writing a C Compiler, Part 1

This is the first post in a series on writing your own C compiler. Here are some reasons to write a compiler:

@b0rk I did a couple of “code offs” with my kid. He coded in Scratch. I used JavaScript (with a reactive library). Time limit one hour. We did snake and ping. Not “hard things”, but fun to make.

https://code-off-pong.netlify.app
https://code-off-snake.netlify.app

Pong

@ross I love implementing snake

@b0rk With all the AI hype lately, could you write a SLM (Small Language Model)?

I wrote a chatbot framework in around 120 lines of JS too. Perhaps there's something in that?

https://peekobot.github.io/peekobot

Again, maybe not the complexity your after, but might spawn other ideas.

Peekobot

@b0rk I know that @coulb has been doing audio processing in Rust. Might be some ideas there. Look up the latest episode of the No Plans To Merge podcast.
Crafting Interpreters

@lesley have you gone through any of those yourself? how long did they take you if so?
@lesley (I ask because crafting interpreters is 600 pages, which makes it really not seem like a weekend project)

@b0rk I did all of them. Yeah, "Crafting Interpreter" takes significantly longer, though "Ray Tracing in One Weekend" can also be a rabbit hole that takes a long time if you consider later books.

I think on average each project can take one or two months of spare time, though it depends on how much time you can spend on it (I can rarely reserve a whole weekend on one task)

@lesley thanks, that's very helpful

https://interpreterbook.com/

Maybe a bit too long?

Writing An Interpreter In Go

In this book we will create a programming language together. We'll start with 0 lines of code and end up with a fully working interpreter for the Monkey programming language.

@b0rk This might be the wrong layer compared to what you did, but: I'm surprisingly proud of the SNMP book catalog agent I wrote in one day (and polished the next morning).

It's Perl, and silly, and taught me a huge amount about how SNMP actually works. People actually use this sort of thing in production.

I left it up as an Easter egg for the book.

@b0rk It certainly pales in comparison to other guides, but you can complete my guide to raytracing in a few hours. I wrote it over the course of a week.

https://sidneys1.com/programming/2022/03/23/raytracing.html

Raytracing!

Since I started programming I’ve had a dream in the back of my mind: raytracers are super cool, and I’d like to build one myself. But with that dream accompanied another thought: raytracers are nearly a pure expression of math, a discipline I am poorly qualified for. However this winter I discovered a new programming community, OneLoneCoder, and its leader, javidx9. Watching the videos produced by javidx9 inspired me to take a leap of faith in myself and start this raytracing project. The result has been amazing to see unfold as I developed first a working prototype in C#, then in C++, and finally as I produced what hopefully is an easy to follow “tutorial” style Git repository. So, lets dive in!

Sidneys1.com
@b0rk https://viewsourcecode.org/snaptoken/kilo/
build your own editor in around 1000 lines of C without dependencies
Build Your Own Text Editor

@b0rk I'm not quite sure if this counts, because it's a "tutorial" only for people who are already familiar with parsing jargon and algorithms, and "hard" only because you have to discover and dig through the several kinda obscure papers that the details are scattered across...

But I wrote my Pint-sized Earley Parser article in two days and over the years a surprising number of people have found me and told me it was helpful: https://joshuagrams.github.io/pep/

A Pint-sized Earley Parser

@b0rk I’m reading the Antlr book by Terence Parr and it’s full of them. One example that comes to mind is a json parser in under 20loc. Though it’s all done using the antlr parser generator so not from scratch.

@b0rk Like a kernel in Rust?
https://os.phil-opp.com/

Just to clarify, not mine.

Writing an OS in Rust

This blog series creates a small operating system in the Rust programming language. Each post is a small tutorial and includes all needed code.

@b0rk @bert_hubert’s neural network blog post / guide! I don’t have the link on hand but I’m sure he does :)
Hello Deep Learning - Bert Hubert's writings

A from scratch GPU-free introduction to modern machine learning. Many tutorials exist already of course, but this one aims to really explain what is going on, from the ground up. Also, we’ll develop the demo until it is actually useful on real life data which you can supply yourself. Other documents start out from the (very impressive) PyTorch environment, or they attempt to math it up from first principles. Trying to understand deep learning via PyTorch is like trying to learn aerodynamics from flying an Airbus A380.

Bert Hubert's writings
@b0rk I really liked Peter Norvig's spell corrector: https://norvig.com/spell-correct.html
How to Write a Spelling Corrector

@b0rk During lockdown I had a lot of fun going through @shiffman 's "coding challenges" youtube library. Often exactly what you describe: a quick implementation of sometimes big concepts, although never low level & always with visuals (he uses p5js or Processing). More geared towards fun & creativity than rigour or algorithmic wizardry.
@b0rk "Software Design by Example" (in JavaScript) is free to read online at https://third-bit.com/sdxjs/, and I hope to have the Python version up for beta readers by August.
Software Design by Example

@b0rk What I'd _really_ like is not more examples, but a volume of commentary and critique. Pauline Kael and Siskel & Ebert helped two generations of actors, writers, and directors be better tomorrow by taking apart what had been created yesterday and explaining how things worked (or didn't). We definitely need more model implementations, but I think we also need people to analyze the ones we have so that we can make the next ones better.
This is one of my dissatisfactions with both software engineering and computing education: neither thinks that criticism in the sense of literary, music, or film criticism is something they should do or reward. Twenty years on, most books and courses on software architecture & software design still don't describe actual, specific systems in pedagogically-useful detail https://third-bit.com/sdxjs/introduction/#introduction-history
Software Design by Example: Introduction

and in answer to a DM: if I thought I was insightful enough to write it, I would have done it by now. I haven't been shy in the past about putting forward opinions in areas where I'm not an expert (e.g., http://teachtogether.tech/), but this one's beyond me.
Teaching Tech Together

@gvwilson I quite liked this deep dive into the Build Engine https://www.fabiensanglard.net/duke3d/build_engine_internals.php
Duke Nukem 3D: Build Engine Internals

Duke Nukem 3D: Build Engine Internals

@gvwilson Gosh, this is so daunting because there's so much noise and the signal takes great effort to generalize. It takes a lot of expertise to critique effectively. Devs and users often praise the design they know while criticizing others and maintainers yearn for a hypothetical second system that surely would be cleaner before encountering the messy constraints. The best lessons may be when informed teams make high-stakes decisions, but it's rare and often for hyper-localized reasons.
@jedbrown and yet it's considered _normal_ in design-intensive disciplines like architecture and industrial design. Their students are explicitly taught, over and over, how to analyze the work of their predecessors and peers, and given a rich intellectual vocabulary with which to do that. No idea how one would prove this claim, but I firmly believe this tradition makes those fields stronger and leads to better designs.
@gvwilson How much do you think this is related to the way software evolves, so much of the critique ends up in seemingly-arcane rationale for new APIs? Well resourced projects can get a long way with brittle bones and even the most elegant collapse without resources.
@jedbrown more than half of the contributors to the first two volumes of https://aosabook.org/ explained design by recapitulating history. One of the reasons I lost interest in design notations like UML is that none of them (that I know of) even try to capture this…
The Architecture of Open Source Applications

@gvwilson One could write a book (and teach a course) on "a brief history of the Rust standard library", putting design decisions in context of prior art (especially C and C++), discussing alternatives that were considered, and reflecting on impact. It's different from modularity of large applications, but the lessons could be more stand-alone and I think they generalize.