Live data from Hacker News

Moving from TypeScript to Rust / WebAssembly

nicolodavis.com

371–380 of 428 posts

Re: Moving from TypeScript to Rust / WebAssembly

#371

Earlier quoted context omitted.

This really nails why languages like PHP and Ruby have won out over static typed, compiled ones for application level web development. The web is a massive collection of disjointed, loosely coupled APIs that all (just barely) interoperate to provide a massive array of functionality. Languages that tend to work well with it are those that are highly flexible around the corner cases of these technologies, and allow you…

I’ve worked on several large Ruby codebases, and the thing is, the same qualities that make it easy to get a Ruby project up and working quickly make it a complete nightmare to maintain later. Its expressiveness and malleability mean that you can never really be sure that you understand how code is being used, and the complexity that emerges from a few years of that is incredibly overwhelming. Nowadays I would much r…

> Nowadays I would much rather slog through ten times as much Java boilerplate, because later I’d expect that I could still refactor code without fearing that the whole thing would collapse around me

Sure, but if you don't reach market fast enough you'll have no reason to slog through anything, period. Can you imagine writing something like Facebook using Rust? It's an almost ludicrous proposition.

Static typing requires that you know what you're building at a relatively fine-grained level--how the pieces will fit together at the source code level, at least roughly. No amount of automated refactoring could ever match the flexibility of dynamic typing when you're just trying to bang out features, let alone explore the feature space, which almost by definition is what any novel solution is doing--exploring. That's why I love using embedded scripting, particularly Lua. You can gradually move components outside the dynamic environment as their place in the architecture becomes fixed and well understood.[1] So-called gradual typing doesn't really permit the same kind of flexibility because it's not the static typing, per se, that burdens development, but rather that static typing has the effect of forcing a more rigid hierarchy of higher-order abstractions and interface boundaries. What you want is the ability to slowly solidify the architecture from the outside to the inside, not the inside to the outside.

Microservices is another way to address the problem, at least in theory, but in practice doesn't actually directly resolve the real dilemmas. At best it just multiplies the number of environments in which you're faced with the problem, which can both help and hurt.

[1] Statically typed scripting languages seem rather pointless to me, and more a reflection of a fleeting fascination with REPL.

Re: Moving from TypeScript to Rust / WebAssembly

#372
post #365

Earlier quoted context omitted.

You're just using the wrong dynamic programming language. Don't get me wrong type checking, static or otherwise, is useful, but eventually you're going to have to throw in the towel and deal with truly hard problems like distributed systems, which in the end must be dynamic (you cannot safely assume that a node separated by time and space respects the same type system your node does). I have a 20k LOC distributed sys…

That you can't capture all constraints in s type system does not make a type system unnecessary. You still drive value based on how much of the correctness checking you can offload to the compiler. I don't really get why programmers better than anyone understand the value of automating work with a computer, but fail to grasp that value applied to their own craft. Let the computer do more of the work in making sure yo…

You're arguing with a strawman. I'm just saying static typechecking is usually sufficient this day in age. Your language itself doesn't have to be static. Actually I'll go even further: It wasn't enough three years ago when language server protocol wasn't a thing.

Re: Moving from TypeScript to Rust / WebAssembly

#373
post #345

Earlier quoted context omitted.

>> But if you're under pressure to build lots of small, partially documented, constantly changing parts every day, you might be better off using more flexible equipment and materials (balsa wood, bailing wire, masking tape, etc.) to get the job done, even if the result will be messier and more prone to breaking. Python & Deno/Node fit the bill for the latter category. Would you consider Julia in the former or latter…

For ML/scientific computing, it can fulfill both roles, I'd say. Julia looks about as flexible and easy to use as Python, R, and matlab for experimenting and iterating quickly with throwaway code, and superior to those languages in every other important dimension except one: it lacks Python's gigantic ecosystem.

Julia has a much larger ecosystem in terms of things like numerical linear algebra, scientific computing, and differentiable programming. How do you use block banded Jacobians inside of ODE solvers? Python's ML ecosystems just barely got non-stiff methods, so advanced accelerations are fairly far away, whereas these are things that have worked with Julia's ML solvers for a long time now.

Re: Moving from TypeScript to Rust / WebAssembly

#374
post #365

Earlier quoted context omitted.

That you can't capture all constraints in s type system does not make a type system unnecessary. You still drive value based on how much of the correctness checking you can offload to the compiler. I don't really get why programmers better than anyone understand the value of automating work with a computer, but fail to grasp that value applied to their own craft. Let the computer do more of the work in making sure yo…

You're arguing with a strawman. I'm just saying static typechecking is usually sufficient this day in age. Your language itself doesn't have to be static. Actually I'll go even further: It wasn't enough three years ago when language server protocol wasn't a thing.

Can you explain that distinction, possibly with an example?

Re: Moving from TypeScript to Rust / WebAssembly

#375
post #71

Earlier quoted context omitted.

This is the fallacy of the grey. Yes, there are nuances and special circumstances, but the overwhelming majority of the time, static typing is simply better. That's one of a small handful of clear consensuses from the last 20-30 years of programming language evolution.

