Тёмный

Typescript Is SURPRISINGLY OK For Compilers?? 

ThePrimeTime
Подписаться 596 тыс.
Просмотров 51 тыс.
50% 1

Recorded live on twitch, GET IN
/ theprimeagen
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagenreact
Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
turso.tech/dee...

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 123   
@soulsearch7383
@soulsearch7383 Год назад
The channel reminds me of the days when there was a person in town who would read the news out loud for the people that didn't know how to read.
@Deemo_codes
@Deemo_codes Год назад
Prime is a Tech Crier
@sellicott
@sellicott Год назад
1:58 As a Ohioan, all I can say is that we are coming for you, you cannot escape.
@ChrisP872
@ChrisP872 Год назад
I have only spent a few days in Ohio about twenty years ago but that was enough. I'm one of you and just waiting for the call to "activate".
@lodbldbol
@lodbldbol Год назад
I once slept at a rest stop in Ohio on the way back from Indiana to New Jersey, I am also now an Ohioan
@vasilisthemelis9017
@vasilisthemelis9017 Год назад
TypeScript: Allows you to make strongly typed printf from scratch Prime: "it's only fake types"
@zeocamo
@zeocamo Год назад
he means that it is still JS understand it, and you got all the power in JS, and it is hard for the TS devs, to remove all the power of JS with Types, so it come in to TS. this normaly happens with the any, null, unknown types, so if you remove them it is not as fake types but still. for me i don't care as i don't need the types to be my Parents, i have learn the places/thing you need to fix or not do, so the JS types work perfect for me, but Prime can't have that in the mind.
@nomoredarts8918
@nomoredarts8918 Год назад
Meanwhile Elm - that's cute
@zeocamo
@zeocamo Год назад
@@nomoredarts8918 ye
@cat-.-
@cat-.- Год назад
what's the problem with unknown? I understand it's as sound as other types. @@zeocamo
@tekneinINC
@tekneinINC Год назад
~ 12:58 : PhantomData is for when you’re using something like unit structs as a generic argument for your types to change the type signature of your impl blocks so you can expose different methods depending on what ‘state’ your struct is in but you don’t actually store those unit structs as a field. Definitely a little confusing the first couple (or tens) times you try to implement it, but useful to only allow methods a() b() c() in ‘impl MyType for MyType’ and d() e() f() in the ‘MyType’ variant.
@wolfeygamedev1688
@wolfeygamedev1688 Год назад
Can just use State directly, if state is 0 sized compiler is smart enough to phamtomdata it. If not you probably want to use it anyway.
@koodeau
@koodeau Год назад
There at the bottom are 2 different kind of people: those who use any and those who use ts-ignore
@draakisback
@draakisback Год назад
Phantom data is a way of telling the compiler that you want the field to act like a specific data type without storing the actual value. I've used this in the past with an interface so that I could call the methods without implementing it concretely. The usecase that I used it for was in a cryptography secret storage library. I used the phantom data to attach an interface to the master key that locks the data so that it can call encrypt/decrypt directly on the vault type with the key. The interface itself is just the API for calling the crypto functions on the vault and having it attached to the key, means that you can have multiple key types with multiple crypto algorithms associated with them. Another usecase would be in a case where you've serialized data into like a binary format but you still want the type information to be associated with the data. That way you can cast the data later back to the type. I would never use typescript for a compiler. The type system isn't actually a type system and you're effectively writing your compiler in JavaScript at the end of the day. I guess you could use static type script but I don't know why you'd waste your time. Ocaml does everything you want and then some
@homelessrobot
@homelessrobot Год назад
Probably you would bother because you are writing a compiler that targets javascript or webassembly, and the easest way to get software portably if you are already operating in the javascript ecosystem is to use something based on javascript.
@draakisback
@draakisback Год назад
@@homelessrobotNaw, if I had to target JavaScript, id rather use something like Dart which has static typing. Or I would just use Reason/Bucklescript via Ocaml. You don't really need to write a compiler for a specific target anymore given that so many language ecosystems have multiple targets that they can support. If I build something in Ocaml, it can target the LLVM, JavaScript or WASM, and various other architectures. You could even target the JVM via the GraalVM. As prime pointed out, Generics in TypeScript and Types in TypeScript are a mess. For example, if you wanted to support multiple number types, you would be in a rough spot.
@Diego-Garcia
@Diego-Garcia Год назад
The name is Thegen
@rapzid3536
@rapzid3536 Год назад
It doesn't help that the tooling won't show you the "resolved" type shape without hacky workarounds. Instead you have to follow a chain of extended types building up your own mental model of what the final resulting type is.. Addressing this is a pretty popular issue on GH.
@dealloc
@dealloc Год назад
You can write a type that simplifies the type into the resulting type. It's simple really, you just build up the type from ground up based on a union of types. You can see how type-fest implements this under its Simplify type. It does have performance implications, however,because TS would need to visit each intersection in T and rebuild the type anew. But it is possible.
@nomoredarts8918
@nomoredarts8918 Год назад
Typescript, language that came to the rescue and leaves even bigger mess
@advanceringnewholder
@advanceringnewholder Год назад
Just Microsoft things
@jingle1161
@jingle1161 Год назад
😂😂😂😂😂
@rodrigobarenco
@rodrigobarenco Год назад
Prime you should couver "rinha de backend". It was a "competition" to make a simples backend in a limited machin with loadbalancer, everything and - the better language ( or dev lol) won. Lol Ps: It means something like backend dogfight in portuguese!
@QuassaKE
@QuassaKE Год назад
@primeagen this 🎯
@t3dotgg
@t3dotgg Год назад
Heads up Flip the audio mix on this one is way too quiet
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
it was my birthday and i was on a bender -Flip
@JakobKenda
@JakobKenda Год назад
0:37 plzoo was created by a college professor of mine, Andrej Bauer, who taught me a class called Programming language principles
@Trequetrum8
@Trequetrum8 Год назад
"It's bimodal programming, I'm not sure how else to describe it other than that. That's really frustrating." A great example! Here *ThePrimeagen* is hitting on the issue with gradually typed languages in general. Haskell struggles to encode fundamentally structural aspects of a program nominally, but dynamic languages grind to a confusing bug-fest in the face of problems a nominal program has no problem with. Languages that provide both have their own issues, but they feel navigable. This is why PureScript (which also compiles to JavaScript) with it's row polymorphism feels so great to me, it really embraces both worlds. (Through I'd love it if the core library embraced row poly a bit more endemically).
@gorge464
@gorge464 Год назад
How you described ocamls type system reminds me of elixirs
@thomasjhickson
@thomasjhickson Год назад
3:39 Indexes (for all intents and purposes) suffer from the same memory management issues as pointers. They can be better in some ways if implemented well (no ownership, typed ids, bounds checking, etc) but also you can do many similar things for pointers. Saying "use indexes" is the same as saying "circumvent the borrow checker". Thats fine, but also why are you using rust if you're just going to circumvent all the safety its trying to give you. Just talking about memory safety here though. The post made some good points about serialization etc
@M0du5Pwn3n5
@M0du5Pwn3n5 11 месяцев назад
The issue isn't inference, it's which kinds of inference the type system makes. If the type system does too much inference, that's just a dynamic programming language. You just end up reinventing dynamic typing from the other direction. You see some people accidentally do this with powerful type systems where the goal becomes not to construct powerful, descriptive types, but to have the type system infer as much about the types as possible to save yourself typing. The point of a good type system is that yes, you DO have to think about certain things twice. That dual path is the entire goal. You come at a problem from two different angles, and you have an inference engine that can tell you when those two angles conflict, in cases where you wouldn't have noticed the conflict yourself. The point of a good type system is to say "I'm pretty sure about A" and then you say "I'm pretty sure about B", and then when you go to write something that involves both A and B the type system will think through some of the implications of their interactions for you, and it can say "wait given what you told me about A and B this doesn't actually make sense". This is useful because often the type of A is easy to reason about and the type of B is easy to reason about, but their interaction is hard to reason about, so pointing out type errors helps you diagnose assumptions about A and B that you forgot or that you weren't thinking of. The problem is that if you let a type system become too inferential, then this benefit goes away. If you have sufficiently powerful inference, then you can define A, and write the interaction between A and B, and the type system can reason about the type of B based on that interaction. But it does that by assuming the interaction, the complicated part that's hard to reason about, that you wanted help with, was correct. At best, if you interrogate it about its inferences you'll notice that it inferred something weird about B. But that won't be an error, so you won't necessarily know to look. Simultaneously, there are a lot of useful type inferences that are not universally safe to make. TypeScript is absolutely full of these - things where you think it ought to infer a type because 99% of the time it would be safe, but it can't because the type could actually be violated. The answer is static typing with minimal inference in the LANGUAGE and tons of inference in the EDITOR. auto and var suck if you leave them in your code, but they are fantastic for entering code. You don't need the language to infer the type of a key, you need the editor to infer it and insert it for you. You do this, and suddenly you get the best of all worlds: you don't have to enter trivial types all the time, your editor can guess types heuristically and it isn't a big issue in those cases where it could technically be wrong in some exotic circumstance, when the editor inserts the type you can immediately see "wait that's not right" instead of hoping you mouse over it and read a tooltip or something, and when you're reading code you can see all the types easily.
@MadushanNishantha
@MadushanNishantha Год назад
I think rust doesn't support defining a generic parameter to a struct, but then not using it in a struct field. PhantomData is just there for to fool the compiler.
@ShadowKestrel
@ShadowKestrel Год назад
PhantomData was originally more for lifetime reasoning, and while it's less necessary nowadays there are still some edge cases where the compiler needs it to understand what's going on. Or if you want an unused generic, it'll make that work too I guess
@mccGoNZooo
@mccGoNZooo Год назад
Awkward to hear the "Haskell is not for production" memes when it's much more common in production than OCaml. I wouldn't choose it for most of my projects nowadays, but it'll be a cold day in hell before it's a worse choice than OCaml for the vast majority of projects, compilers included.
@TechBuddy_
@TechBuddy_ Год назад
5:19 wtf happened there I was playing this video on full volume. Everyone around me gave a wierd look 😂 I couldn't even explain to them what just happened there
@gritcrit4385
@gritcrit4385 Год назад
just say you were watching a porn. it's easier to explain.
@abdo_omareg
@abdo_omareg Год назад
love matklad articles, he's a rust/zig legend
@salvatoreshiggerino6810
@salvatoreshiggerino6810 Год назад
24:00 and then you go off the right end of the top line when you hit an edge case in the type system that they didn't think off, so you still fall right back down to hell.
@istasi5201
@istasi5201 Год назад
i kinda wanna learn haskell now
@c0zn1c
@c0zn1c 10 месяцев назад
Combine Purescript and Rust using Waterslide? Waterslide is an unmaintained, yet supposedly stable library to share datatype definitions between the 2 languages. I'm new to programming, so my idea might be off, but I'm thinking i can get by learning Rust(i have the time and patience.. even if it hurts me), Purescript, WebAssembly, HTMX and refresher on my old Html Css days. What objections, tips, secrets would you share on this logic? 🙏 thanks.
@jorgerojas4402
@jorgerojas4402 Год назад
I get TOC by seeing you highlight phrases except for the first and the last letter. Please help me.
@pokefreak2112
@pokefreak2112 Год назад
I wrote a toy compiler in ts and can't recommend it. Performance was at least 100x slower compared to my previous compiler written in C, compile time evaluation sucks because you don't have real data types, and because node.js and the browser have different API's you end up writing a bunch of your own abstraction layers for basic stuff like file I/O and buffers.
@SimonBuchanNz
@SimonBuchanNz Год назад
Well, yeah? They explicitly say to use it for prototyping, so performance and portability is pretty pointless.
@benbowers3613
@benbowers3613 Год назад
So, you used node and not deno?
@pokefreak2112
@pokefreak2112 Год назад
@@SimonBuchanNz I chose ts for my own reasons, those being the ability to run in the browser and (what I thought would be) "good enough" performance. Even for prototyping I wouldn't consider it to be a good choice, development went only marginally faster than with C and as I already mentioned any interesting features you'd actually *want* to prototype are way nicer to implement in a language with real types.
@pokefreak2112
@pokefreak2112 Год назад
@@benbowers3613 pretty sure I tried it at the time and even just console.log("hello world") took several seconds to run, I'm not putting up with that
@SimonBuchanNz
@SimonBuchanNz Год назад
@@pokefreak2112 shrug? Might depend on experience, I tend to find greenfield typescript to be super fast, it's only when you start productionising that it becomes more of a pain, and I bet I'd be pretty garbage at C.
@dealloc
@dealloc Год назад
Naming types and variables the same is not a problem-it's conceptually the same as using `class` because a class is both its own type and value. If your intention is to import the _type_ from another file, the use `import type`. There's no other downside to this. TypeScript knows the difference, because they cannot be used interchangeably (i.e. using a type as the value and vice versa), which is why it allows it.
@thekwoka4707
@thekwoka4707 Год назад
sure, but the class gets exported both together.
@dealloc
@dealloc Год назад
@@thekwoka4707 So does importing the function as value, if it has an associated type with the same name it will also import said type information. TypeScript uses on declaration merging for this behaviour.
@DiThi
@DiThi Год назад
I tried to use TS compiled through a couple of compiler projects (one to C++, one to LLVM), and during that struggle I discovered that Nim is almost exactly what I was looking after, because it targets both C/C++ and JS. Well, after using Nim for a while I think the native mode is great but the JS mode not so much, but it's not a big deal because I'll use emscripten instead of Nim's JS mode (once I finish porting my JS/TS code that is). I may still use JS mode occasionally, for that reason I'll try to improve it.
@glompix
@glompix Год назад
do typechat next. pydantic can suck an egg. i only have 1000 tokens of context to work with and typescript's type format uses up less of that (i think idk i haven't actually tried it yet)
@djupstaten2328
@djupstaten2328 Год назад
IS OHIO A LIBRARY
@atalhlla
@atalhlla Год назад
All supply chain attacks are just Ohio probing for weaknesses
@RedPlayer_1
@RedPlayer_1 Год назад
It can also be a string if you want
@sacredgeometry
@sacredgeometry Год назад
Thats not surprising. You know what would make it better? If it had runtime type checking.
@aqezzz
@aqezzz Год назад
“Just use indexes instead of pointers” wait wait wait. Pointers are literally indexes into ram so we’ve come full circle
@clementdato6328
@clementdato6328 Год назад
binAry the way you pronounce it chokes meXD
@lucrativelepton
@lucrativelepton Год назад
I have never heard of the Ohio thing... what the what!? Lol
@drsensor
@drsensor Год назад
You forgot to put the link in the description
@RasmusSchultz
@RasmusSchultz Год назад
13:28 "all sorts of problems when you name them the same thing" - no there isn't? the namespace for types is completely separate from JavaScript variable/symbol names - type hints can only refer to types, which cannot be referenced from anywhere in JS. what's the problem?
@dealloc
@dealloc Год назад
There's no problem and you're right. I use this pattern a lot and have never run into any issues. It's effectively the same as using `class`, it just abstracts away this relationship.
@RasmusSchultz
@RasmusSchultz Год назад
@@dealloc I use it mostly for functions, which for some reason, unlike classes, don't automatically get a type - I actually opened a TS issue and pointed out this inconsistency, and they were like, nah, that would be way too confusing. Okay? But when the class name somehow refers both to the constructor type and the instance type, somehow that's not confusing? I think maybe TS is a little too inspired by C# on this point - it's almost as if they forgot that classes in JS are actually instances. 🤨
@dealloc
@dealloc Год назад
@@RasmusSchultz It does make sense to me. The class type points to an instance of that class, whereas `typeof Class` points to the type of the constructor. You can think of the constructor as being equivalent to pointing to a function, since both are callable, albeit one creates an instance through `new` keyword, while the other does not. Classes in JS can be used to create instances, but are not themselves instances; they are more of a blueprint.
@RasmusSchultz
@RasmusSchultz Год назад
@@deallocclasses are also instances of Function - my point is, a class declaration generates both a type { new(): T } for the constructor function as well as it's return type T. So with one declaration, you get something that is immediately useful for type-hinting, and with functions you do not.
@dealloc
@dealloc Год назад
@@RasmusSchultz The reason is that TypeScript wants to differentiate between function declarations and classes because they have different rules when it comes to instantiation. A class is required to be constructed using the `new` keyword whereas a function call does not require it, even if it acts as a "class". Typeof makes this distinction less clear and so TypeScript just wants to make it easier by avoiding this distinction ( { new(): ... } vs { (): ... }. Even though classes are syntastic sugar for prototypal inheritance, they also come with limitations imposed by the language spec and will be thrown at runtime.
@Heater-v1.0.0
@Heater-v1.0.0 Год назад
I thought the new PHP was the thing now a days! The world has gone upside-down. As far as I'm concerned if your high level language compiler is not written in itself, from lexing to code through optimisation to code generation, you have not made a real language yet. All this resting on LLVM (C++) is backsliding.
@thehibbi
@thehibbi Год назад
*Enter CPython*
@zweitekonto9654
@zweitekonto9654 Год назад
Based.
@shmuelisrl
@shmuelisrl Год назад
I'm sorry, but please call them indices, not indexes. Idk why; It's just sails smoother by me
@lauraprates8764
@lauraprates8764 Год назад
Ppl really forget that deno translate ts to js in order to run it
@u9vata
@u9vata Год назад
I find this not that good at all... Actually do parsing in TS lately - and also a simpler parser I wrote in C++ for the same thing. Honestly I think some choices here I dislike - but ts is not really clean enough for me for this. But yes... its "ok" meaning that you might be not puking while coding in down - which is good in practice... but if I could choose I would not do it in TS.. just this way rest of the team can read it easier....
@aidantilgner
@aidantilgner Год назад
Typescript is a bonafide silly goose
@tobyzieglerrr
@tobyzieglerrr Год назад
Rust not yet production ready... i thought i should rewrite all with Rust. What am i supposed to do now?
@kollpotato
@kollpotato Год назад
Rewrite everything in JDSL
@postsupremacy
@postsupremacy Год назад
rewrite in C#
@tobyzieglerrr
@tobyzieglerrr Год назад
@@postsupremacy you mean Java 😆
@smallfox8623
@smallfox8623 Год назад
@@tobyzieglerrrJava is a shitty version of c#
@diadetediotedio6918
@diadetediotedio6918 Год назад
Rust is production ready
@johanrg70
@johanrg70 Год назад
Yeah, it might be good from a pure language perspective, but it still compiles down to regular javascript that frankly is dog slow for a compiler. DO NOT MAKE YOUR TOOLS IN JAVASCRIPT if its for public usage. Slow developer tools have wasted so much time for js developers.
@M4Dbrat
@M4Dbrat Год назад
Come to the dark side, we have Rescript
@beetrootpaul
@beetrootpaul Год назад
I dislike these cases where to understand the app you have to both get a grasp of the JS code and of the complex type system as well 😕 I prefer to use basic TypeScript only and have my life easier. Tried to incorporate some fancy generic in my recent code, reverted quickly.
@v2ike6udik
@v2ike6udik Год назад
5:09 I know what happend there was Eminem - Ken Kaniff :)
@vitiok78
@vitiok78 Год назад
I'll tell you a secret... PHP has runtime type check...
@darkfoxwillie
@darkfoxwillie Год назад
wtf was that voice with Deno jajajajajajajajajaja
@zeocamo
@zeocamo Год назад
all of the languages he list here is fine for prod. and they are use for it.
@jonforhan9196
@jonforhan9196 Год назад
Fun police
@emjizone
@emjizone Год назад
3:30 The problem, @ThePrimeTimeagen, is that they've just called you an *hobbyist* tinkerer. 😆 Do you resent that? For me pointers are pseudo- *random* indexes and indexes are *ordered* pointers. And I like *order.* You should like order, too: How do you think Sauron, Darth Sidious and Keyser Söze had success ? 🤣 In the end, the whole issue is to know how to efficiently *hash* memory. SACROSANCTAE MEMORIAE SECTIONEM IN AETERNUM VIGILEMUS
@pif5023
@pif5023 Год назад
I guess the reason is that it let’s you describe a grammar, by accident though
@CamaradaArdi
@CamaradaArdi Год назад
2:50 please elaborate
@btm1
@btm1 Год назад
What are your thoughts on "GPT Engineer" and "MetaGPT"? Do you think they will evolve in the following years to become even more capable?
@BosonCollider
@BosonCollider Год назад
Honestly python is probably nicer for this now that it has a match operator
@ChaotikmindSrc
@ChaotikmindSrc Год назад
Yeah let's write compilers in TS then wonder why a standard project takes 3 days to compile....
@howuseehim
@howuseehim Год назад
Most people don't even understand this video to begin with
@thekwoka4707
@thekwoka4707 Год назад
Strange they picked Deno over Bun. I find Bun to be the MUCH MUCH better TS scripting runtime.
@lucsoft
@lucsoft 11 месяцев назад
if you let the legacy world behind deno is really awesome, all the modern feature and also way more stable then bun
@CottidaeSEA
@CottidaeSEA Год назад
Union types is just as bad as inheritance and I'll die on this hill if necessary.
@boreddad420
@boreddad420 Год назад
javascript, I love it
@BaptistPiano
@BaptistPiano Год назад
Was that a quote from senior JavaScript engineer interview?
@Soulis98
@Soulis98 Год назад
I wouldn't recommend.
@Dev-Siri
@Dev-Siri Год назад
its ok until the compiler encounters *any*
@renat0sp
@renat0sp Год назад
ok compiler
@complexlity
@complexlity Год назад
It’s not PRE READ it’s PREAD
@freesoftwareextremist8119
@freesoftwareextremist8119 Год назад
All this TS interface generic blabla voodoo and you still need to add some hack "tag" field because you need to dispatch on the type at runtime... I sometimes wonder if people have simply forgotten that JS can do OOP and you can even write "class" if you are allergic to prototoypes. Instead of writing switches over some hacky string field, maybe use the features the language comes with (in this case, dynamic dispatch)???
@JoãoSilveira-n9m
@JoãoSilveira-n9m Год назад
Coming from OCaml without knowing any TS, this video was a complete shitshow to me 😂
@thekwoka4707
@thekwoka4707 Год назад
idk...TS can be pretty good, but this guy is making a LOT of confusing indirection...
@hfspace
@hfspace Год назад
i am a bit disappointed in you. Not the first time, that karen needed to interfere :-/
@hfspace
@hfspace Год назад
just joking ;-)
@SeriousBooster
@SeriousBooster Год назад
What the actual F is this video even about? I don't get what that code is doing
@homelessrobot
@homelessrobot Год назад
its literally in the title of the video.
@dragontos
@dragontos Год назад
wow
@vitalyl1327
@vitalyl1327 Год назад
Compilers are simplest things in existence. You can write a compiler in anything. You don't even need a Turing-complete language to write a compiler. Just pretty much any language is ok.
@jeremycoleman3282
@jeremycoleman3282 Год назад
This guys a noob. Typescript is good .. but not like this. Tbh should just use node bindings to llvm. Also fwiw , you can use generics without ever declaring a concrete type/context and the program/expression can be proven correct symbolically.
@pif5023
@pif5023 Год назад
Hot take: Java > TS
@calunsagrenejr
@calunsagrenejr Год назад
First!
@YouilAushana
@YouilAushana Год назад
Object.keys is Emotional Damage!
Далее
Have We Forgotten How To Program?? | Prime Reacts
22:53
7 Signs Of A Bad Programmer | Prime Reacts
11:27
Просмотров 400 тыс.
这位大哥以后恐怕都不敢再插队了吧…
00:16
The Truth About Code Performance (Sorry Prime)
20:03
Просмотров 121 тыс.
Jblow Talks About Rust, Jai, And More | Prime Reacts
22:50
Advanced TypeScript is Hard
13:42
Просмотров 33 тыс.
Prime Reacts: The Flaws of Inheritance
29:05
Просмотров 353 тыс.
I made a Compiler in 25 Days - Here is what I learned
40:59
TypeScript Generics are EASY once you know this
22:21
Просмотров 138 тыс.
Dependency Injection, The Best Pattern
13:16
Просмотров 833 тыс.
"We Ran Out Of Columns" - The Worst Codebase Ever
23:29
这位大哥以后恐怕都不敢再插队了吧…
00:16