3 ms·
Byte streams are "untyped and unchecked" too, but that's because typing and checking can be deferred to a higher layer in the stack. I.e. one could easily defi
by zozbot234 4y ago
Byte streams are "untyped and unchecked" too, but that's because typing and checking can be deferred to a higher layer in the stack. I.e. one could easily define a typed IDL to provide a semantics over these bare text streams. No different from how most languages provide type checking over, e.g. ABI-standard subroutine calls.
- qubex 4y agoOr how types in typed languages are expressed by in-stream sequences in the source-code made implemented in untyped text files.
- IshKebab 4y agoRight, but if you're going to have a higher layer that presents a nicely typed interface why use a text-based interface in the first place? It's just an opportunity for inefficiency and bugs. The fact that you can paper over a bad interface doesn't mean it isn't a bad interface.
- cropcirclbureau 4y agoUnless your OS is virtual machine that checks the structure of the user program, at some point, your typed data will have to be a set of numbers and/or a byte stream. Granted, the set of numbers required for utf-8 `connect` is a little less efficient than your system call no. but that's hardly a highly typed API. Anything with less mechanical sympathy that's designed for _any_ user program to access it will have to pay similar costs.
- IshKebab 4y agoIt's not highly typed no, but it does force the use of a highly typed API. How many languages provide a string-based interface to the connect() syscall?
- cropcirclbureau 4y agoLanguages and kernels don't exactly have the same design considerations. Types and compilers are trying to help you write valid programs for your benefit. A kernel only has access to machine code representation of your possibly buggy or malicious program. Sure, your language or libc might provide a convenient and object based API to the kernel but these are just wrappers over the basic number and pointer to C struct soups based syscall APIs that machine code can interface with. I.e. there's nothing exactly preventing you from providing the wrong numbers and bad structs aside from the "higher layer in the stack". At least you're allowed to mispell `cnect` accessibly so from the shell. There are ways around this ofc like the Android Runtime that requires any code that interfaces with it to be written in Java adjacent bytecode that gets compiled to machine code (and cached) by the runtime (after being checked I imagine).
- IshKebab 4y ago> there's nothing exactly preventing you from providing the wrong numbers and bad structs aside from the "higher layer in the stack" Right, mistakes are possible in both cases. But why pick the design that is more likely to lead to mistakes (on both sides of the interface) and is slower? There's just no good reason to do it like that.