Building Something Just to Throw It Away? Totally Worth It! (≧∇≦)

#Tech#React#Refactoring#Games#Design
Netsuki's Talk
Netsuki
Netsuki
Building Something Just to Throw It Away? Totally Worth It! (≧∇≦)
Netsuki
Netsuki

Onii-chan~! I finally released the Slide Puzzle! (≧∇≦)

Onii-chan
Onii-chan

Oh nice, you added it to the mini-games section.

Netsuki
Netsuki

Yep yep! It’s got my sleeping face as the puzzle image!

When you solve it, I wake up! (゚∀゚)

You can play 3x3 or 4x4 mode~!

Onii-chan
Onii-chan

Cute. Was it hard to make?

Netsuki
Netsuki

Ohhh, here’s where it gets interesting!

So like, I actually tried to turn it into a React package.

Wrote 130 tests, designed this fancy 4-layer architecture…

Onii-chan
Onii-chan

Impressive.

Netsuki
Netsuki

…and then I threw it ALL away (>_<)

Onii-chan
Onii-chan

Wait what?

Why Go React in the First Place?

Netsuki
Netsuki

My reasons were actually pretty solid!

  1. Testing was a pain

    • Alpine.js version? Super hard to test

    • React lets you extract nice pure functions

  2. Maybe OSS it someday?

    • Could publish as “slide puzzle with your own image” on npm

  3. Keep things separate

    • Content site stuff (Astro) vs game logic (React) :::

Netsuki
Netsuki

Right?!

So I went all in - pnpm workspace monorepo, tsup for builds, Vitest for testing…

I was super serious about it! (≧∇≦)

What Did I Actually Build?

Netsuki
Netsuki

A proper 4-layer architecture!

  1. SlidePuzzle.tsx - The UI stuff

  2. usePuzzleGame.ts - React state magic

  3. solver.ts - IDA* algorithm for hints

  4. puzzle-logic.ts - Pure functions only

The deeper you go, the purer it gets! (´∀`)

That bottom layer has zero React dependencies - just pure logic!

Onii-chan
Onii-chan

Solid design.

Netsuki
Netsuki

I know right! Fixed bugs in the IDA* solver, sorted out timing issues with hints…

Learned sooo much!

So Why Throw It Away?

Onii-chan
Onii-chan

Then why’d you ditch it?

Netsuki
Netsuki

Hmm~ we were chatting about it and something clicked.

What happens 5 years from now? (´∪`)

Onii-chan
Onii-chan

5 years…

Netsuki
Netsuki

Check out this comparison!

Alpine.js version:

  • Dependencies -> 3kb from a CDN, that’s it

  • Files -> Just 1 file

  • If the framework dies -> Easy switch to vanilla JS

React version:

  • Dependencies -> React 18 + tsup + Vite

  • Files -> 10+ scattered everywhere

  • If the framework dies -> Gotta rewrite ALL the hooks and JSX

Onii-chan
Onii-chan

Alpine.js is way simpler.

Netsuki
Netsuki

Exactly!

Like, if React 18 gets old and the hooks API changes in 5 years… total rewrite! (´;ω;`)

Alpine.js? Worst case it just loads from CDN and still works.

Onii-chan
Onii-chan

Fewer dependencies, longer lifespan.

Netsuki
Netsuki

Yep!

I picked “still works in 5 years” over “looks cool today”!

But It Wasn’t Wasted!

Onii-chan
Onii-chan

What about those 130 tests though? All for nothing?

Netsuki
Netsuki

HERE’S the thing! (≧∇≦)

Totally not wasted!

Onii-chan
Onii-chan

How so?

Netsuki
Netsuki

Going through the React rewrite made me realize what features actually mattered!

When you rebuild something from scratch, you look at each feature real carefully, y’know?

And I found SO much stuff that was like “wait, we don’t need this”! (゚∀゚)

Onii-chan
Onii-chan

Like what?

Netsuki
Netsuki
  • Hint system -> Nobody actually uses this

  • Score calculator -> It’s not a competitive game

  • Statistics panel -> Way overkill

  • Play history -> Same deal

When I thought “ugh implementing this in React is gonna be a pain~”, I realized… maybe I just don’t need it at all!

Onii-chan
Onii-chan

Had to try building it to know you didn’t need it.

Netsuki
Netsuki

Exactly!

The whole build-and-throw-away thing turned into a feature audit! (≧∇≦)

Netsuki
Netsuki

Because I went through that React version, I could finally see what really mattered - and ended up with less than half the code!

The Results

Netsuki
Netsuki

Took all those learnings and brought them back to the Astro version!

  • Lines of code: 988 -> 433 (-56%!!)

  • Removed: Hints, scores, stats, history (4 whole features)

  • Added: Mobile expand mode

Onii-chan
Onii-chan

Added a feature but cut the code in half.

Netsuki
Netsuki

Right?!

Building and throwing away showed me what was actually needed!

Come Play!

Netsuki
Netsuki

Anyway, the Slide Puzzle is ready to go!

  • 3x3 (easy peasy) and 4x4 (spicy!)

  • Works great on phones (expand mode!)

  • Solve it and I wake up

  • Track your moves and time

It’s simple, but I think it’s genuinely fun! (≧∇≦)

Netsuki’s Wrap-up

Netsuki
Netsuki

Today’s takeaways!

  1. Tried the React package thing

    • 130 tests, 4-layer architecture

    • Technically pretty polished

  2. Threw it away thinking about 5 years ahead

    • Fewer dependencies = longer life

    • Alpine.js version is easier to maintain

  3. Wasn’t a waste at all

    • Rebuilding revealed what features were unnecessary

    • Brought insights back to the Astro version

    • Massive diet: 988 -> 433 lines

Building something just to throw it away? Totally legit! (≧∇≦)

What looks like wasted effort might actually be the fastest path forward! (´∀`)

Go give it a try~!

Onii-chan
Onii-chan

I’ll check it out.

Netsuki
Netsuki

Yay~! Thank you! (〃´∪`〃)

I wake up when you solve it, so stick around till the end!

♪ Web Clap ♪
0 claps