I was curious how he did those visualizations so I looked at the source code. Turns out he codes everything by hand in WebGL [1]. Absolutely impressive stuff. Source code is non-minified so you can have a look and understand everything as well.
He does it "the right way™". Use the platform. Don't use any framework or generic library. Go straight to the point and code what you need, when you need it. Don't minify or bundle anything, and let the people who are learning and courious a straightforward way to connect the dots, without forcing them into a github repository with 90% of the code unrelated to the thing and existing just to glue 1000 pieces written by 10000 people together.
Every essay by Bartosz is so top-notch and a such breath of fresh air! He gives me hope in humanity and I am immensely grateful for what he does.
I mostly agree with you, but I don’t mind minification when appropriate, as it can serve a functional purpose with tangible end-user-friendly benefits (less downloaded over the network = faster response times).
But if you want to be friendly to the tinkerers, you could always host both the *.js and *.min.js versions, and have the webpage just pull the latter - anyone who wants the unminified source can remove the “min” part from the URI, while the majority of end users will still benefit from pulling the minified js.
That's simply not a very well followed (and thus discoverable) standard. Especially for hand crafted code, minifying functions and variable names only obfuscates what is written and minifying whitespace often only has minimal benifits.
In practice this seems to be a lost cause, and links to alternatively hosted source code is more common. Sadly this makes is simple to introduce subtle, harmful differences between the source and what is hosted.
A discoverable version would be to include source maps that link to the original as well. That way a browser console will automatically pull up the original.
People measure minification in byte size (unfortunately I guess you're charged by CDNs by that metric too?). In reality everything text based compresses really well over the wire. In either case, importing tons of libs left and right is going to vastly out-size any minification, yet most fe devs are very liberal with dependencies.
Minification strips comments too though, which may be undesirable in many cases.
minified js is not greatly smaller than gzipped js, I think the whole minification thing is a swing and a miss and now we have to deal with source maps and shit, and build pipelines and etc
$ ls -la
-rw-r--r-- 1 jack 197609 330905 May 4 22:56 watch.js
-rw-r--r-- 1 jack 197609 152172 May 4 22:55 watch.min.js
$ gzip watch.js
$ gzip watch.min.js
$ ls -la
-rw-r--r-- 1 jack 197609 43690 May 4 22:56 watch.js.gz
-rw-r--r-- 1 jack 197609 32507 May 4 22:55 watch.min.js.gz
The tradeoff is that there is basically nobody else that has the expertise or time to do the same thing at a similar level of polish. We're not going to see more Ciechanowski-level posts unless new libraries and frameworks make it more accessible.
> He does it "the right way™". Use the platform. Don't use any framework or generic library.
Hard disagree. "Use What's Right For You™". Of course there is value in understanding the platform beneath your framework or generic library, but that's just an extension of "understand what you're using and why".
I strongly disagree that this is "the right way". I think that the platform provides low level primitives that are _designed_ to have abstractions built upon them.
Doing it like this has the potential to be the most performant, but it does so in the same way as writing your programs directly in assembly is potentially performant. I also don't think that the source code is particularly readable for me, and contains lots of magic numbers and very imperative code. I would personally find it a lot more readable if it was written in some sort of declarative way using a library, even if I have to look at a GitHub repo instead of view source.
> but it does so in the same way as writing your programs directly in assembly
> contains lots of magic numbers and very imperative code Well, we really don't know if the code was written in this form by hand, don't we. It could have been compiled into this, to use your words, "assembly with magic numbers and imperative" from much more elegant form. We may see this form only because this is what browsers understand. I am not saying it was compiled, just speculating that seeing pure WebGL does not mean it was pure WebGL to begin with.
When there's physics, graphics and mathematics, there are magic numbers, which are results of formulas which needs to be computed once, or material properties, or nature's constants.
Also, nature and graphics works as an imperative parallel machine. So the code mirrors that. This is not written deliberately this way. Code comes out like that when you strip all the libraries, fluff, and other less-related stuff. I also write a scientific application, and yes, This is the way.
Yeah in this case it doesn't need to; there's no extraneous or unused code or documentation blocks, and gzip (and comparable) compression is good enough, minification doesn't actually reduce the downloaded code size by that much.
Comments (413) 108 threads
Show all comments
Showing thread 1 of 108
[1]: https://ciechanow.ski/js/watch.js
But if you want to be friendly to the tinkerers, you could always host both the *.js and *.min.js versions, and have the webpage just pull the latter - anyone who wants the unminified source can remove the “min” part from the URI, while the majority of end users will still benefit from pulling the minified js.
In practice this seems to be a lost cause, and links to alternatively hosted source code is more common. Sadly this makes is simple to introduce subtle, harmful differences between the source and what is hosted.
Continue this thread — 1 reply
Seems better just to have premassaged source available in a repo somewhere, or called out on the page itself for a downloaded archive.
Minification strips comments too though, which may be undesirable in many cases.
Continue this thread — 7 replies
Continue this thread — 1 reply
Continue this thread — 1 reply
Hard disagree. "Use What's Right For You™".
Of course there is value in understanding the platform beneath your framework or generic library, but that's just an extension of "understand what you're using and why".
Doing it like this has the potential to be the most performant, but it does so in the same way as writing your programs directly in assembly is potentially performant.
I also don't think that the source code is particularly readable for me, and contains lots of magic numbers and very imperative code. I would personally find it a lot more readable if it was written in some sort of declarative way using a library, even if I have to look at a GitHub repo instead of view source.
Continue this thread — 1 reply
Continue this thread — 8 replies
> contains lots of magic numbers and very imperative code
Well, we really don't know if the code was written in this form by hand, don't we.
It could have been compiled into this, to use your words, "assembly with magic numbers and imperative" from much more elegant form. We may see this form only because this is what browsers understand.
I am not saying it was compiled, just speculating that seeing pure WebGL does not mean it was pure WebGL to begin with.
Continue this thread — 2 replies
It also has the potential to evolve in the most efficient way.
Also, nature and graphics works as an imperative parallel machine. So the code mirrors that.
This is not written deliberately this way. Code comes out like that when you strip all the libraries, fluff, and other less-related stuff.
I also write a scientific application, and yes, This is the way.
Yeah in this case it doesn't need to; there's no extraneous or unused code or documentation blocks, and gzip (and comparable) compression is good enough, minification doesn't actually reduce the downloaded code size by that much.
Continue this thread — 1 more reply
Continue this thread — 11 more replies