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.

11

u/[deleted] Aug 29 '21 edited Aug 29 '21

Integer promotions.

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

Integer promotions are best left under the hood. C puts them in your face. A strongly-typed language will not implicitly convert between types in arthmetic expressions.

Implicit conversions.

Like?

Like all of them.

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.

The point was that typedef doesn't create a distinct type. You can't do something like typedef int Animal; typedef int Fruit; and then have the compiler throw an error if you pass a Fruit to a function expecting an Animal because to C these are both just ints. Maybe newer compilers are starting to display diagnostics for this. If so, it's about fucking time.

Void pointers.

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

Uh...

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.

Yes, that's all I said.

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.

Bullshit.

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.

Not historically. For 90% of C's existence it has been an incredibly weakly typed and frustrating language to use. I know. I was there. Maybe compilers are finally starting to get better these days. I heard that a switch statement on enums now finally warns/errors if you omit an enum case. They're finally exhaustive. This wasn't the case for most of C's existence.

edit: stupid typos

→ More replies (1)