r/programming • • Nov 11 '22

NSA urges orgs to use memory-safe programming languages - C/C++ on the bench, as NSA puts its trust in Rust, C#, Go, Java, Ruby and Swift

https://www.theregister.com/2022/11/11/nsa_urges_orgs_to_use/
4.2k Upvotes

799 comments sorted by

View all comments

Show parent comments

9

u/TheChance Nov 11 '22

Typehints are wonderful, but they aren’t enforced by the interpreter.

3

u/anon_tobin Nov 11 '22 edited Mar 29 '24

[Removed due to Reddit API changes]

5

u/TheChance Nov 11 '22

It’s not always worth going back and adding them to old code, but the effect when they’re present from the get-go is dramatic. Just getting the right type under your cursor in an editor is a big QoL improvement, and the only “cost” incurred, apart from a few keystrokes, is having to think about your data before it crashes.

2

u/pudds Nov 12 '22

I do, 2 seconds of extra typing makes using those functions and variables far nicer, and it helps VSCode show possible errors and useful suggestions.

I don't usually bother with mypy, but I still add hints just to make working with my code easier.

At this point I'm hesitant to use any library that doesn't come with good type hinting.

0

u/[deleted] Nov 11 '22

[deleted]

1

u/anon_tobin Nov 11 '22 edited Mar 29 '24

[Removed due to Reddit API changes]

2

u/[deleted] Nov 11 '22

By enforced you mean typechecked like TSC does?

1

u/TheChance Nov 11 '22

I mean the interpreter ignores them in every way. There’s nothing you can do, to my knowledge, to get them to shout at runtime if a type is wrong.

Your editor, however, can do a lot in that regard, and so can some test setups.

1

u/____0____0____ Nov 11 '22

Not true. You can read type annotions at runtime and do whatever you will with them like compare the expected type to the running type. Any 3rd party tooling could enforce as strict typing as it wants. I'm guessing this is how mypy operates, but I've never looked at it.

1

u/TheChance Nov 11 '22

Right. But the interpreter doesn’t do it for you. And that brings us full circle.

1

u/[deleted] Nov 12 '22

Types are not checked at runtime in strongly-typed compiled languages, either.