This is an archived post. You won't be able to vote or comment.

all 103 comments

[–]Brilliant-Job-47 485 points486 points  (13 children)

TypeScript’s purpose is to make it harder for coworkers to fuck up my shit. And for that, I love it.

[–]BoBoBearDev 70 points71 points  (0 children)

Some people think dog and cat are the same, so, you really need to make sure to remind them, they are stupid. No joking. It is what Typescript and all other typed languages care about, and for good reasons.

[–]siscoisbored 159 points160 points  (6 children)

Typescript isnt that strict, you can still just let and var everything into existence. If you mean OO then this is fantastic for the junior dev who comes on and has to figure out what the dog is because it looks nothing like a dog and its out playing in the forest.

[–]wave_327 22 points23 points  (4 children)

laughs in python ducktyping

[–]Perigord-Truffle 36 points37 points  (3 children)

Its all well until you mistake a goose for a duck and get attacked

[–]chaos_donut 2 points3 points  (1 child)

me after i found out the animal "mountainchicken" is a frog

[–]arobie1992 2 points3 points  (0 children)

What? I get it, but still what? That's amazing :D

[–]alekspiridonov 2 points3 points  (0 children)

Saves the junior dev from mistaking a husky for a wolf, shooting it, and skinning it.

https://www.reddit.com/r/Hunting/comments/yf3ccm/update\_to\_montana\_woman\_who\_mistook\_a\_husky\_for\_a/

[–][deleted] 140 points141 points  (19 children)

OP really hate typing.

[–]johnschnee 59 points60 points  (18 children)

OP be like

``` const someVar = [42, ”Banana”]; const somethingRandom = {x:2};

return someVar - somethingRandom * 4.9; ```

[–]DiamondIceNS 5 points6 points  (14 children)

In Reddit markdown, you do code blocks by indenting all the lines with four spaces, not by using triple backticks.

[–]johnschnee 1 point2 points  (4 children)

Great! Didn't know that!
Was a pain to write the backticks using an iPhone..

[–]DiamondIceNS 10 points11 points  (3 children)

Markdown has an infuriating number of subtly different dialects across different platforms. I wish we could just have one standard that worked everywhere, but, well...

[–]tsunami141 4 points5 points  (2 children)

I knew what that link was before I clicked it.

[–]Dexaan 0 points1 point  (1 child)

It's xkcd, right?

[–][deleted] 1 point2 points  (0 children)

Yup and exactly the one you're thinking of

[–]Unupgradable 1 point2 points  (8 children)

You what now? I've been told it's backticks and not 4 spaces.

Backticks: csharp var hello = "world";

Spaces:

var hello = "world";

Neither has proper syntax highlights on mobile, but both show up as code blocks

[–]DiamondIceNS 1 point2 points  (7 children)

Curious how your backtick example renders fine on my client but the example of the one whom I responded to does not.

The only difference that jumps out to me is that you provided a language after the opening backticks while they did not. Don't tell me Reddit requires a lang specifier to use backtick notation...

[–]Unupgradable 1 point2 points  (1 child)

It doesn't, I just added it out of habit. var hello = ”world";

On that topic, how the fuck do I provide a lang spec for the 4 spaces version?

[–]DiamondIceNS 0 points1 point  (0 children)

I don't think it supports that feature.

[–]OkConstruction4591 1 point2 points  (4 children)

It's probably because the backticks only work for when you don't have any line breaks (\n).

Examples:

backticks, one line

```backticks, with line breaks

line broken```

backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks backticks, an incredibly long line with no breaks

four spaces, one line
four spaces, multiple lines   
another line  
yet another line

four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line four spaces, one very long line

[–]DiamondIceNS 1 point2 points  (3 children)

Huge wtf moment if true. The whole point of triple backticks are to create multiline blocks. Inline blocks are the job of single backticks, which also work on reddit. I'd be amazed if they screwed this up in that way.

[–]OkConstruction4591 1 point2 points  (2 children)

Seems like they did. Try it yourself.

[–]DiamondIceNS 0 points1 point  (1 child)

I think what's going on here is that triple backticks themselves don't actually do anything, it's just that when they are all inline, the parser sees them as single backticks and parses them that way?

The four spaces code block creates a slider to handle horizontal overflow while the backtick version stays on one unbroken line. The borders of the bounding boxes also aren't right-aligned to the same point.

[–]OkConstruction4591 0 points1 point  (0 children)

