Live data from Hacker News

How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

chiragswadia.medium.com

291–300 of 400 posts

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#291
post #276
post #122

Earlier quoted context omitted.

Ironically, as someone who has experience w/ both fast-and-loose JS and with "properly" statically typed languages, my beef with typescript is precisely that it allows people to be fast and loose, sometimes in ways that are not super obvious. For example: type Thing = { name: string, }; function getThing(): Thing { return JSON.parse('{"error": "invalid id"}') } const thing: Thing = getThing(); // lie to me! console.l…

Wait... so I assume `JSON.parse()` returns `any`, yeah? TS automatically downcasts (in function returns and assignment)? How is that at all useful?

It's a historical artifact of Typescript's development. The `unknown` type wasn't introduced until Typescript 3.0 and since `JSON.parse` is part of the Javascript "standard library," changing it now would be a brutal breaking change across almost the entire ecosystem.

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#292
post #122

Earlier quoted context omitted.

Ironically, as someone who has experience w/ both fast-and-loose JS and with "properly" statically typed languages, my beef with typescript is precisely that it allows people to be fast and loose, sometimes in ways that are not super obvious. For example: type Thing = { name: string, }; function getThing(): Thing { return JSON.parse('{"error": "invalid id"}') } const thing: Thing = getThing(); // lie to me! console.l…

Sure, but you also should never just blindly trust a JSON.parse, and if possible you should avoid typing functions for exactly this reason, and let their return types be implied instead. If you didn't type `getThing` then its return type would be `any` and you'd get an error in your IDE on the last line.

If you don't annotate the return value you open yourself up to another class of mistakes because the compiler can't check that each branch returns the correct type, especially if type inference decides the function returns `any` which swallows `undefined` in type hints, while also losing the self-documenting aspect without an IDE.

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#293
post #192

Earlier quoted context omitted.

JS the language isn't great but it's JS the culture that is the real problem. There is a subset of JS codebases that are good, well engineered and written by people that understand the languages faults and limitations but the list is incredibly small and even smaller still now Joyent isn't really around anymore. If there was one ecosystem I wish I never needed to touch again it would be JS but unfortunately it's beco…

>JS the language isn't great but it's JS the culture that is the real problem. I'm happy you bring this up. Us developers have a tendency to blame bad code on poor tooling/languages or on individual developers or organizations. Not enough attention is given to cultural factors within various ecosystems that systemically induce bad coding practices.

Also worth mentioning that the tooling and language follows the culture to a degree.

Java has incredibly high quality tooling because the engineering culture demands it. (also they tend to pay for it which creates a market. I myself pay maybe ~$400/yr total for my professional tools, Jetbrains Toolbox, Yourkit, etc)

The changes to the language and runtime also follow from this.

I would say Java and it's periphery ecosystems show the most promise in 2020 bar maybe Rust. There is also great things going on in C#/.NET space but I'm less involved there than I was previously so can't speak to how fast it's moving.

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#294

Earlier quoted context omitted.

>The author isn't claiming to have had an informed opinion of types. They're saying that they found learning about types to be difficult and stressful. That's a real problem that I think people who understand types forget. Respectfully, its really hard for me to wrap my head around this mindset. When I wrote my first line of code, almost 10 years ago, one of the very first concepts I learned was types. You know the b…

A move at my alma mater to switch the introductory course from Java to Python was criticized on the same grounds. The students had a hard time in successive levels of coursework. It seems to be a lot harder to get people who learn dynamic typing first to learn static typing, than the other way around.

It's dangerous to assume that the same number of people will continue programming if you start people on dynamic vs static typing. Maybe the static first programs weed out more people?

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#295
I tried using typescritp with vim, the setup was painful; flow in the other hand was pretty straight forward; I'm considering moving to flow because of this and also because we can have contributors not familiar with typescript helping the code base grow.

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#297

