Re:Ask HN: Why do many CS graduates lack foundational knowle...
by Koshkin on Monday March 20, 2023 @08:00AM
(#35230297)
Isn’t that why some other languages explicitly draw a distinction between a function and a procedure? I think ‘void’ was introduced in C to do the same thing, implicitly (because omitting the return type does not achieve that).
Re:Ask HN: Why do many CS graduates lack foundational knowle...
by WalterBright on Monday March 20, 2023 @03:26PM
(#35237233)
Yes, but Wirth (Pascal's inventor) was an academic, which is why Pascal has a separate notion of functions and procedures. `void` is a hackish special case in the type system, and not just for function returns. It's unsound.
With a sound type system, you can do things like compose a new type out of other types, and it will work consistently (not produce weird edge behaviors).
For example, C's `void` type introduces anomalous behavior. A function returning `void` is not composable, e.g.:
would work in a sound type system, but does not work in C. You'll see it in the compiler implementation because it's a special case that appears over and over.