News for hackers. Stuff that matters.
Re:Are dynamic languages going to replace static languages? ... by zarzavat on Wednesday August 04, 2021 @06:02AM (#28059192)
If you are writing a new large project in JS without TypeScript, you are doing it wrong period. Bare JS is a cute language for personal websites but it's not feasible for anything more than a few thousand SLOC.
Re:Are dynamic languages going to replace static languages? ... by Zababa on Wednesday August 04, 2021 @10:27AM (#28061374)
I'd personally reach for something else than TypeScript. TS tries to type the existing JS world which makes it really big and complex.
Re:Are dynamic languages going to replace static languages? ... by lolinder on Wednesday August 04, 2021 @12:09PM (#28062683)
The advantage TypeScript has for front-end over something that compiles to JS is that you pretty much know what your code will compile to: with a few exceptions, you just strip out the type annotations. Knowing this, you can accurately predict things like performance.

In contrast, a compiles-to-JS language can produce code that behaves unexpectedly in its non-functional requirements, and in the worst cases crashes where it shouldn't. That will be less of an issue as compilers get better, and WASM should help a lot, but in the current ecosystem TypeScript produces more predictably good results.

Re:Are dynamic languages going to replace static languages? ... by Zababa on Wednesday August 04, 2021 @12:52PM (#28063295)
That may be true in theory, but I find that people write radically different code in JS and in TS. TS code looks a lot more like C# compared to regular JS code, people use a lot of classes over plain functions and data structures.
Re:Are dynamic languages going to replace static languages? ... by nawgz on Wednesday August 04, 2021 @12:16PM (#28062795)
TypeScript is not really big and complex, it's just a type system. The only real pain with TypeScript vs. a language with native static types is that TypeScript requires a bit of extra work to fiddle with the compiler, otherwise when it comes to the code it's flexible but can be used in a very simple manner.
Re:Are dynamic languages going to replace static languages? ... by Zababa on Wednesday August 04, 2021 @12:48PM (#28063248)
> TypeScript is not really big and complex, it's just a type system.

It's a very complex type system though.

Re:Are dynamic languages going to replace static languages? ... by nawgz on Wednesday August 04, 2021 @02:19PM (#28064379)
Can you say some ways it is more complex than other type systems? I think type systems are inherently complex.

From my perspective, I feel user-facing complexity is quite low in TypeScript in some key ways. You can write your type declarations anywhere, you can import and export them in a familiar JS-module way, you don't need to explicitly type anything in particular so you can be anywhere on the spectrum from very rigorous types to no types at all / `any` everywhere, and finally it has really good error messages so you rarely are stuck with a type mismatch that makes no sense.

Re:Are dynamic languages going to replace static languages? ... by dimitrios1 on Wednesday August 04, 2021 @09:48AM (#28060954)
Tell that to the mountain of "few thousand line SLOC" javascript projects that existed and continue to exist before Anders Hejlsberg embarked on his mission to C#-ify javascript. I am not opposed to adding strong type checking to JavaScript, but Typescript ain't it.
Re:Are dynamic languages going to replace static languages? ... by paavohtl on Wednesday August 04, 2021 @11:15AM (#28061972)
TypeScript has nothing to do with C#, apart from its creator. The structural type system with explicit nulls, sum types and very powerful generics makes it feel much closer to the ML family of languages than C#, despite using the C-like JS syntax. The teams I've used it in have never really used it to build complex OOP hierarchies or even used classes for anything other than React components, though there are probably many who do.
Re:Are dynamic languages going to replace static languages? ... by zarzavat on Thursday August 05, 2021 @01:00AM (#28070046)
Both are true. The original TypeScript v1 was a lot more like C#-in-JS and was very class-oriented, however over the years the type system has grown into a mature ML-like structural type system as a side effect of trying to type the wide variety of dynamic JS out there.

Anybody who last looked at TypeScript a few years ago and dismissed it needs to have another look.

Re:Are dynamic languages going to replace static languages? ... by morgancmartin on Wednesday August 04, 2021 @10:17AM (#28061257)
I agree that TypeScript leaves something to be desired, but it is far and away a better alternative to pure JS. TS may not be total, but it comes close enough to get the job done for the dynamic environment it's meant to target assuming operators competent enough to lean on what it offers.

I should also note, I've attempted OOP in TS and it wasn't pretty. It is much more suited to a functional style IME, although I will concede I have seen some open source projects that use it in a Java-esque OOP style presumably to good effect. Personally it wasn't my cup of tea.

Re:Are dynamic languages going to replace static languages? ... by k_ on Wednesday August 04, 2021 @10:29AM (#28061395)
> I am not opposed to adding strong type checking to JavaScript, but Typescript ain't it.

If you are curious about this, you might be interested in checking out Haxe [0]. It has static typing, type inference, pattern matching [1] (maybe not on par with ML languages, but still good), and can transpile to multiple targets [2] including JS.

[0]: https://haxe.org [1]: https://haxe.org/manual/lf-pattern-matching.html [2]: https://haxe.org/documentation/introduction/compiler-targets...

Re:Are dynamic languages going to replace static languages? ... by xvilka on Wednesday August 04, 2021 @12:22PM (#28062889)
There are also notable Rescript [1], Melange [2], Reason [3], PureScript[4].

[1] https://rescript-lang.org/

[2] https://github.com/melange-re/melange

[3] https://reasonml.github.io/

[4] https://www.purescript.org/

Re:Are dynamic languages going to replace static languages? ... by wing-_-nuts on Wednesday August 04, 2021 @10:18AM (#28061273)
>Typescript ain't it.

Expand please?

Re:Are dynamic languages going to replace static languages? ... by jamil7 on Wednesday August 04, 2021 @10:46AM (#28061605)
I think what the parent is getting at that Typescript doesn't try to give you the kind of guarantees that something like Rust, Swift, Elm etc. can. They are upfront about this though and it's stated here in the design goals as a non-goal https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi...
Re:Are dynamic languages going to replace static languages? ... by bwship on Wednesday August 04, 2021 @12:58PM (#28063393)
Actually Typescript is it.
Re:Are dynamic languages going to replace static languages? ... by claytongulick on Wednesday August 04, 2021 @10:27AM (#28061367)
If you're wasting your time with needless datatypes you are doing it wrong period.

See what I did there?