HNHacker News
TopNewBestAskShowJobs

kuramitropolis

258 karma · joined February 28, 2022

submissionscomments
kuramitropolis··on The Case of the Dead Mini5SX
2 glued transistors + thermistor in the middle = "tempco" (temperature compensator). Used in VCOs to compensate for frequency changes brought by ambient temperature changes. Maybe the backlight is PWM-based?
kuramitropolis··on The Cancellation of ‘Jihad Rehab’
The censors' safe play is also well known:

Introduce mandatory "what did the author mean" classes in schools, where children write down the one true interpretation of a corpus of sanctioned texts from preferably >100 years ago, under dictation, for many years; until they are completely incapable of approaching a work of art to understand it for themselves.

It's not 100% effective, but the remaining few percent end up mentally ill, so it's a win-win!

kuramitropolis··on TikTok has an open computational chemistry position
Experimenting on people. It's the new sex, drugs, and rock'n'roll revolution, delivered straight to your optic nerve, so get with it. They already got the monitoring and analytics in place - ain't no regulator got sufficient resolution to stop them from figuring out how to make that dopamine hit just right.
kuramitropolis··on TypeScript is now officially 10 years old
>Thankfully they’re actively working to address that now.

Where? The response I saw on GitHub issues (to the few people who considered it worthwhile to be vocal about the issue) was literally (well, paraphrased): "yeah we did this wrong but we're sticking to it anyway" (because of MS-internal org inertia I assume, something that the TS devs surely have to account for but it's hidden from us as an "open source" downstream)

kuramitropolis··on TypeScript is now officially 10 years old
>I guess your post might have been received better

You assume that I'm primarily optimizing for that.

I optimize for being able to express my opinion in sufficient detail that people actually bother to try to show me things that I don't know, just because they're mildly outraged at my audacity to say, "but some things are very not ok" :)

>Where I'm from...

...they stopped putting people in cages not even for believing outrageous things, but for holding outrageous disbeliefs, about a generation ago. So it's also about maintaining the capability to express dissent.

>I'm clear about this being my opinion, not an universal truth.

God forbid I claim to know any universal truth! Therein lies the way to True Madness. Anything anyone says can at most be their subjective truth - if they can reproduce from memory the things that make them believe what they're saying. Snippet battle was fun

>If the compiler tells me I'm passing a string to a function expecting a number, I find that error pretty easy to grasp, and I don't need to run the code to know how to proceed from that error-message.

And if the compiler happens not to? Back to runtime validation, considering priorities it remains ad-hoc, so the mess gets even unholier.

