by Fudgel on 8/18/23, 5:58 AM with 231 comments
by grumblingdev on 8/18/23, 1:25 PM
The fact that Functions are Objects that can have properties/methods is supremely undervalued.
Are there other languages that do this so nicely? It's the perfect blend of OO and functional.
Programming is mostly about gradually figuring out the right design I find. JS/TS let's me evolve things naturally without big rewrites.
function foo() {}
function bar() {}
function baz() {}
const commands = [foo, bar, baz]
// Run commands
commands.forEach(x => x())
foo.help = 'This does something'
// Describe commands
commands.forEach(x => console.log(x.help))
// Add some state via closure.
const config = {}
function foo() { config.blah }
// Add some state using partials.
function _foo(config) { config.blah }
const foo = foo.bind(null, config)
I can flexibly do what I need, without ever having to define a class like `Command`, which I probably don't even know what it should be yet.This premature naming of things in OO creates so many dramas.
It avoids things like `VideoCompressor#compress()`, `VideoSplitter#split()`. You don't have to think: what state belongs in which class...you just call the function and pass it what it needs.
by lmm on 8/18/23, 6:42 AM
by gr__or on 8/18/23, 8:47 AM
Going between Rust and TS it is painfully obvious how much sth like tagged enums are missing, which can also be seen in this post.
I know of this [1] proposal for ADT enums which looks like it has stalled. Anyone know of other efforts?
[1] https://github.com/Jack-Works/proposal-enum/discussions/19
by rtpg on 8/18/23, 6:51 AM
by dna_polymerase on 8/18/23, 8:07 AM
The author uses a TypeScript subset to write a compiler to 32bit ARM assembly and explains that it almost looks like Pseudocode, so it is very accessible. A sentiment I can get behind, despite avoiding it in any case possible.
by domlebo70 on 8/18/23, 7:53 AM
export const run = <T>(f: () => T): T => f();
Now you can go: const inferred_type = run(() => {
switch(blah) {
...
}
})
by andrewcobby on 8/18/23, 10:10 PM
For standard parser generator frontend, Ohm-js[1] is quite pleasant. I wouldn't recommend anyone reviews the offical tsc compiler, it's huuuge - instead there's mini-typescript[2] (in particular the centi-typescript branch[3]) which does a nice job illustrating how tsc is working.
[1] https://ohmjs.org/ [2] https://github.com/sandersn/mini-typescript/ [3] https://github.com/sandersn/mini-typescript/tree/centi-types...
Looking forward to GC an DOM access in WASM.
by catsarebetter on 8/18/23, 6:53 AM
by paxys on 8/18/23, 4:16 PM
by hardware2win on 8/18/23, 8:25 AM
Ive personally decided to avoid visitor pattern bloat and Im waiting for closed enum feature in order to have compile time exhaustive check
by rustybolt on 8/18/23, 9:16 AM
by andromaton on 8/18/23, 8:54 PM
by auggierose on 8/18/23, 12:53 PM
Of course, that one has been downvoted to -4 (as of now).
by metalforever on 8/18/23, 2:17 PM
by boredumb on 8/18/23, 1:25 PM
by harha_ on 8/18/23, 11:10 AM
by tomp on 8/18/23, 9:06 AM
It doesn't even have destructuring pattern matching!
At this point, even Java is better [1].
[1] https://github.com/tomprimozic/caya/blob/master/src/caya/Int...
by frozenport on 8/18/23, 9:56 AM
by newusertoday on 8/18/23, 7:14 AM
by zelphirkalt on 8/18/23, 7:29 AM