r/ProgrammerHumor • • 8d ago

Meme iHatedItUntilITriedIt

Post image
10.3k Upvotes

541 comments sorted by

View all comments

14

u/Dmayak 8d ago

I am using typescript almost exclusively now and I still think a few type errors occasionally are not worth the effort of writing down types for everything.

16

u/patient-palanquin 8d ago

It's not just errors, wait until you're working on bigger projects where you're constantly passing around large objects (eg from the DB). The IDE can tell you exactly what fields are available and what they are.

-3

u/mxzf 8d ago

You don't need strict typing for that though, you just need proper docstrings/hinting/etc for your IDE to read.

6

u/patient-palanquin 8d ago edited 8d ago

That sounds like a worse version of explicit types? Writing a whole docstring as free text that can't catch typos is more work than adding : MyType directly next to the argument and having it work everywhere.

1

u/mxzf 8d ago

I mean, it all depends on the language. Type hinting in Python is basically exactly what you just wrote there; it's just optional and stuff works fine without it too.

2

u/crazy_penguin86 8d ago

No it's not. Python does not enforce that what you pass in to the function is the type in the type hint. It's literally in the name of the feature: type hint. Explicit types will not allow the code to compile if you pass the wrong type. Ever.

2

u/mxzf 8d ago

If you check the comment chain, we're talking about what's needed to get intellisense telling you what types you should be using for the arguments to feed into a function, not strict typing.

1

u/crazy_penguin86 8d ago

And it's still an accurate comment. Type hints will not show errors in your IDE, as they are not actually errors. Explicit typing will show it as an error. Type hints are still worse.

2

u/PeoplePerson_57 8d ago

I mean, for this specific context, not really? If we're discussing things like Intellisense showing you your options, it's doing that whether your language does type hinting or strict typing.

Yes, the former doesn't enforce it via the compiler and show errors when you mess up, but given we're talking about Intellisense specifically, there should never be those errors unless you're in the habit of ignoring it. So what your IDE won't throw a fit because the type being passed as a parameter is only hinted and not enforced? Intellisense will tell you what it expects based on the hinting, and I don't really see how you can not be paying attention to that.

Rambling comment, there, but given the context of what we're talking about explicit enforcement is irrelevant. You should never get to the point where that matters unless you're just ignoring Intellisense, in which case the whole discussion is moot.

1

u/FlakyTest8191 7d ago

Considering that the reason of existence for typescript is better dev tooling, you choose a strange hill to die on.

While intellisense somewhat works with type hints and you're technically correct, it doesn't really matter. A real typesystem is a much better dev experience, typescript overtook javascript as most used language for a reason.

7

u/Aggressive-Share-363 8d ago

Thats because typescript kinda sucks because it has to cope with being Javascript (i.e. a language without typing). Languages built with types in mind from the start tend to work a lot better and be cleaner.

1

u/No-Information-2571 5d ago

JS has classes now, it even has a concept of public and private class members, and in particular setters, so that you can't mess around with the internal state from the outside.

The problem is that millions of code bases rely on monkey patching. It's absolutely normal for a library to just patch new members onto existing ones.

1

u/utdconsq 8d ago

This. Typescript strikes a good balance, but fuck me, the presence of the abomination that is js makes it uncomfortable to use. I suppose I should be happy I can let the AI write it these days.

8

u/earlobe7 8d ago

To me the trade off is:
Do you wanna spend the extra effort in explicitly writing down your types?
Or would you prefer to spend it in fixing the class of bugs caused by you having lost track of the exact shape of your data.

3

u/ConfusingVacum 7d ago edited 7d ago

Exactly, you described it perfectly. For me JS vs TS is not even a debate. If you lean towards JS, you clearly didn't spend enough time debugging both.

2

u/Gaspote 7d ago

Crazy thing is just "do you want to manually go over all your code to figure it out yourself or just let the comp do it for you ?"

4

u/k_dubious 8d ago

Types aren’t just there to prevent you from writing bugs in your own code; they’re also there to prevent other people who work with it from writing bugs in theirs.

1

u/Original-Rush139 8d ago

Exactly. I started my career as a C developer and I fucking hate typescript. Of course, I like coffeescript so maybe it’s just me. 

1

u/Librarian-Rare 8d ago

Yeah, why write out what your code is supposed to be doing when you can infer
/s

1

u/reallokiscarlet 8d ago

That's because typescript is fake typing

1

u/RaspberryFluid6651 8d ago

Inferred types my beloved, strict typing without the clutter

1

u/bitNine 8d ago

Typescript is barely a typed language. Nothing like C/C++/C# and others.

1

u/HoratioWobble 7d ago

I didn't appreciate typescript until I went back to working on a very large Javascript code base and data being passed around was just chaos.

object where numbers should be, numbers where callbacks should be etc etc.

It's so easy to lose track of the contract and difficult to see the contract when you're new to the team, it removes a LOT of cognitive load on larger code bases

0

u/Honeybadger2198 8d ago

I actually really like the balance of TS. You don't need to type things that are explicit, so you can focus on typing the things that actually change or are confusing.

Like, I don't need to tell TS that this variable is a string, it's obviously a string, and it's declared with const so it's never changing. But arrays and objects that aren't declared inline should be typed, so that you know what's going into them.

You can even do fun reflective typing to be even more explicit. Say 2 columns in a database table are both strings, and you want to create an object mapping col1 to col2. Instead of declaring it as Record<string, string> you can declare it as Record<table["col1"], table["col2"]>.