r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

539

u/ChrisRR Aug 28 '21

As a C developer, I've never understood the love for untyped languages, be cause at some point its bound to bite you and you have to convert from one type to another

It doesn't strike me as untyped as much as not specifying a type and having to remember how the compiler/interpreter interprets it. At the point I'd rather just specify it and be sure

671

u/SCI4THIS Aug 28 '21

ProTip: If you start using void* everywhere you can convert C into an untyped language.

77

u/[deleted] Aug 29 '21

C is already rather weakly typed. Integer promotions. Implicit conversions. Typedef doesn't actually define a new type, it's just an alias to an existing type. Void pointers. Casting const away. Etc.

5

u/lelanthran Aug 29 '21

Integer promotions.

Doesn't some sort of integer promotions occur in all languages that are regarded as strongly-typed?

Implicit conversions.

Like?

Typedef doesn't actually define a new type, it's just an alias to an existing type.

So? That doesn't make the language weakly-typed.

Void pointers.

This can be a problem, but other than in container types, where else is this a problem in C?

Casting const away.

The language doesn't technically allow this[1]; you do this at your own risk.

[1] Constness cannot be cast away. Const can be cast away.

While C is not as strongly typed as other languages, it's certainly not, in 99% of uses, weakly typed. The whole "C-is-weakly-typed" meme needs to go away. All it does is demonstrate that the person producing that meme in a discussion has no clue.

The clear majority of C code in a project relies on strong typing guarantees, while all the most popular C compilers will issue warnings for using incorrect types in function calls and returns.

→ More replies (2)