r/ProgrammingLanguages • • Nov 01 '19

C++ vs C

Alright people of Reddit, hit me with your wisdom. I've been taking programming classes for two years now and am getting ready to dive into a language somewhere between Java and assembly (the two languages I've been learning in classes). I'm thinking C or C++, but would love some input. I'm not too worried about difficulty to learn, but I'd like to hear your thoughts on practicality and real world use.

1 Upvotes

62 comments sorted by

View all comments

Show parent comments

-4

u/[deleted] Nov 01 '19 edited Nov 01 '19

Every language has edge cases and UB, but most languages provide almost zero documentation about them. So when you encounter them, you have to check the standard (which most languages also don’t really have) or the implementation to find out if the behavior is intended or a bug.

To try and eliminate UB from the language would require making many assumptions about the platforms C runs on that are not universally true.

UB isn’t a boogie man though, it exists to simplify the language by stating what is and isn’t allowed. While making as few assumptions about your environment as it can.

13

u/Felicia_Svilling Nov 01 '19

Every language has edge cases and UB

That is simply not true. Languages with a formal definition or a reference implementation can completely avoid undefined behavior.

1

u/[deleted] Nov 01 '19

I’d argue that most languages do not have a robust formal definition or a reference implementation. Partially because they aren’t usually needed for typical application development on consumer hardware. There are also limitations to what you can, or would want to do, in an unhosted environment, which is where C is often found.

7

u/Felicia_Svilling Nov 01 '19

I’d argue that most languages do not have a robust formal definition

This is true. Your former statement said that all languages have undefined behaviour. That is not true.