Live data from Hacker News

Just Say No to JavaScript

infoworld.com

51–60 of 86 posts

Re: Just Say No to JavaScript

#51
post #21
post #11

Earlier quoted context omitted.

>catches a mistake you'd have missed or your IDE out you used the wrong type. Do people really have this issue? My errors are never type related and when they are the console tells me immediately and the exactly line to fix. What I need is a StupidScript to save me from the stupidity of my logic errors… Like for example I’m working on a custom game engine for a web game I’m making, I’m having issues with the rewards…

> the console tells me immediately and the exactly line to fix. Uh, yeah, that's a runtime error. Type safety tells you the error before you even hit save, let alone run and test. It's a wildly faster loop.

I'm still going to run it every change and those errors are rare and quick to fix.

Re: Just Say No to JavaScript

#52
post #16

Earlier quoted context omitted.

> The author never actually says what is so wrong with JavaScript The lack of explicit typing. The author argues against untyped code, and for using typescript instead of javascript to get types.

> The lack of explicit typing. The JIT seems to figure it out just fine. Otherwise typeless programming is just a particular style and it's not particularly complicated just different. I've never understood this rationale in a language that does not have pointers.

JS ist not typeless. In fact dynamic languages allow you to use very complex types that are not even possible to express in most static type systems. That is why TS needed to have such an advanced and complex type system to catch at least most of it's power.

You are right that dynamic typing is a valid style though and offers some great advantages but also disadvantages. That is why most dynamic languages have added gradual typing support to have the best of both worlds. The real issue is the weak typing in JS which is an design mistake in retrospect.

Re: Just Say No to JavaScript

#53
post #11

Earlier quoted context omitted.

>catches a mistake you'd have missed or your IDE out you used the wrong type. Do people really have this issue? My errors are never type related and when they are the console tells me immediately and the exactly line to fix. What I need is a StupidScript to save me from the stupidity of my logic errors… Like for example I’m working on a custom game engine for a web game I’m making, I’m having issues with the rewards…

At that point sir you would have no job. Your job is logic safety

That's why I test the code and solve the logical issues? The joke was that the language would be smart enough to catch the less obvious stupid mistakes instead of obvious to solve type bugs.

Re: Just Say No to JavaScript

#55
post #11

Earlier quoted context omitted.

>catches a mistake you'd have missed or your IDE out you used the wrong type. Do people really have this issue? My errors are never type related and when they are the console tells me immediately and the exactly line to fix. What I need is a StupidScript to save me from the stupidity of my logic errors… Like for example I’m working on a custom game engine for a web game I’m making, I’m having issues with the rewards…

> Do people really have this issue? Yes. The point is that without type-safety and a compile-time type check, you have absolutely no way of knowing if you have an error like this until you hit that piece of code. The very fact that you think you don't have those kinds of issues just exemplifies how you actually are just ignorant to all the type errors you have in your code because you haven't tested enough, hit the r…

I have bunch of code/programs that have been running live on prod for years that are super stable with no errors that have been reported but what do I know?

Re: Just Say No to JavaScript

#56

This kind of rant, culminating in a hackneyed "created in a week" insult, usually comes from backend developers who jumped into frontend work thinking it was a silly little thing that could be mastered in under an hour, discovered that it was a whole separate field, and still failed to adjust their priors. This time it comes from a "former Delphi product manager" turned clickbait writer. I just hope that my visit wit…

Finally, an accurate take on FE! Well said!

Re: Just Say No to JavaScript

#57

I don't get the "type checking is the solution for the problems of the world". A lot of good things were/are written without type checking. Most of the problems I see in production have nothing to do with the wrong type being used or some forgotten required parameter. Also, typescript is just javascript with a mustache. It's the same thing

> Most of the problems I see in production have nothing to do with the wrong type being used

I think this depends on how you use the type system in your code. If you're just passing around strings and numbers, then sure. But if you're making explicit types for all the entities your program processes, and if you're structuring them in a way that means you don't have a bunch of undefined fields in the normal case (e.g. by using tagged unions a lot), then Typescript is absolutely, objectively, transformative compared to Javascript.

Re: Just Say No to JavaScript

#58
post #16

Earlier quoted context omitted.

> The author never actually says what is so wrong with JavaScript The lack of explicit typing. The author argues against untyped code, and for using typescript instead of javascript to get types.

> The lack of explicit typing. The JIT seems to figure it out just fine. Otherwise typeless programming is just a particular style and it's not particularly complicated just different. I've never understood this rationale in a language that does not have pointers.

