this post was submitted on 11 Sep 2023
29 points (79.6% liked)

Programming

17313 readers
102 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

On the current typescript / anti-typescript internet drama I saw someone mention javascript without a build step.

Do you think we're already there?

Last time I attempted it:

  • there were too many libraries I couldn't import
  • JSX (using babel) had a warning saying you shouldn't do it in the browser for production
  • there was some advice against not using a bundler, because several requests for different .js files is slower and bigger than a bundled package
you are viewing a single comment's thread
view the rest of the comments
[–] Rooki 29 points 1 year ago (4 children)

I dont get the third point. Its weirdly written.

Imagine not using typescript. The python community gaslighting the js community. Imagine a big project website, and all in plain js, + multiple devs. Thats is going to be a mess. Never going back from TS.

[–] [email protected] 6 points 1 year ago (2 children)

About the third point, the performance of your JavaScript code can be worse if it's broken down into several small files rather than a single, bundled file. When a browser encounters a script tag linking to an external JavaScript file, it makes an HTTP request to fetch that file. This process occurs for each separate file. Each HTTP request involves time for network latency, server processing, and data transfer.

I'm usually preferring typescript too, but this point got me curious. I'm guessing it wasn't an honest point, almost everywhere I look people are still using a build step, and I didn't notice any move in a different direction

[–] [email protected] 12 points 1 year ago* (last edited 1 year ago)

Http/1.0 would require serial connections, and the "multiple files bad" absolutely applies. Bundling and minification into a single JS file was common, even required - and I would consider that a build step. Otherwise you are dealing with all your code in a single massive file.

On http/1.1 browsers would open 6-8 concurrent connections to fetch files simultaneously. At this point, code splitting had benefits.

Most webservers now run http/2 which can fetch multiple files at the same time over the same connection. I believe it is "virtually unlimited" and the initial connection setup - which is often the largest performance hit - only happens once. At which point code splitting has such little impact on the transport layer, that it is more perfomant than transferring and loading all the code.

https://blog.vespa.ai/http2/ Has an more details as well as some load testing against http/1.0, http/1.1 and http/2

[–] YourAvgMortal 1 points 1 year ago

There is also a limit to the number of files the browser can download in parallel, so if many files have to be fetched, they have to wait until the previous downloads are finished. This slows down performance even more

[–] [email protected] 3 points 1 year ago

I think it’s a double negative: “against not using”

As in, use a bundler.

[–] MajorHavoc 2 points 1 year ago (2 children)

The python community gaslighting the js community.

As a Python developer, I am absolutely giving ya'all a hard time for your gross bolted-on JavaScript type solution. /s

I do this primarily because I find it cathartic while I work with our gross bolted-on Python type solution. /s (mostly sarcasm, some truth here)

I do this secondarily because I'm jealous that Typescript seems to be a good bit more mature than MyPy. (No sarcasm here. I really am jealous on this point.)

[–] Rooki 2 points 1 year ago

Yeah i programm a lot in python and typescript too. Even if i type something in python its still very weakly typed.

[–] [email protected] 2 points 1 year ago (1 children)

I recommend Pyright over Mypy if you don't mind it being owned by Microsoft. It has far fewer bugs, and if you do stumble on one, you don't have to fix it yourself because Microsoft's paid devs will fix it in a couple of working days (at least for the small bugs I've reported).

[–] MajorHavoc 1 points 1 year ago

Sweet. I'll check it out. Thanks.

[–] [email protected] 1 points 1 year ago (2 children)

If you want type safety and no build step you do like svelte did and use jsdoc instead. You can run the typescript type checker on those annotations so if you care about not having a build step you can still have type safety.

[–] Rooki 1 points 1 year ago (1 children)

its like js but with extra steps WHY NOT USING TS then?

[–] [email protected] 1 points 1 year ago (1 children)

That's litterally less step. It's just a comment above a function. How is that more steps?

I mean, don't get me wrong, I don't mind build step but this is objectively less steps.

[–] Rooki 1 points 1 year ago

In typescript you dont comment before there you see the variable name and that (should be enough) and the type is there...

[–] [email protected] 1 points 1 year ago (1 children)

That sounds like spending a lot of extra effort just to avoid a little up-front effort.

[–] [email protected] 1 points 1 year ago

How is it extra effort? It's just a comment instead of inline types. It's not like going from no types to types everywhere.