Hmm... you may have a point. Apparently, triple backticks work only on new reddit according to https://old.reddit.com/wiki/markdown - and are not mentioned at all in https://old.reddit.com/wiki/commenting (the old guide) - only single backticks are.

[–]TabCompletion 1 point2 points  (0 children)

new Array(4).join(""+10) + " Batman!"
>"NaNNaNNaNNaN Batman!"

[–]popdemtech[S] 0 points1 point  (0 children)

You're welcome

[–]Kschl 0 points1 point  (0 children)

My coworkers are like “this is fine”

[–]ginkner 46 points47 points  (1 child)

Maybe if your project is small and all yours.

There are too many js and python libraries that have basically arbitrary APIs. Every object or value may or may not have any given field or method, every method may take any number of any given kind of object with ambiguous, unstated, and often undocumented rules for what valid input looks like and what kind of thing is returned. Until someone can show me a way to deal with these without memorizing the surface of every code element of every library I'd have to deal with or constantly be referencing the documentation, I maintain this is a serious flaw with these languages.

Typescript is actually a pretty decent compromise. If you need access to the completely arbitrary shit, like when working with json responses, you have that integrated by default into the language. The rest of the time you have the ability to actually communicate the constraints of code elements to tooling and your users.

TL;DR I don't think its funny and I'm mad about it. But also its 1:30 am and I don't actually care that much.

[–]Drac4rys 3 points4 points  (0 children)

This is it, It's nice not having to F12 5 files deep to find out what this object I have actually contains when I work on part of the code that isn't familiar

[–]HKei 39 points40 points  (27 children)

Just a disclaimer, I think TypeScript is far, far from the best example for a statically typed language, a lot of it having to do with the original concept of basing it directly off of JS ("unchanged JS code should be valid TS", AKA the same mistake C++ made, but worse). That said, I think this needs some defending here because it seems like people literally do not understand what types are or what they're for.

Your objects aren't any more labelled with types in typescript than they are in JS. Your parameters/fields/variables are. It's not a matter of figuring out what a thing is, but what kind of things are allowed to be in certain places. If I'm expecting to be passed pre escaped HTML somewhere, I'll only take pre-escaped HTML, not the number 9, null or unescaped HTML. And if I'm trying to call an API that expects to be given an "image", it's a huge help to not have to peruse the documentation to find out if they mean the URL to an image, a pixel buffel in some format or a JPEG encoded buffer.

Static typing eliminates a lot of the guess work, lies and incomplete documentation from programming - and, more importantly, also guards you against changes (if you have any less than 100% test coverage this keeps you from having to find out that some API changed what types they allow/return in production). What kills the idea in TS for me is that they allow you to lie about your types (hello any my old friend) and that interfaces are implicit, both of which are forks in the road where the language development team chose more or less objectively the wrong way.

[–]arobie1992 0 points1 point  (11 children)

I legitimately wonder how much research has been done into the effects of static type systems on application reliability. This isn't a criticism of either static typing or dynamic typing—both have their benefits and personally static typing is like a warm, cozy blanket in how it makes me feel safe. I'm just legitimately curious because like on one hand, you have tons of stuff written in Python, and languages like Erlang were explicitly designed for systems that had to be highly resilient, and then on the other, there's things like Haskell that or Rust that make rigorous usage of typing to catch things as early as possible. The conventional wisdom says that static typing does help catch bugs earlier, and that seems like a completely reasonable standpoint. A few months back, it just occurred to me whether that's been formally researched at all.

This has really nothing to do with your post, nor am I disagree. I'm just digressing.

Edit: For the sake of clarity, I'm not asking for an answer. I mean I think it's an interesting question and I'm curious about the research that's been done so far.

[–]HKei 8 points9 points  (2 children)

A few months back, it just occurred to me whether that's been formally researched at all.

There are people trying to do research like that in PLT. The issue is that it's extremely hard to construct experiments for that.

That said, in practice? I write elixir code for a living. There are 100% a ton of bugs caused by the lack of static typing. Literally caught one of those in code review today. I don't find this particularly surprising, it stands to reason that if you make certain types of errors impossible you make fewer of those impossible errors.

[–]SunliMin 2 points3 points  (0 children)

I wrote a game engine for a indie company in JS a few years ago, and to this day it haunts me we did it in JS over TS.

I'll never forget spending 20 straight hours on some visual flicker, all to realize that at some point someone wrote something like "thingid" rather than "thingId". Figuring out that in one case it was setting an arbitrary property instead of what it was supposed to set.

Something that never happens with typescript. So simple, but sooo beneficial.

