News for hackers. Stuff that matters.
Re:Mechanical Watch by panzerboiler on Wednesday May 04, 2022 @12:44PM (#31262858)
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.
Re:Mechanical Watch by valtism on Wednesday May 04, 2022 @06:38PM (#31266785)
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.

Re:Mechanical Watch by ranit on Wednesday May 04, 2022 @09:38PM (#31268322)
> 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.

Re:Mechanical Watch by aiisjustanif on Thursday May 05, 2022 @10:53AM (#31274132)
Re:Mechanical Watch by tomc1985 on Thursday May 05, 2022 @12:01PM (#31275054)
Graphics code tends to be imperative and have lots of magic numbers. I suppose it's the math-intensive nature of it.

Personally I'm not a fan of the magic numbers either but as I study more and more of it, it's everywhere

Re:Mechanical Watch by bayindirh on Friday May 06, 2022 @11:50AM (#31286589)
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.

Re:Mechanical Watch by the_cat_kittles on Wednesday May 04, 2022 @09:34PM (#31268296)
it depends if you are doing something to get paid, or to last, or to be really good. only in the first case do i ever consider a heap of abstractions
Re:Mechanical Watch by kaba0 on Thursday May 05, 2022 @05:42AM (#31271361)
Abstraction is the only thing that makes any of our advancements possible. Not even the simplest of math theses could be proves without a “framework” of relevant lemmas, nor could you write even a single hello world without the layers upon layers of abstractions written carefully over the decades. Sure, there is also bad abstraction, but the problem is the bad part, not the concept itself.

Without abstractions you wouldn’t be able to read a text stored on a remote computer with accompanying style information displayed the same on both of our devices and with embedded 3D graphics doing the same thing on vastly differing devices be it a top of the line GPU or a simple low-end phone. Is it not abstraction?

Re:Mechanical Watch by jseban on Thursday May 05, 2022 @05:53AM (#31271418)
Well, if the abstractions were peer reviewed and put through the same rigour as mathematical proofs, that's a whole different topic.

The equivalent would be a mathematical services company, who created "free" abstraction packages that required you to rewrite all your math, away from the scientific community standards, to fit their abstractions, and who also made money on consulting and selling books. And the big benefit of it all, is really that they only abstracted away writing summaries of your papers, which is actually the easiest part that is quite irrelevant to your research.

Re:Mechanical Watch by kaba0 on Thursday May 05, 2022 @06:59AM (#31271791)
But it is not math - we only have empirical evidence and not even much from that.

Who is to tell whether the OSI model is ideal? It is more than likely not it, but we can’t measure these things up front, there is an insane cost associated with changing it, etc. Yet again, what is the alternative? We can’t manage complexity any other way, and essential complexity can’t be reduced.

Re:Mechanical Watch by the_only_law on Thursday May 05, 2022 @02:28PM (#31276883)
> Who is to tell whether the OSI model is ideal?

The current idea of the OSI model was also retrofitted from what it originally was.

Re:Mechanical Watch by mr_gibbins on Friday May 06, 2022 @06:54PM (#31290382)
Ooo, you're giving me LaTeX vibes!
Re:Mechanical Watch by the_cat_kittles on Thursday May 05, 2022 @11:50AM (#31274892)
i mostly mean the heap of stuff people often throw at problems. of course you cant do anything without abstractions. it helps to understand them better though.
Re:Mechanical Watch by noitpmeder on Thursday May 05, 2022 @04:45AM (#31271050)
This is so backwards.
Re:Mechanical Watch by the_cat_kittles on Thursday May 05, 2022 @11:51AM (#31274918)
it really depends on what your doing mate!
Re:Mechanical Watch by swayvil on Wednesday May 04, 2022 @07:36PM (#31267301)
On a scale of 1 to 10 how strongly are we talking here?
Re:Mechanical Watch by plebianRube on Wednesday May 04, 2022 @07:45PM (#31267400)
9.5 Your PR will be held up for at least a month with the back and forth.
Re:Mechanical Watch by jseban on Thursday May 05, 2022 @06:12AM (#31271516)
> has the potential to be the most performant

It also has the potential to evolve in the most efficient way.

Re:Mechanical Watch by 10000truths on Wednesday May 04, 2022 @12:55PM (#31262991)
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.

Re:Mechanical Watch by throwaway2214 on Wednesday May 04, 2022 @05:00PM (#31265803)
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
Re:Mechanical Watch by MrDOS on Wednesday May 04, 2022 @08:18PM (#31267707)
Of surprise to no one, Brotli does better on both:

    $ ls -l *.js
    -rw-r--r--  1 mrd  staff  330904  5 May 01:04 watch.js
    -rw-r--r--  1 mrd  staff  152172  5 May 01:10 watch.min.js
    $ brotli watch.js
    $ brotli watch.min.js
    $ ls -l *.br
    -rw-r--r--  1 mrd  staff  34461  5 May 01:04 watch.js.br
    -rw-r--r--  1 mrd  staff  27122  5 May 01:10 watch.min.js.br
If I were serving this content, and if my web server and all of my target browsers supported Brotli, I'd be somewhat more content to ship an un-minified + Brotli-compressed file than an un-minified + gzip'd one. I'm sure it's some rule of thumb stuck in my head from the Web 2.0 era, but a JavaScript payload in excess of 40KB crosses some warning line in my head. (Probably 40KB / ~4KB/s throughput on a good dial-up connection = 10s transfer time, about the longest you'd want to wait for even a pretty spiffy page to load.)
Re:Mechanical Watch by MrDOS on Thursday May 05, 2022 @11:23AM (#31274525)
> I'd be somewhat more content to ship an un-minified + Brotli-compressed file than an un-minified + gzip'd one.

Whoops, typo: I meant to say that I'd be somewhat more content to ship an un-minified + Brotli-compressed file than a minified + gzip'd one. That is, I'd be more happy to serve the 34.4KB watch.js.br than the 32.5KB watch.min.js.gz.

Re:Mechanical Watch by jseban on Thursday May 05, 2022 @04:37AM (#31271000)
> and now we have to deal with source maps and shit

Yeah minification is only really for obfuscation. The small and unpredictable difference is absolutely not worth the ridiculous complex "solution" of source maps. Just the fact that your debugger really doesn't work right, is a deal breaker in and itself, not to mention all the time spent configuring and fighting with webpack.

I don't think any form of "compilation" i.e. bundling, transpiling, minification etc is needed at all. Javascript can already dynamically load (additional) code files when needed, I don't understand why you need to bundle it in the first place.

I don't buy that the http request overheads are so big that it motivates all this complexity, and in the average case a user don't use every single page of the application anyway, so by bundling everything you are always serving "too much", compared to just dynamically loading additional code.

Re:Mechanical Watch by lifthrasiir on Thursday May 05, 2022 @07:04AM (#31271834)
Gzipped JS is generally much smaller than minified JS, but minified-then-gzipped JS is even more so. The minification (assuming gzip) doesn't make a much difference in this case only because the input file is not that large at all and compression algorithms have a natural bias for larger inputs. You can (rightly) claim it is bad to have a JS file large enough that the minification makes a difference after all, but you'd be moving a goalpost then.
Re:Mechanical Watch by selcuka on Wednesday May 04, 2022 @08:26PM (#31267778)
True, but it also removes the comments and the whitespace, leading to slightly better performance and memory usage. There are also less bytes to gzip on the server side.
Re:Mechanical Watch by Cthulhu_ on Thursday May 05, 2022 @04:20AM (#31270897)
Slightly, but is it enough to warrant the extra steps?

I don't think the difference is significant enough in this case.

That said, I do think there should be an alternative to minification+gzipping, like e.g. a compiled version of JS that is more optimized than a browser's own JIT compiler can do. Mind you, that might up being a larger package than the JS source code.

Re:Mechanical Watch by kaba0 on Thursday May 05, 2022 @05:44AM (#31271366)
Webassembly is* pretty much that

* hopefully will be

Re:Mechanical Watch by kevincox on Wednesday May 04, 2022 @02:12PM (#31263910)
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.
Re:Mechanical Watch by klabb3 on Wednesday May 04, 2022 @03:20PM (#31264685)
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.

Re:Mechanical Watch by operator-name on Wednesday May 04, 2022 @01:32PM (#31263462)
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.

Re:Mechanical Watch by NoSorryCannot on Wednesday May 04, 2022 @06:25PM (#31266655)
The pattern is extremely common on CDNs that serve JS.
Re:Mechanical Watch by monocasa on Wednesday May 04, 2022 @01:33PM (#31263475)
It's hard to guess that extra assets exist on the server if they aren't being pulled down by the site itself.

Seems better just to have premassaged source available in a repo somewhere, or called out on the page itself for a downloaded archive.

Re:Mechanical Watch by AceJohnny2 on Wednesday May 04, 2022 @06:37PM (#31266775)
> 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".

Re:Mechanical Watch by Liron on Wednesday May 04, 2022 @01:24PM (#31263369)
We need a ciechanow.ski explainer for how ciechanow.sky explainers are built
Re:Mechanical Watch by jhallenworld on Wednesday May 04, 2022 @03:03PM (#31264507)
Where are the comments in his code? :-)
Re:Mechanical Watch by WHA8m on Wednesday May 04, 2022 @01:33PM (#31263480)
He made this in the spirit of watch making. Super impressive and interesting website!
Re:Mechanical Watch by Cthulhu_ on Thursday May 05, 2022 @04:18AM (#31270882)
> Don't minify or bundle anything

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.

Re:Mechanical Watch by ivanhoe on Friday May 06, 2022 @04:18AM (#31282695)
the obvious downside is that it's a lot of work and takes a lot more time... so it might be "the right way™" for some cases, but it's definitely not a rule of thumb...
Re:Mechanical Watch by phailhaus on Wednesday May 04, 2022 @04:47PM (#31265655)
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.
Re:Mechanical Watch by Handytinge on Thursday May 05, 2022 @04:27AM (#31270939)
We definitely won't if people are taught that frameworks are the only option and never allowed to just write a full program on their own.
Re:Mechanical Watch by phailhaus on Thursday May 05, 2022 @10:28AM (#31273795)
Nobody stopping you from not using a framework, and yet there is basically nobody else at Ciechanowski's level. It's not going to happen, you can't expect everyone to become a hardcore webgl expert (have you tried?). If we want more cool interactive visualizations, we have to make it easier. Otherwise, we're stuck waiting for those with the time and expertise to pull it off.
Re:Mechanical Watch by javajosh on Wednesday May 04, 2022 @05:03PM (#31265823)
Maybe, maybe not. We should do the experiment, though.
Re:Mechanical Watch by phailhaus on Wednesday May 04, 2022 @06:04PM (#31266456)
What experiment do you mean?