News for hackers. Stuff that matters.
Re:Modern Javascript: Everything you missed over the last 10... by Cyberdog on Saturday May 15, 2021 @01:29PM (#27167146)
So many people are bringing up TypeScript here as an example of how JavaScript isn't so bad. I kinda feel like that's cheating. Like saying eggs are absolutely delicious when baked into a cake - you're praising something after it has been turned into an entirely different product.

Maybe TypeScript is great, but I just don't like the idea of depending on transpilers to not suck when creating the final code, and also having to debug that transpiled code, and then the whole transpilation step in between the standard command-S-command-tab-command-R workflow (this is also why I never use SASS/LESS if I don't have to).

Once JS itself has strict typing and real classes, and enough time has passed that I can be assured 95% of people using five-year-old browsers will be able to use it, then we can talk about the wonders of JavaScript. Until then I don't get why anyone would use it (or anything that transpiles to it) when there are so many better alternatives for server-side development.

Let's not even get started with Electron.

Re:Modern Javascript: Everything you missed over the last 10... by Waterluvian on Saturday May 15, 2021 @01:56PM (#27167380)
People occasionally rely on compilers. I don't really see this as much different.

At the end of the day all I care about is if I build the products and solve the problems I'm hired to do. Beyond maintainability, the "engineering" stuff is a distraction we need to be careful not to obsess over.

Re:Modern Javascript: Everything you missed over the last 10... by lanstin on Saturday May 15, 2021 @02:13PM (#27167534)
Well yes. But as the problem solver, there is nothing better than when someone has a problem, and you have a solution ready at hand which came from lambda calculus or distributed systems tricks or some crazy shit from On Lisp. That is why they are paying you, not to cranks out good dutiful straightforward solutions but for clever ideas that are simple to implement and operate. The engineering is both awareness and skill in following processes to get great cheap and effective solutions. Otherwise you end up with 20 million lines of code and all the aesthetically sensitive people have have to leave the company.
Re:Modern Javascript: Everything you missed over the last 10... by Vinnl on Sunday May 16, 2021 @02:25AM (#27171647)
Given that people are usually already using Babel, TypeScript isn't really any different than running a linter is. There's no additional transpilation step if you write your code in TS, but you can also run TypeScript to have it warn you of potential errors.
Re:Modern Javascript: Everything you missed over the last 10... by osmarks on Saturday May 15, 2021 @01:43PM (#27167280)
Why is the transpilation step an issue? You can set it up to happen whenever the file is changed with most things.
Re:Modern Javascript: Everything you missed over the last 10... by cesarb on Saturday May 15, 2021 @03:45PM (#27168311)
Because it's no longer the same language. You're not programming in JavaScript, you're programming in TypeScript, which happens to be compiled to something JavaScript engines accept. All the praise towards TypeScript does not necessarily apply to JavaScript. It would be like praising Assembly while you're actually programming in C.
Re:Modern Javascript: Everything you missed over the last 10... by goodoldneon on Saturday May 15, 2021 @06:52PM (#27169704)
AFAIK, the only difference between TS and JS is types. TS doesn't give you anything that's functionally different than JS -- only types that are stripped during compilation. You can't perform any logic on types at all (e.g. you can't have conditional logic based on interfaces).

Comparing assembly/C to JS/TS doesn't make sense.

Re:Modern Javascript: Everything you missed over the last 10... by CRConrad on Sunday May 16, 2021 @05:15PM (#27177064)
Yeah, and the only difference between C and machine code is that C hasn't been compiled yet. The comparison makes perfect sense.
Re:Modern Javascript: Everything you missed over the last 10... by goodoldneon on Sunday May 16, 2021 @06:40PM (#27177750)
Writing TypeScript is like writing JavaScript but with type annotations. Writing C is not like writing assembly with type annotations.
Re:Modern Javascript: Everything you missed over the last 10... by CRConrad on Monday May 17, 2021 @01:31AM (#27180335)
> Writing TypeScript is like writing JavaScript but...

...but different.

> Writing C is not like writing assembly...

...it's different.

Re:Modern Javascript: Everything you missed over the last 10... by Cyberdog on Saturday May 15, 2021 @03:48PM (#27168342)
With most things, yes, if the implementation for that feature supports your operating system, and it doesn't take long enough to be noticeable, and there's no weird caching issues at any given level, then yes, it's transparent in that case.

Or you could just write the JS directly and be done with it.

Re:Modern Javascript: Everything you missed over the last 10... by mnahkies on Saturday May 15, 2021 @02:00PM (#27167414)
> I just don't like the idea of depending on transpilers to not suck when creating the final code

How does this differ from trusting a compiler or interpreter?

Every language has to be translated to machine code in some way.

Re:Modern Javascript: Everything you missed over the last 10... by Cyberdog on Saturday May 15, 2021 @03:52PM (#27168381)
> How does this differ from trusting a compiler or interpreter?

When was the last time you found a bug and it was the compiler or interpreter's fault?

At any rate, the big difference is debugging, as I mentioned above. How fun is it to debug code which you only kind of indirectly wrote?

Re:Modern Javascript: Everything you missed over the last 10... by mnahkies on Saturday May 15, 2021 @04:03PM (#27168482)
The code output by typescript is generally pretty readable depending on the target, and the source mapping works very well regardless. The debuggers in all major browsers and ides handle it fine.

I've not come across any bugs caused by typescript itself in the time I've been using it since 2014, and my point was that this is the same for c or any other language - how fun is it to debug assembly you only kind of wrote