I was not arguing for explicit typing myself in the previous comment (I was just the messenger).

But now I'm going to. For context, I write code in both explicitly typed and not explicitly typed languages (mostly JS).

> The JIT seems to figure it out just fine.

And the CPU will figure out binary code just fine. But you won't. You can, but not easily. You are writing for the computer, but also in a way that you (and your peers, if applicable) will be able to work with the code: extend it, fix it, maintain it, make it evolve. "The runtime figures it out" is hardly an argument for the dev UX.

Explicit typing is one way among other things to document the code, and this is documentation that's automatically checked by the tooling, which is nice. Types are documentation that can't rot. I'd say, good to take.

"The JIT doesn't need this to figure out the types" also applies to documentation by the way. The runtime, however, doesn't need to understand the code, just to run it. But you need to understand the code when working on it.

Types can help you figure out what functions you can call on any particular variable, without having to have something similar to a complete stack trace in your mind to know which type is a variable.

Sometimes, you can't even have the complete stack trace, for example when you are working on a library called by user code, or when you are calling some black box library code from user code. It's nice having types that are automatically checked at the interfaces so you don't have to figure it out (which you may need to do by running the related code, noticing the return types and hoping for the best). Even if you are dealing only with code that you have access to, it's nice not to have to go read all the code of the other side each type.

Explicit types just make it easier and faster to understand code, and also to modify it. Without types, you need to "recompute" the type of anything you are dealing with, risking calling the wrong method if you do a mistake at this step. Of course, if you have solid testing in place, you will probably catch it, but with explicit typing, that's a mistake you can't do: it'll be in red in your editor, or an error at the type checking step, winning some time.

Explicit types lets you avoid having to re-figure out again and again types of things, and that's cognitive burden that's freed to give more room to focus on what the code actually does. They also help your IDE help you if you use one (or something like LSP).

if you are dealing with small pieces of code, it doesn't matter much: everything can be kept in your head anyway. For such code, explicit typing can be just noise. But for bigger code, types are a relief.

For me, a nice balance is explicit typing at the interfaces (function parameters and return types), and implicit typing inside the function body.

All in all, I think explicit types make me faster for anything more than a trivial amount of lines of code. So I have a strong case for explicit typing. But I don't have much for non explicit typing.

The only reason I can choose to write vanilla JS despite this is because Typescript more or less requires opening the NPM can of worms. Would browsers allow type annotation in JS, I would totally use them and have some type checking pass somewhere to enforce correctness.

Re: Just Say No to JavaScript

#59
post #36

How disappointing. It is not at all "say no to JS". It's "use my preferred flavour of JS instead." I want to return to the pre-JS internet and especially the pre-JS Web. Say no to Javascript at all in any variant. Also say no to PHP. Nothing of lasting value to humanity would be lost if both of them went away completely, forever.

Hi Liam, What about dynamic websites? For example, a platform-independent chat app. Javascript has a place, although that place would be better filled by another language. PHP... yes, PHP can be completely replaced by other server side frameworks.

> What about dynamic websites?

An exact example of the kind of thing I'd like to get rid of.

The UK PC vendor Elonex had the first ever webmail system I saw, called HTMail. It was impressive but it was a private in-house tool to give remote workers email access without needing their own machine with an email client. Wrong sales model.

It the was followed by the indie HoTMaiL, based on NetBSD servers I think, which had the right model: a free public standalone service, paid for with ads. Of course MS bought it and ruined it.

Webmail doesn't need Javascript and worked with pre-JS browsers and servers.

> For example, a platform-independent chat app.

Good. Let's eliminate them, too. They are bloated slow things that allow companies to hijack their own commercial clients' data.

Stick to standard protocols, extend them if necessary -- XMPP 2, Matrix, whatever -- and document and publish the protocols. Make it possible for 3rd party client apps to connect. Pidgin was great and it takes about 1% of the RAM of a bare handful of these crappy Electron efforts like Slack.

What you are citing as reasons to keep it are the reasons I want to see it dead.

Re: Just Say No to JavaScript

#60
post #3

This is a plea to use TypeScript instead of JS. Why not. Strong typing is certainly great. But the reason I don't use TypeScript isn't any of those listed: it's because it needs a compilation step, and I don't want that.

Do look into jsdoc typing and "//@ts-check".

I do agree with you on the compilation, and this is the reason I'm still writing the occasional .js or .mjs file. However, the js I write starts with enabling ts-check and has all of its type information encoded as comment. This way, I'm getting the benefits of typescript while writing the code without needing the whole compilation step.

Post reply on HN