It's probably worth taking a step back and interrogating why the actual "Why was I Anti-TypeScript?" a little bit more and use it as an opportunity for broader self development. The author didn't use and understand something, and rather than trying to they instead just defaulted to rejection. It's midly disapointing seeing this in people who label themselves as "Senior".

Senior probably means they've been doing JS for decades before TS was invented. They got along just fine without it for so many years, why rock the boat now? Or maybe it is more of a Senior person has a ton of work to do and not enough time to do it in so there isn't time left to learn a whole new way of writing JS. Or maybe many of the errors TS is meant to catch, the Senior developer has already learned over the de…

I've been programming JS for 13 years (professionally, and some more as a hobby) and I'm pretty aware of its warts. And as a firm believer of TDD, most of my code is pretty well tested.

Unit tests have similar advantages to types: they catch errors early and let you refactor your code with confidence.

But unit tests go even further, because they test the _correctness_ of the returned value, not just its type.

And a massive turnoff for me is that the types are compile-time only.

So you see, if your code is tested, and the types are just partial static checks; I feel like it's just not worth it.

I enjoy using types in other languages, for example it feels nice to add type hinting to old PHP codebases. But in PHP, types are much simpler (less work) and more effective.

If they added optional run-time instrumentation like "spec" in Clojure, I would definitely use TS. But for now, I'm out.

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#298

Earlier quoted context omitted.

A move at my alma mater to switch the introductory course from Java to Python was criticized on the same grounds. The students had a hard time in successive levels of coursework. It seems to be a lot harder to get people who learn dynamic typing first to learn static typing, than the other way around.

It's dangerous to assume that the same number of people will continue programming if you start people on dynamic vs static typing. Maybe the static first programs weed out more people?

The anecdotal information I heard was that in general there were less people adjusting to later coursework successfully, in absolute numbers.

From a pedagogical standpoint, if the point of an undergrad education was to produce people with well-rounded abilities in their field, I don't know that switching introductory courses to Python was the best move.

Personally, I'm thankful that the first program I was enrolled in allowed me to "fail" fast, so that I quickly figured out that I shouldn't really waste more time and energy into the program and switched into CS. It's a lot easier to pivot as a freshman in your second semester than as a junior finishing the academic year. (And I knew people who took that long to switch majors, who either spent way more time and money or dropped out.)

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#299

The other benefit is refactoring. That saying which goes along the lines of: "you're going to be reading a lot more code than writing it" is very true. After your project gets to a certain size, and it need not be large, you start making smaller changes and moving code around -- having some guard rails there is a huge productivity boost. Being able to read code and know that it does what it says because you know the…

I don't really buy this argument about readability because the sort of information stored in types very quickly becomes pretty meaningless for humans. I remember working on a Haskell codebase and getting into an argument about this with a developer who was very much in the typed language camp. Then I saw a function that had like 8 parameters, some were just String, or Int, some where synonyms, and I asked him what it…

[deleted]

Re: How an Anti-TypeScript “JavaScript developer” like me became a TypeScript fan

#300
post #219
post #192

Earlier quoted context omitted.

JS the language isn't great but it's JS the culture that is the real problem. There is a subset of JS codebases that are good, well engineered and written by people that understand the languages faults and limitations but the list is incredibly small and even smaller still now Joyent isn't really around anymore. If there was one ecosystem I wish I never needed to touch again it would be JS but unfortunately it's beco…

> JS the language isn't great but it's JS the culture that is the real problem. This is the money quote of the thread for me. From the perspective of someone whose main language has been JS or TS for about 8 years, it's getting worse since some of the biggest names in the discipline just seem to be people with large social followings giving terrible advice. This advice is then eaten up by hoardes of bootcamp alumni w…

Its not just bootcamp alumni, frontend is filled with people with 15 years of experience who were sitting in some shop before the frontend boom basically being a jQuery engineer and never actually learning about software design, never mind basic computer science concepts. Then the boom came and now these types are managers and senior engineers who only know how to talk about "which framework?" as far as design goes and who are eager to call any other discussion as over-engineering.
Post reply on HN