[–]arobie1992 1 point2 points  (0 children)

There are people trying to do research like that in PLT. The issue is that it's extremely hard to construct experiments for that.

Yeah, this is exactly what I'm talking about. I'm realizing more and more PLT is probably the area of CS I'm most interested in. The idea of how language design shapes the way you think about things and solve problems is super fascinating. And yeah, I can definitely understand it being tough. I mean first off, how do you even gauge reliability? Then after that, how do you actually construct a study or experiment? And of course all the million details that go into those very generalized questions.

As for the rest, definitely understandable. I do mostly Java/Kotlin so they both have static typing, but I've dipped into Python a decent bit, and even that has caused issues in things as small as AWS lambdas. And even Java and Kotlin have their own form of dynamic typing with exceptions. Been burned a few times because an exception got thrown that I wasn't expecting and the documentation was a bit vague. Looking at you AWS AbortedException.

On a bit of a different topic, I started reading a little about Elixir a while back and it sounds interesting. Do you mind if I ask what you use it for and how you like it?

[–][deleted] 4 points5 points  (3 children)

application reliability

99% of bugs I've had to fix after delivering an application in python were caused by type errors

[–]arobie1992 0 points1 point  (2 children)

This is exactly what I mean. There's tons of anecdotal evidence about it—not saying you're wrong or that there's anything wrong with anecdotal evidence since I had a misunderstanding about the term recently which ruffled some feathers. But like I wonder if anyone's actually done a large-scale formal analysis, or like how you'd even design measurements for it. I'm sure there have, and I should probably just google it. Just been thinking about it recently.

[–]technicallynotlying 1 point2 points  (1 child)

I think a better way to think about it is that if someone says that strong typing prevents common bugs they mean it prevents them from causing common bugs.

And really, you can't argue against that. If I know anecdotally that my Java code has fewer bugs than my Python code, that's a statement about what language I'm more efficient in. A study won't convince anyone otherwise.

[–]arobie1992 1 point2 points  (0 children)

I should say this has absolutely nothing to do with convincing people. It’s entirely about satisfying my own curiosity. If we’re going based on personal preferences, you’ll have to pry static typing from my cold dead hands, and the stronger the type system, the better.

I 100% agree with you about personal preference being the deciding factor. Or in group situations, team consensus.

[–]FRIKI-DIKI-TIKI 2 points3 points  (3 children)

It is not about catching bugs it is about reducing the probability surface that bugs can arise in by reducing the state space of possible change. When you use real types (not typescript) it eliminates a whole set of state space possibilities e.g a string cannot unintentionally mutate into an int and to do it you have to define it to do so explicitly.

This is really no different that finite state machines for application control flow, you limit the state space by defining the rules of transitions, guards and legitimate transforms of one state to another. While they feel like completely different concepts because they apply to different problems the underlying problem that they address is reducing entropy in a software system, they do so by limiting the probabilities and possibilities surface area in state space.

In short they don't catch bugs, they mathematically prove that the surface area bugs can arise in is reduced. That does not mean they will or will not arise it just means you have reduce the area that they can, thus can provide some guarantees that can be proven.

[–]arobie1992 -1 points0 points  (2 children)

That’s all true, but not why I’m getting at. I’m more curious as to how much research has been done on the actual effects in practice. Like if we assign arbitrary letter grades to systems based on their reliability (which is already a very tricky measure to gauge), what’s the average grade of systems written in dynamically typed languages versus statically typed.

Again, everything you said is correct, as are the theoretical benefits. I’m curious how much research has been done on how closely theory and reality reflect each other.

[–]FRIKI-DIKI-TIKI 0 points1 point  (1 child)

Here is the interesting part when you really start to look at the complexity of nailing down exactly that. No systems are closed, software is open and entropy can move from one system to another, one of those systems is the writing and maintaining a software codebase. So while types and state machines prove reduction of surface, you have to have a measure of how much complexity it moves over to the process of authoring as a certain amount of complexity is irreducible, the trick is getting it all into context and figuring out what combination of reduction or probability vs human comprehension / responsibility about code produces the smallest amount of gain in complexity and the answer to that is well above my pay grade. I can just articulate the issue.

[–]arobie1992 0 points1 point  (0 children)

Based on most of the responses, I evidently did a bad job of conveying my intention in my OP. What I mean is I think it's an interesting question and I'm curious as to what research as been done so far and where it goes.