(where's my authomatic runtime validation layer based on parsing the type definition? holla at me)

>Javascript as a language has lots of quirks. Lots of quirks which are unexpected to most developers not coming from Javascript. That is to say, Javascript behaves differently than most other programming-languages. >I'm not saying it's wrong or "not sane", but programmers coming from other languages will make assumptions and those assumptions will be wrong for "plain" Javascript, leading to buggy code.

I'm not saying it's wrong for JS to be like that either (I put forward a couple good reasons for the contrary and know a couple more), but I am saying that it is already "not sane" enough - in the sense that the hidden assumptions and unexpected behavior impair one's immediate ability to reason about the codebase.

The transpiler ecosystem doesn't help with that, either - TS, Babel, CLJS or whatever else, if I have to run scripts through a compiler it smells like someone isn't managing complexity right and it sure as hell it ain't every downstream developer who just uses whatever has the most mindshare (so that the quirks are at least googlable). Though I guess you could approach it from that angle too

>rather trust the correctness of your own code, than having a compiler check it for you

Rather verify the correctness of my code by running it, than trust the half-assed third-party static analyzer that's manipulated itself between my editor and runtime, yes

>Where Typescript tries to force you to make formal declarations for your code, you find those limiting or getting in your way.

That's a deficiency of TypeScript. The only option is not to use TypeScript, which is in many cases not an option.

>Me (and many others) on the other hand, are just human, and we like a compiler to tell us about obvious errors in our code without having to discover them at runtime, or even worse, in production.

I'm all in for this! I just wish it worked well enough to justify the drawbacks.

>To me it seems like you're one of those people who prefers to work with all the quirks that Javascript provides and considers those to be good things,

Prefer to know things that will not become invalidated by progress? Who doesn't. I already have to reason about a whole stack of "quirks" from the user's brain to the CPU and back. I would've preferred for Microsoft not to add 2322 more of those out of sheer community goodwill but there you have it.

>But if you (and that's up to you!)

It's up to me on my down time. Rest of my life it's up to the economy lol

>decide to write your code using types and allow TypeScript to check them

"decide to buy into the TypeScript language and ecosystem" because "writing your code using types and allowing TypeScript to check them" by manually writing a .JS + .D.TS is also not a practical option.

>That's why people use it.

My guess is most devs adopted it on their down time to stay relevant, "join us or fade away" hahahaah

>at least you know that your code in isolation is unaffected by whatever dynamic runtime it will end up being run on.

Where did that even come from. You mean like how it's now 4x harder to publish an isomorphic library because the CJS->ESM migrations and TypeScript doing its own things with modules have mangled the packaging surface in further sanity-reducing ways

>Be a superstar if you like.

One does not reach a position of power simply by doing what one wants. You also gotta tell others what not to do :)

kuramitropolis··on TypeScript is now officially 10 years old
I'm not even talking about the module support. (It just seems to have the default support of TypeScript.)

Yes, it imports the module. No, it doesn't do even basic type inference (knowing that Foo is a class and consequently allowing it to be used as a type name) - which it would, if it was a superset of JS. Instead it seems to import everything as "any", which is... a start, I guess?

kuramitropolis··on TypeScript is now officially 10 years old
Okay...

    $ echo "export class Foo { a = 1 }" > test.mjs

    $ npx ts-node
    > import('./test.mjs').then(console.log)
      error TS7016: Could not find a declaration file for module './test.mjs'. '/home/user/Lab/test.mjs' implicitly has an 'any' type.

    $ npx ts-node -O '{"allowJs":true}'
    > import('./test.mjs').then(console.log)
      Promise { <pending > }
      Error [ERR_REQUIRE_ESM]: require() of ES Module /home/user/Lab/test.mjs not supported.

    $ echo "module.exports.Foo = class Foo { a = 1 }" > test.cjs

    $ npx ts-node -O '{"allowJs":true}'
    > const { Foo } = require('./test.cjs')
    > Foo
      [class Foo]
    > new Foo
      Foo { a = 1 }
    > function bar (foo: Foo) {}
      TS2749: 'Foo' refers to a value, but is being used as a type here. Did you mean 'typeof Foo'?
No I did not, TypeScript, and that's about as much as it seems to interoperate. I guess in some cases practical migration might be viable - but as for the general case, the out-of-the-box experience seems to speak otherwise.

It's not even viable to write in JS and manually write a DTS - no way to check em against each other. Except idk library in JS, test suite in TS anyway. So not a lot of lateral movement possible in practice.

kuramitropolis··on TypeScript is now officially 10 years old
>you can’t have explicit type defs without explicit defining them somewhere

Sure, as long as I have to define them once and exactly once. Not always possible, as in the case of simple, garden-variety keyword arguments.

   // foo is required, bar has default, baz is optional
   type POJO = { foo: number, bar: number, baz?: number }

   function myFn ({ foo, bar = 3, baz }: POJO = {}) {
     // oh wait...

   function myFn ({ foo, bar, baz }: POJO = { bar: 3 }) {
     // oh wait...

   function myFn ({ foo, bar, baz }: Partial<POJO> = {}) {
     bar ??= 3
     if (foo === undefined) throw new Error("type safety")
     // ...oh.

   // maybe?:
   function myFn ( foo, bar, baz }: POJO = { foo: undefined as never, bar: 3 }) {
     // try :D
Technically the destructuring and the type declaration are completely separate things ofc (that just happen to look about the same because they're isomorphic but that's a watchlist word).

But... it doesn't even try to infer the type of an untyped destructuring - even if it's a local function used only once!

>well defined value objects are easier to reason about than duck typed POJOs, and they perform better too

Long live those!

    class BaseValueObject {
      constructor (values: Partial<this> // oh wait...
> Assuming your default satisfies the non-undefined type, you can just skip the union, it’s implied

    type Foo = { defaultBar?: Bar }

    function main (foo: Foo, bar?: Bar = foo.defaultBar) {
      // oh wait... parameter can't have question mark an initializer

    function main (foo: Foo, bar?: Bar|undefined = foo.defaultBar) {
      // this works but is silly and scaryish
>The only difference is that TS provides a fully optional shorthand for assigning both the type and value in constructor arguments. The actual behavior isn’t any different

That's what a sane person would assume, no? Well, allow me to disappoint you (like that ever needs permission):

    $ node
    > Object.getOwnPropertyNames(new class Foo { a })
    [ 'a' ]

    $ npx ts-node
    > Object.getOwnPropertyNames(new class Foo { a: any })
    []
Probably because it compiles them to a pre-standard, ES5-compatible class implementation based on good ol' `Foo.prototype`. And since they've already handled them one way, they can't become spec-compliant without breaking backwards compatibility.

The other place where this shines through particularly egregiously is the support of ESM static import/export. Everybody's build tools been compiling that back down to CJS so hard that Node.js 16+ introduced intentional incompatibilities between CJS and ESM modes just to get people to finally switch to the standards-compliant module system. So you end up in a situation where the library is written in TypeScript with ESM syntax but the only available browser build is a CJS blob which completely defeats the main touted benefit of static imports/exports, namely dead code elimination...

So you decide what the hell, let's switch TSC to ESM and moduleResolution node16, and end up having to use something like https://github.com/antongolub/tsc-esm-fix because the only allowed fix for TSC doing the wrong thing is at the completely wrong level - https://www.typescriptlang.org/docs/handbook/esm-node.html - if you don't see what's wrong with that, you're one of today's lucky 10000...

kuramitropolis··on TypeScript is now officially 10 years old
>There is no way to export a Go struct for consumption via FFI, for instance.

I hope not.

>Using TS, you can import any valid JS module without any special preparation

Why does the DTS ecosystem exist then (https://www.npmjs.com/package/@types/node etc)

kuramitropolis··on TypeScript is now officially 10 years old
> 10542667 Aug 9 20:40 node_modules/typescript/lib/typescript.js

aint fitting ten megs in a peek view... :(

kuramitropolis··on TypeScript is now officially 10 years old
>your definition of a “sane” developer is not as universal as you may have thought

Where I'm from, sanity has historically been the minority opinion, so we don't really have a word for this, but I think the English one is... "gaslighting"? "TS is a superset of JS", "there are 4/5 lights", "this line is longer/shorter", etc. (Look those up if you haven't, Microsoft marketers surely have.)

What I'm saying is, I am well aware that I represent a minority, and guess what, getting downvoted (not nearly as much as expected) still beats keeping silent about the things that have been fucking with my head for the past, what, year and a half? Considering I've been writing Node for barely 6, the fact that every year the number of software developers doubles [cit needed] probably has a lot to do with it.

No matter if we're talking about a very simple or a very complex system: if there are a lot of subtle inconsistencies in it, and you have to gradually learn your way around them, your ability to keep a consistent mental model of it in your head, and reason about what you're doing, will be impaired: -1 sanity.

Ironically this is the same as people's gripes about the original JS type system. IMHO `==` and `===` should've been the other way around, and 1000 ships wouldn't've been launched. This unwieldy choice of notation (implicit type coercion on `==`) made it just enough subtly different for people expecting C-like strict equality, to create a feeling of confusion and distress.

But since the underlying design principle was not clarified (in browsers all input comes from text boxes, as strings, anyway; and the original "source of truth" was only the HTML file, where element attributes are also strings; so in some limited sense it makes sense to have convert-from-string by default), we get all these (generations of) people with the impression that JS is a "low sanity" language... and that it needs, of all possible features, even more of a type system.

>Personally I almost never see any value in running known broken code.

That's completely subjective. Personally, I don't know how to fix a piece of code without being able to see with my own eyes how/where/why it breaks, but surely that's just my deficiency and everyone else is just telepathic. Boo, shame on me! (I'm also the guy with the months-long pull request because guess what, TypeScript did not make it easier for me to see what I'm doing wrong, just looped me into a waves of type refactors, sometimes causing me to break working code to get dat "spellcheck" out of everyone's faces. I do semver, but most libs on NPM don't ...)

So, in my experience, TypeScript prevents me from running known good code way more often than it prevents me from running known/unknown broken code. As for what value you see in either, sure - that's a matter of style.

Rust was mentioned elsewhere in the thread. It's great to work in a language where "compiles"="works". But TS is not a static language, where types actually matter; it's a restrictive "sanity checker" overlay on top of a dynamic language. And not one that's good enough for me to sacrifice the expressivity that JavaScript allows.

Maybe it's good enough for many other people who never came to rely on JavaScript's flexibility that much in the first place. Thoughts and prayers to 'em. Each one has to make the choice which is the right tool for a job - and when there's an incipient monoculture trying to make that choice for me, I'm bound to make a ruckus.

> If I need to run/test a subset of my code without a complete working system, I have unit-tests for that purpose.

Amen to that! Thing is... you see how elsewhere in the thread, it's mentioned that people use TS annotations as an excuse not to write documentation? Well, in my purely anecdotal personal experience, they also use it for an excuse not to write unit tests! And considering what unit testing in JS looks like... well, no surprise there, either. "Ubiquitous JS" is supposed to be accessible. Instead, we have a number of onramps to it covered with rusty razor blades,

TypeScript is not without its good parts, but overall my journey with it has been one of frustration and, as I'm sure you can see from miles a way, a whoooooole lot of mismatched expectations. Like, ESM working...

Hence the exaggerations, and generally the lots of writing. I like JS/Node, I consider them simple I've been round the block just enough to see it evolve a bit, I gotta adapt to what others are doing (TS) because otherwise good luck getting help, right? So this is my honest perspective about that and I'm here to represent it because it's gotta amount to at least as much as the usual "nah bruh everything ok... u ok?"

kuramitropolis··on TypeScript is now officially 10 years old
JSX is also not TS at all, yet it gets preferential treatment (TSX). Unlike JSX/TSX, the TypeScript used by Vue is just TypeScript - wrapped in a tag next to some other stuff, so you know where the part you need to type check starts and where it ends. All TS needs to do to support this, on a basic level, is ignore the non-TS parts, i.e. let you turn each non-TS line into a comment.

But no, even adding supported extensions to the compiler, that's right, not even formats, just making TS recognize a new extension as a file that it can load code from, is a no-go; a pre-load hook is the simplest thing to add, had they not made it explicitly, intentionally non-extensible.

I didn't even have time to get into the "stacking of language servers" (something that can and should be as simple as a pipe, and of course Microsoft has all the reasons to make it the opposite of that). So the Volar people literally had to monkey patch Node's the standard library and edit TSC's source on the fly to make anything, work, at all.

It all just goes downhill from there. Designing good APIs is hard enough - having to design them around the arbitrary barriers of some Microsoft boffins who decided to add a complex type system to a language which desperately needs a simple macro system - and took 10 years to do a shit tier job - oh, such an enlightening experience! Let's just say that I have become acutely aware that during the past year I have, well, degraded. As a person. And I literally attribute about 50% of that degradation to my ill-advised choice to do my work in TypeScript. Because like everyone I thought "hey, it's just a superset of JS, can't be that bad..."

kuramitropolis··on TypeScript is now officially 10 years old
>You’re right on the first

Strictly speaking, it takes exactly one such behavior (that you cannot even disable) for TS to stop being a superset of JS.

>although classes are out of fashion, so this is low impact

Looking at the TSC codebase, so are keyword arguments. The "in" thing is just to write very very long lines of multiple verbosely named positional arguments instead.

That said, "clases are out of fashion" is a complete non-argument. I'm of the functional persuasion, yet I've found that classes are the ony way to write TypeScript that fits on your screen at all.

Especially now that classes are being introduced in JavaScript proper, and of course TypeScript does them only slightly differently (handling of default property values and "definedness" differs).

>On the second, doesn’t this work?: ‘function foo({ bar = 3 }: { bar?: number })’

You also need a `= {}` there, otherwise you'll need to call `foo({})` - it won't let you call `foo()`. This is also in JS though, so a bad example of TS breaking things (`function foo ({ bar })` still won't work though). There are probably better ones that people encounter, work around, and forget about, because nobody's listening anyway. "The code making sense is not important, what's important is helping the user" lol.

Now imagine how the above looks with 5-10 kwargs (because keeping context in the class instance is "out of fashion", so it's either a ton of args per function or a "context" record which is effectively reimplementing classes but with a worse experience), and an aggressive formatter insisting every individual thing has to be in its own line.

Here's another: failing to infer the type of `this.constructor`.

Sure, the constructor signature may change in a subclass (why not disallow incompatible constructor overrides, given incompatible property/method signatures are already disallowed?); then what about static methods accessed via `this.constructor`?

So you end up defining an interface type for the constructor and using `(this.constructor as MyConstructorType).staticMethod` or whatever. Which is just visual noise where the fucking intent of the code was previously clear as day, so clear that TSC should've been able to infer it (yeah the type inference also sucks).

Also, ever seen TS2322? It's my pet now. What it do

All in all, TS really puts the "Java" back in JavaScript, and then some.

EDIT: Also crap like not being able to have a question mark and a default value in positional arguments so you gotta add `|undefined` there. Even the stuff it adds on top of JS is poorly thought out.

kuramitropolis··on TypeScript is now officially 10 years old
>At the moment vscode only checks files that are currently open

While TSC checks everything by default - even files that are not even part of the dependency graph. That's how great the "great tooling" is in reality.

>I think type checking should only be done when building to some sort of production or realtime in your editor.

Agreed, that's the lest awful option. The problem is that they had 10 years to think of it, and didn't.

>Templates like "create react app"

...are a big part of the problem. "But I don't want to spend a whole day just setting up a project!" You wouldn't have to, if you didn't drink the React kool-aid in the first place.

kuramitropolis··on TypeScript is now officially 10 years old
No, cringing at some "helpful" popup appearing right over the previous line of code. If anything, they could've made it appear under the current line; code's still written top to bottom so it's less likely for "suggested relevant info" to obscure the actual relevant info.
kuramitropolis··on TypeScript is now officially 10 years old
For one, try redefining a property as a getter/setter pair in a subclass.

Also, try implementing a function that takes keyword arguments, some of which are required, and some of which have default values.

I'll wait. When you're back I might've remembered some more.

kuramitropolis··on TypeScript is now officially 10 years old
Yes, it also comes delivered as several near-identical builds for different contexts, each of which is nearly non-extensible. Have you seen the kind of monkey patching Volar (Vue tooling) does to enable type checking of TypeScript embedded in Vue templates? Meanwhile, native JSX support lol
kuramitropolis··on TypeScript is now officially 10 years old
> great tooling

"go to definition" -> goes to type definition

Microsoft makes it intentionally impossible to get anything done in their ecosystem without having "great tooling".

kuramitropolis··on TypeScript is now officially 10 years old
>Incremental adoption

i.e. "it stays out of your way if you don't actually try to use it"

kuramitropolis··on TypeScript is now officially 10 years old
I.e. cringing all the time?
kuramitropolis··on TypeScript is now officially 10 years old
Someone please make WASM source maps JustWork!
kuramitropolis··on Eierlegende Wollmilchsau (2011)
Is "pork"? There's a layer of English that has decidedly Germanic origins; see also "legal doublets".
kuramitropolis··on TypeScript is now officially 10 years old
And then you have to contribute to a codebase with restrictive ESLint (bleurgh!) configuration, so you can't even try out whether your code works because the tooling disallows you from compiling it as long as it contains "any", and the other devs are like "but muh best practices". So not only you gotta work around TS, you gotta do it invisibly. How did people even live before VSCode's type hint popups covered up the previous line?
kuramitropolis··on TypeScript is now officially 10 years old
TS is emphatically not a superset of JS. It rejects perfectly valid JS leaving you no recourse other than design your whole architecture around what TypeScript allows. Which is what Microsoft wants of course.
kuramitropolis··on TypeScript is now officially 10 years old
Opposite experience. Rust was my stepping stone into "hey, maybe JS will be better with some degree of static typing?" Yes it would. But not the way TypeScript does it though, and there aren't any other viable options, are there?

TypeScript brands itself a "superset" of JavaScript. In practice, it arbitrarily invalidates completely sensible JavaScript idioms.

kuramitropolis··on TypeScript is now officially 10 years old
...as optional hints that don't require you to buy into a whole new toolchain.
kuramitropolis··on TypeScript is now officially 10 years old
My project is small but TS takes 4-5 seconds to compile it from scratch on each run.

The main speed impact is in developer productivity though. If something ain't working right, now I first gotta fix the types before I can see if I've fixed the actual logic.

I imagine if my codebase was more "OOP-y" (i.e. if I replaced every layer of my domain model with 3 layers of dependency injection, turning the whole thing into an inscrutable ball of spaghetti like the cartel wants me to) I could probably iterate without breaking the types.

But for any sane developer having made the mistake to touch TypeScript, the capability to strip the types and run the code with broken types, is essential.

"But then why have types at all?" Exactly. They're a crutch for people who want their IDE to understand the code instead of them.

kuramitropolis··on TypeScript is now officially 10 years old
Worse than useless.
kuramitropolis··on TypeScript is now officially 10 years old
Seems so :(
kuramitropolis··on TypeScript is now officially 10 years old
>import every and all .ts file with a .js extension

And recompile on every change, gotcha. I am emphatically not doing either.

EDIT: for future reference, `"type": "module"` is not part of the fix but the thing that opens that particular can of worms. Rotten ones.

← PreviousPage 4 of 6Next →