5 ms·
Other candidates: - null terminated strings - machine dependent integer widths
by ohazi 8y ago
Other candidates:
- null terminated strings
- machine dependent integer widths
- DaiPlusPlus 8y agoNull-terminated strings are useful for buffering values of unknown length (e.g. copying from a network stream). Length-prefixed strings have issues of their own (e.g. what size length prefix to use, efficient encoding of variable-length integer prefixes, what happens if a length-prefixed string's calculated end-position is outside the process' memory space?)
- thaumasiotes 8y ago> Null-terminated strings are useful for buffering values of unknown length (e.g. copying from a network stream). That doesn't seem like a good example. The data arriving over the network arrives length-prefixed, because 0 is a legal byte value for arbitrary data. What do you then gain by throwing away your existing knowledge of the length?
- saagarjha 8y ago> null terminated strings This is mentioned. > machine dependent integer widths What exactly do you dislike about this?
- rusk 8y ago> What exactly do you dislike about this? Or what do you even do about it? A handful of solutions already exist: - Use a higher-level language - Java
- Dylan16807 8y ago> Or what do you even do about it? All you need is a list of what width each type is. > A handful of solutions already exist: - Use a higher-level language - Java It doesn't require being "higher level". If anything it pushes code to a slightly lower level.
- rusk 8y ago> All you need is a list of what width each type is. This is exactly the kind of minutiae that GP was bemoaning. > If anything it pushes code to a slightly lower level Yeah by way of higher-level abstractions ...
- bfrydl 8y ago> This is exactly the kind of minutiae that GP was bemoaning. How is this “minutiae”? You should always know the possible range of a numeric variable or field when you create it, so why not just write what size it is? In Rust the main numeric types look like this: i32, u64, u8. You just pick the one you want.
- kiriakasis 8y agothe main numeric type is usize
- steveklabnik 8y agoThat’s not correct, it’s i32. usize has a specific purpose: when you need a length of something in memory.
- shittyadmin 8y agoThe entire idea of a "main numeric type" is sort of silly - know what data you're dealing with and pick the length accordingly!
- steveklabnik 8y agoYeah, I only say "main" here because it's what you should pick if you're not sure.
- rusk 8y agoI'm sorry, I misunderstood you. These typedefs as I'm used to them do address cross-platform issues. Storage classes are "minutiae" however when all you want is just a straight up number. Python gives me an Integer type when I want a whole number, or a Float when I want to represent partials. I don't really care to be honest how that gets represented in memory in this case.
- pjc50 8y agoIt's an area of the language which can produce "works on my machine" bugs? It becomes less important as we all converge on 64-bit machines with 32-bit "int" types, but it's still a monumental pain point for portability.
- altmind 8y agoI came here to write that ASCIIZ is the more costly design decision than null, that not only led to crashing programs, but also to security vulnerabilities, sloppy APIs that cannot handle "binary data" and subpar performance.
- deleted 8y ago[deleted]