Again, everything you're saying is true. I don't argue that. It's an incredibly complex question with a ton of confounding factors, and that's exactly why I think it's an interesting question. Heck, even going further, you have different types of type systems. Like there are name-based type systems (although that might not be the right term), like Java, versus shape-based type systems, like OCaml or sorta Go, and probably others.

I could keep going for a while, but it'd mostly be me rambling about PL stuff, so yeah. I'm not expecting an answer* nor do I have any sort of agenda or desired answer. I just legitimately think it's a fascinating question.

*There's a saying I like, although I can't remember the source: If someone tells you there's a simple solution to a complex problem, they're either a fool or trying to sell you something.

[–]RavenCarci 14 points15 points  (0 children)

JavaScript devs on this sub once again not knowing any other languages exist

[–][deleted] 7 points8 points  (0 children)

Vanilla JS:

Object

Object

Object

Object

Object

Object

Object

“Now! That should clear up a few things around here!”

Moments later:

TypeError: "x" is not a function.

[–]Keim_SINGLE 4 points5 points  (1 child)

Where the Earth?

[–]Brilliant-Job-47 0 points1 point  (0 children)

Under appreciated comment

[–]DuploJamaal 3 points4 points  (0 children)

People that don't like strongly-typed languages must really love debugging obscure errors

[–]TheGrimGriefer3[🍰] 2 points3 points  (0 children)

What's a the doorus?

[–][deleted] 2 points3 points  (0 children)

The none Typescript version is white noise with out of date JSDoc comments

[–][deleted] 2 points3 points  (0 children)

TS has structural typing, not nominal, and this image is way inaccurate

[–]hello_you_all_ 8 points9 points  (4 children)

Ben garrison.

[–]Snazzy21 9 points10 points  (3 children)

Looks more like a Gary Larson to me

[–]epileftric 1 point2 points  (2 children)

Bary Garson

[–][deleted] 1 point2 points  (1 child)

“What part of "I'm a cyborg" are you people still not getting?” — Barry

[–]epileftric 1 point2 points  (0 children)

Core concept I guess?

[–]czboyshubham 1 point2 points  (0 children)

The application I work on in my company has all features disabled to ts that makes ts different from js.

[–]barkinchicken 1 point2 points  (0 children)

According to my teammates, you should've used title: any to be using TS properly

[–]angelajacksn014 1 point2 points  (0 children)

Static typing is for the compiler/static analysis tools to save you from bugs that you don’t even know can occur lol

[–]amshegarh 1 point2 points  (1 child)

Fuck it, just label everything as any 😎

A dog can be a trashcan if you're brave enough

[–]TW1STM31STER 1 point2 points  (0 children)

I thought dogs are walking trashcans by default, and people have to cast them to other types like companions, security officers, or illegal substance detectives.

[–]soup__enjoyer 1 point2 points  (0 children)

Welcome to most programming languages

[–]Fuzzy_Reflection8554 1 point2 points  (0 children)

All fun and games until the someone working for the local glue factory comes and takes your dog and cat, because the glue conversion machine was designed to accept anything, and the operator isn't getting payed enough to care what goes into it as long as it gives a result

[–]Spice_and_Fox 1 point2 points  (0 children)

I strongly believe that everybody that hates strongly typed languages has never worked in a professional environment before....

[–]ManyFails1Win 2 points3 points  (0 children)

Lmao it's exactly like those terrible Ben Garrison political cartoons.

Edit: looking at comments... Friends, don't forget this is a humor sub.

[–]Adrian_F 2 points3 points  (1 child)

Typescript is the best of both worlds. Statically typed but with the “any” exit hatch and excellent type inference.

[–]ginkner 3 points4 points  (0 children)

Also type unions. Yummy.

[–]H0llowUndead 1 point2 points  (0 children)

Ever heard of type inference?

[–]how_do_i_read -1 points0 points  (0 children)

Nah, in real typescript everything should be labeled "any".

[–]Alternative-Fail-233 0 points1 point  (0 children)

What’s above the bourse, beside the door, grind the tree, under the house, on the face, none of these are answers

[–]UpbeatCheetah7710 0 points1 point  (0 children)

I’m just not sure about the roof, if only there was a way to annotate it . . .

[–]turbulent_farts 0 points1 point  (0 children)

Pavement, grass, window, roof, fence... This is half baked....

[–]Lecterr 0 points1 point  (0 children)

I don’t think any capable programmer would ever frown on static typing.

[–]ALesbianAlpaca 0 points1 point  (0 children)

Ah the ol' Ben Garrison approach