News for hackers. Stuff that matters.
Re:<3 Deno by zengid on Sunday February 12, 2023 @07:22PM (#34768665)
> The only big drawback of Deno is the language

Ooft. Although TypeScript does have a bit of a learning curve, and a lot of gotchas, I still have to say it's my favorite language to use. If you combine the delicious syntax-sugar of ES6 (and beyond) with a sprinkling of tasteful types, the language leaves you full and energized without feeling bloated.

Re:<3 Deno by brigandish on Sunday February 12, 2023 @08:52PM (#34769264)
What are you comparing it to and what is lacking in those other languages?
Re:<3 Deno by zengid on Tuesday February 14, 2023 @10:56AM (#34791182)
Good question. To be fair, JavaScript was my first "real" programming language, so my brain has adapted the most to it's weirdness. That's probably why TypeScript is very useful for me. But to answer your question, I've been using C# primarily for the last 4 years, and I dabble in other languages like Rust and Python. I used C++ in school (that's what they used for programming classes if you'll believe it). TypeScript feels pretty nice, but I do adore C#. I wish Microsoft would make a T# (as someone else put it once).
Re:<3 Deno by AlchemistCamp on Sunday February 12, 2023 @09:14PM (#34769411)
TypeScript’s type system is very complex and yet fails to achieve type safety to the degree that really strict languages do.

I’m not that into class-based languages and prefer a language to have macros (more for DSLs they enable them for application code). However, even if those preferences were off the table, I’d still rather have something like Kotlin on the server than TS. It’s simpler and isn’t weighed down by 30 years of cruft.

Re:<3 Deno by spartanatreyu on Sunday February 12, 2023 @10:54PM (#34769933)
Typescript isn't really a class-based language.

It's a language that supports both function and OO paradigms.

Also, if macros/DSLs are what you're after, then you'd probably be interested in typescript's decorators. (you can use the old experimental decorators based on the old standard from ages past, and the new *standard* decorators introduced in typescript 5 which are based on the current stage-3 ecmascript proposal).

The only things typescript as a language is really lacking are:

1. Pattern matching (minor issue)

- +90% of pattern matching is really just a more concise switch/case syntax

- the remaining -10% can be done by hand with mapping or just basic if statements

2. Immutable data-structures (minor issue)

- The `as const` suffix handles most of the use cases.

- There is a Records/Tuples proposal which would give some better syntactic sugar and some run-time performance improvements too.

3. Trait system (minor issue)

- Typescript compiles down to Javascript which at the lowest level is actually a prototype-based language. Traits can be approximated using run-time mixins which alter the prototypes to essentially perform the same functions as traits.

- But, it would be nice to have compile-time rather than run-time support for traits.

- I think most languages are still only coming to terms with the fact that traits are often better than "traditional OOP classes".

4. Effects system (investigate)

- It's too early to tell, but having an effects system (à la OCAML 5) will probably lead to entirely new programming paradigms. I'm not sure where it will lead, but having native algebraic effects to replace try/catch/throw would be very nice.

Edit: Formatting

Re:<3 Deno by AlchemistCamp on Monday February 13, 2023 @01:36AM (#34770784)
As I said, the primary reason I wanted macros was for the DSLs they make possible, not their use in application code. For example when I’m working on a Phoenix app, I very rarely write a macro, but I get a great deal of benefit from Elixir them since they make Phoenix’s router DSL, Ecto’s database query syntax and the standard testing DSLs possible.

I disagree that "pattern matching is "really just a more concise switch/case syntax" and use it regularly in function heads and in parsing nested data structures.

More importantly, I reject the premise that the four items you mentioned are the only things really lacking or even that the problem with TS was a lack of features as opposed to its bad features, superfluous features and poor design decisions. For example, I'm not a fan of any of the following:

- loose typing

- multiple ways to declare variables, with different scoping rules

- multiple ways to declare functions, with different treatment of "this"

- the ability of code in any module anywhere in the system to affect code in the module you're looking at without leaving any evidence of this in the module you're looking at

- the ability of functions to alter parameters they're called with

- the sort function in the standard library being destructive by using the above

- etc...

That said, JS/TS really is missing some important things that didn't make your list:

- a good concurrency model

- macros

- compile time guarantees about references

- list comprehensions (actually minor)

- a sufficient standard library

- etc...

Re:<3 Deno by MrJohz on Monday February 13, 2023 @03:30AM (#34771356)
Fwiw, the function syntax in Typescript/Javascript is generally expressive enough to use as a basis for DSLs, and not needing to use macros for this also has a lot of benefits. I'm a big fan of Rust, but I find often library authors overuse custom syntax in macros when just writing functions would have been easier, just as expressive, and much simpler to integrate with an IDE. Where macros do exist in Javascript-land, they tend to be either to implement upcoming features, or as optimisation tools (e.g. converting CSS-in-JS expressions at build-time rather than run-time). The one exception here is probably JSX, but even there lots of people prefer to use function calls instead.

But for things like testing blocks, configuration, HTML/CSS generation, etc, it's generally enough to use the language by itself.

Re:<3 Deno by AlchemistCamp on Monday February 13, 2023 @09:50AM (#34774053)
If JavaScript is “expressive enough to use as a basis for DSLs”, why do you suppose it is that various explicit attempts to recreate RoR in JS, going way back to SailsJS have failed to recreate its router DSL or even similarly terse models or controllers?

Of course not everyone wants a Rails-inspired MVC framework experience, but why do you figure even those who did couldn’t achieve the same level of syntactic sugar?

(I know Ruby doesn’t have macros either, but it does have enough expressiveness in a few other ways to do some things Python and even JS can’t)

Re:<3 Deno by MrJohz on Monday February 13, 2023 @03:31PM (#34779941)
It's interesting that you mention Python, because obviously the RoR equivalent there is Django which leaves something to be desired when it comes to DSLs and expressive APIs. Symphony and Laravel also come to mind here, and I guess Spring in the Java world. I think it's difficult to argue that the creation of a major web framework hinges on being able to express things in a nice DSL.

Rather, I think the truth is that server-side Javascript tends to be used in a different way to Ruby - generally Node projects that I've worked on are much smaller (and often coupled with other similarly-sized services), and are often just minimal APIs designed to act as a middleman between a database and a front-end application. It's not an issue with missing expressivity, but rather a tendency not to need (or at least, not to want) the full-featured powerhouse that is RoR.

Re:<3 Deno by spartanatreyu on Monday February 13, 2023 @08:31PM (#34783885)
These comments are getting a little large, so let me break it into topics:

# DSLs

I'm not familiar with a Phoenix development workflow, but judging by what you've written already, it seems that DSLs are the main sticking point for you.

If I understand correctly, you want to use them to minimise the amount of code you need to write to and/or to guide the project to follow a specific pattern.

I already see this being used in the js/ts sphere:

- NestJS uses decorators for routing and to make the MVC pattern more terse: https://stackblitz.com/edit/nestjs-typescript-starter-pcysqn... - AdonisJS uses decorators for its ORM: https://docs.adonisjs.com/reference/orm/decorators#column

---------------------

# Pattern matching

Can you give an example of what you mean by "use it regularly in function heads and in parsing nested data structures" in regards to pattern matching?

I'm under the impression that it's just a shorthand switch/case that uses filters as conditions.

The current ecmascript proposal for pattern matching (which would end up in js and ts if passed) seems to be inspired in part by Elixir/Erlang.

---------------------

# Features that you're not a fan of

One of the things that makes TS so interesting is that it's a broad language. It doesn't impose a way of development for you.

You can start a project based on how you know how to develop.

- If you already know about functions and typing systems then you can start programming right away.

- If you only understand 90's style OOP then you can start programming right away

Developers should have the option to define the programming styles of the project that they create.

But to go through your list:

> loose typing

I don't see this as a negative.

Those that want strict typing use strict typing, those that want loose typing use loose typing.

> multiple ways to declare variables, with different scoping rules

The `var` keyword is only there for backwards compatibility.

But, if you do try to use it in a new project, you'll be alerted immediately by eslint and you can change it to `let` or `const` depending on your intention.

> multiple ways to declare functions, with different treatment of "this"

All this comes down to is if you want to do OOP (function keyword), or functional (arrow functions).

Use the one that suits you best.

>the ability of code in any module anywhere in the system to affect code in the module you're looking at without leaving any evidence of this in the module you're looking at

What do you mean by this? It sounds like you're describing side effects in general, and nothing to do with modules.

> the ability of functions to alter parameters they're called with

What do you mean by this?

When you pass by reference, you get the same reference. When you pass by value, you get a copy of the value.

If you want to alter the original source of something directly, you pass by reference.

If you want a temporary copy of a value, you just pass the primitive value and you'll get your own copy of it scoped to a function. Now you can make whatever changes you want to it, and when you're happy you can return the final value. This has the added benefit of the outer value not being stuck in a half-changed state if the function throws in the middle of its execution before the changes to the value were finished.

> the sort function in the standard library being destructive by using the above

I'm not sure what you mean by this. This is just pass-by-reference vs pass-by-value again.

---------------------

# Features that you think are missing from JS/TS

> a good concurrency model

JS/TS already has an event loop, async/await functions, pull-style generators, and threads.

One of the things I suggested in my previous comment (but marked as needing further investigation) was an effects system. They can be used to make so-called "colorblind" functions which can be valuable for some async workflows.

> macros

I don't see how these are different from decorators. Unless maybe you're talking about compile-time macros, in which case that's more in line with metaprogramming and things like extending the language with your own (re)compilers like babel.

> compile time guarantees about references

Isn't this what `readonyl`, `as const` and the `satisfies` operator already achieve in TS?

> list comprehensions (actually minor)

Yeah, this is minor. Just syntactic sugar, nothing more to say here.

> a sufficient standard library

Yeah, a lot of early weirdness was caused by not having a standard library. But now we have things like lodash and deno's std.

Re:<3 Deno by biorach on Monday February 13, 2023 @04:11AM (#34771547)
> typescript's decorators

Typescript has decorators?!!

Damn, i wish I'd know about this 3 months ago.

Re:<3 Deno by WorldMaker on Monday February 13, 2023 @03:04PM (#34779522)
~3 months ago the TC-39 (ES/JS language steering committee) hadn't moved their decorators proposal to Stage 3 and Typescript hadn't implemented it yet.

Typescript supported a much older (and different) decorators proposal under an experimental compiler flag, but my momma always taught me never to use flags marked "experimental" in Production.

Re:<3 Deno by lioeters on Monday February 13, 2023 @06:52PM (#34782784)
Decorators in TypeScript is still an experimental feature which may change depending on if/how it's implemented in JavaScript.

> To enable experimental support for decorators, you must enable the experimentalDecorators compiler option either on the command line or in your tsconfig.json

https://www.typescriptlang.org/docs/handbook/decorators.html

> ..the current decorators proposal, which is a work in progress

https://github.com/tc39/proposal-decorators

Oh, but I see that the proposal is now at Stage 3, which means the specs and syntax are stable ("completely described") and ready for browsers to implement.

On further digging, it seems decorators will be a standard feature included in TypeScript 5.0 planned for release on March 14th.

TypeScript 5.0 Iteration Plan - https://github.com/microsoft/TypeScript/issues/51362

Re:<3 Deno by cageface on Monday February 13, 2023 @05:55AM (#34772124)
Immerjs is close enough to language level immutable data structures that I don't miss them that much.

I'm hoping the proposal for match syntax finally lands. Something like Swift's protocols would be nice.

TS inherits some unfixable mistakes from JS but overall I find it a pretty comfortable and productive language.

Re:<3 Deno by garyclarke27 on Monday February 13, 2023 @08:40AM (#34773207)
What About Named Parameters?

I'm surprised Typescript has not tried to add this major missing feature from Javascript.

I know you can hack this using an Object, but for me Named Parameters are so useful for code readability and intent - especially for calling functions to make it obvious what's happening and to so that different order of arguments doesn't cause bugs.

Re:<3 Deno by giraffe_lady on Monday February 13, 2023 @11:37AM (#34775812)
Shit even something like rescript. Ocaml is weighed down by 30 years of cruft and it's not known for a simple type system either. Yet it's still easier to work with than typescript and you get more for it.
Re:<3 Deno by pjmlp on Monday February 13, 2023 @11:45AM (#34775934)
ES6 classes are still based on prototype inheritance underneath.
Re:<3 Deno by darthrupert on Monday February 13, 2023 @01:49AM (#34770846)
Afaik, it's still missing a high quality REPL which python can give you. Extremely useful for exploratory coding.

Otherwise I have to agree, Typescript is a pretty damned good compromise.

Re:<3 Deno by jeremyjacob on Monday February 13, 2023 @02:20AM (#34770998)
Deno’s REPL is quite nice. It’s syntax highlighted, supports Typescript and autocompletion as well as creature comforts like enter opening a new line when the cursor is in between quotations. You can also pass a file to load and then work interactively from that. The URL-based imports allow you to paste code from another project and not worry about `npm install`ing anything.
Re:<3 Deno by lloydatkinson on Monday February 13, 2023 @05:11AM (#34771885)
You can get pretty close with Vitest, a unit test as a REPL, and Vitest's ability to run tests as soon as the file changes.
Re:<3 Deno by spencerchubb on Monday February 13, 2023 @09:11AM (#34773574)
I never understood why people feel that typescript has a learning curve. I never formally learned typescript; I just started using it intuitively. I already knew javascript, and I already understood how types work from using other languages, so there wasn't anything to learn.

When people say typescript is hard to learn, do they know javascript, or are they starting from scratch?

Re:<3 Deno by zengid on Monday February 13, 2023 @10:37AM (#34774774)
I had a similar experience where I was able to pick up most of it just by tinkering around with it, but there were a few places where I expected it to behave in a certain way, but ended up tripping over a few places where the type system is a little too weak, or the syntax for some of the advanced types are too unique to guess how it works without some studying. I made a blanket statement about the curve too, since I feel like the community as a whole is still adopting it. Library authors adopted it early, but the average front-end dev (judging from podcast topics and documentation I see) seems to be really getting serious about learning it in depth. YMMV.
Re:<3 Deno by quectophoton on Monday February 13, 2023 @10:41AM (#34774856)
Same.

Python's type hints and Ruby's Sorbet (or their weird RBS thing), I can understand.

But TypeScript? Besides a few things that are not obvious at first (like callable interfaces), I don't think you really need to think about most stuff.

Re:<3 Deno by jamal-kumar on Monday February 13, 2023 @11:36AM (#34775780)
It has an insanely complex type system. It's kind of incredible, I don't know of any other type systems off hand which are totally turing-complete. That's honestly really impressive.

I don't think you need to use most of these types until you start getting into stuff like needing union types. You can get away with reading and writing most typescript without getting too crazy.

I think the most compelling thing I read about type hinting is that it's like salt - A little and the dish doesn't taste the same without it but too much and you've ruined the thing

Re:<3 Deno by pjmlp on Monday February 13, 2023 @11:46AM (#34775958)
OCaml, Haskell and C++ (with templates) for example.