3 ms·
Who needs type safety when we got integers.
by zokier 12y ago
Who needs type safety when we got integers.
- zxcdw 12y agoWho even wants that? When I am coding, sure as hell some compiler vendor won't be telling me what to use my bits for! I identify myself as an atypical coder.
- kazinator 12y agoIf you tell yourself what the bits are for and stick to it, that is still type. Real chaos is when even you don't.
- deleted 12y ago[deleted]
- AnimalMuppet 12y agoIs this just using some vague connection to ride on one of your favorite hobby horses? Or does this have a connection to the article, and I missed it?
- GhotiFish 12y agowell you're no fun.
- mkehrt 12y agoThe problem is that C and POSXIX don't (idiomatically) provide rich enough data types force checking the error condition. The fact that the error is signaled by a random integer (-1) is horrible. In a language with stronger types and richer data structures, one can have a return type that is a disjunction of {failure, parent, child}, so you can never accidentally treat a failure as a PID. In a functional language this would look like a datatype (essentially a generalized enum), while an OO language you would use different subclasses of a common superclass. In C you can return a tagged union and check the tag, but nothing forces you to do the check. A user of this API can just go ahead and assume the success branch of the union. Furthermore, this isn't idiomatic POSIX, so it is never done. [edit: "subclass" -> "superclass"]
- dllthomas 12y agoYou could return a pointer or null. That would successfully force the "did it succeed" check, but of course raises questions about memory management. Tagged union is probably the best approach. It doesn't prevent skipping the check, but it at least makes "thing I am supposed to use" different than "thing I am supposed to check".
- nathan_long 12y agoRaising an exception would also work.