It's not any better if business trade-offs make another decision better. You don't have "all things equal" trade-offs in the real world. Want an easy concrete example? You and your cofounder have 10 years of Ruby experience and investors/customers who want a product yesterday. Or the deliverable that makes most sense is a PHP script that users can drag into CPanel because that's your customer base. The tinkerer insid…

> It's not any better if business trade-offs make another decision better.

I'm sorry, but cleaning your windows with Windex instead of tap water is then "not any better if business trade-offs make tap water better". I am just not sure what you are arguing for: Static typing is better, except for when you don't have static typing?

Some folks here are in the position to choose their current, or shape a collective future landscape, and for those static typing is a consideration.

You mention PHP a few times, but I think this is actually a good example for something that has been pushed away in favor of better things. My impression is that at least the bigger software corporations have moved away from PHP if they ever used it to begin with. Even Facebook, one of PHP's biggest users, replaced it with their own so-named "Hack" eventually, which is apparently a PHP-derivate with "both dynamic typing and static typing" according to Wikipedia.

Re: Moving from TypeScript to Rust / WebAssembly

#376
post #20

As long as you use a language with a good, static type system, I don't care so much what you use. TypeScript or Rust, for all I care you can transpile Haskell into JavaScript if you feel adventurous. But don't use a dynamically typed language as the source language for anything that is supposed to be more than a simple script.

This is silly. There are systems which have had nine nines of uptime written in dynamically typed languages.

So? There are people who crossed the Atlantic in a kayak, does not mean it's an efficient use of your time. The difference is that the people in the kayak were aware of that.

Re: Moving from TypeScript to Rust / WebAssembly

#377
post #42

Earlier quoted context omitted.

That it can be done doesn't mean is the optimal approach. I was a diehard fan of dynamic languages for a decade, but eventually I saw the light. I still use dynamic languages daily, but the bigger the project the more I want proper static typing. None of that mypy stuff, the real deal.

You're just using the wrong dynamic programming language. Don't get me wrong type checking, static or otherwise, is useful, but eventually you're going to have to throw in the towel and deal with truly hard problems like distributed systems, which in the end must be dynamic (you cannot safely assume that a node separated by time and space respects the same type system your node does). I have a 20k LOC distributed sys…

> if your axioms are violated by your system then your system can wind up in an undefined state.

Yes, and if your hardware is broken or a cosmic ray hits your system in just a bad way, then all the static type checking in the world won't help against that. But that's a different problem to solve, isn't it?

I'd postulate that for most applications, you'd usually be happy to have a software stack that's less likely to contain programming bugs in the first place. It's also true that you don't want faulty Airbag software in your car to affect your steering, but don't you want non-faulty Airbag software as well?

Re: Moving from TypeScript to Rust / WebAssembly

#378
post #371

Earlier quoted context omitted.

I’ve worked on several large Ruby codebases, and the thing is, the same qualities that make it easy to get a Ruby project up and working quickly make it a complete nightmare to maintain later. Its expressiveness and malleability mean that you can never really be sure that you understand how code is being used, and the complexity that emerges from a few years of that is incredibly overwhelming. Nowadays I would much r…

> Nowadays I would much rather slog through ten times as much Java boilerplate, because later I’d expect that I could still refactor code without fearing that the whole thing would collapse around me Sure, but if you don't reach market fast enough you'll have no reason to slog through anything, period. Can you imagine writing something like Facebook using Rust? It's an almost ludicrous proposition. Static typing requ…

Facebook uses a bunch of a Rust, incidentally. They also use a lot of statically typed languages, and have made some of their own, even.

Re: Moving from TypeScript to Rust / WebAssembly

#379
post #46

> webassembly is faster than javascript Everyone says this, but I would dispute it as misleading in a lot of cases. I've been experimenting a lot with wasm lately. Yes, it is faster than javascript, but not by all that much. It's the speed of generic 32 bit C. It leaves a lot to be desired in the way of performance. My crypto library, when compiled to web assembly, is maybe 2-3x the speed of the equivalent javascript…

I also have a WASM crypto library, focused on hashing algorithms: https://www.npmjs.com/package/hash-wasm#benchmark I was able to archive 10x-60x speedups compared to the performance of most popular JS-only implementations. You can make your own measurements here: https://csb-9b6mf.daninet.now.sh/

I think he doesn't complain at all about WASM speed vs JS.

He wants WASM to be closer to C performance. I.e. to move further along this line:

    |JS|========>|WASM|=========>=========>========>|C|

Re: Moving from TypeScript to Rust / WebAssembly

#380
post #371

Earlier quoted context omitted.

> Nowadays I would much rather slog through ten times as much Java boilerplate, because later I’d expect that I could still refactor code without fearing that the whole thing would collapse around me Sure, but if you don't reach market fast enough you'll have no reason to slog through anything, period. Can you imagine writing something like Facebook using Rust? It's an almost ludicrous proposition. Static typing requ…

Facebook uses a bunch of a Rust, incidentally. They also use a lot of statically typed languages, and have made some of their own, even.

[deleted]
Post reply on HN