• JSR_FDED a minute ago

    Using the same length of related variable names is definitely a good thing.

    Just lining things up neatly helps spot bugs.

    It’s the one thing I don’t like about strict formatters, I can no longer use spaces to line things up.

    • qouteall 2 hours ago

      With modern IDE and AI there is no need to save letters in identifier (unless too long). It should be "sizeInBytes" instead of "size". It should be "byteOffset" "elementOffset" instead of "offset".

      • pveierland 17 minutes ago

        When correctness is important I much prefer having strong types for most primitives, such that the name is focused on describing semantics of the use, and the type on how it is represented:

            struct FileNode {
                parent: NodeIndex<FileNode>,
                content_header_offset: ByteOffset,
                file_size: ByteCount,
            }
        
        Where `parent` can then only be used to index a container of `FileNode` values via the `std::ops::Index` trait.

        Strong typing of primitives also help prevent bugs like mixing up parameter ordering etc.

        • kqr 4 minutes ago

          I agree. Including the unit in the name is a form of Hungarian notation; useful when the language doesn't support defining custom types, but looks a little silly otherwise.

        • throwaway2027 2 hours ago

          Isn't that more tokens though?

          • post-it 24 minutes ago

            Only until they develop some kind of pre-AI minifier and sourcemap tool.

            • 0x457 an hour ago

              Sure you get one or two word extra worth of tokens, but you save a lot more compute and time figuring what exactly this offset is.

              • Onavo an hour ago

                Not significantly, it's one word.

            • akdor1154 6 minutes ago

              The 'same length for complementary names' thing is great.

              • wahern 3 hours ago

                Relatedly, a survey of array nomenclature was performed for the ISO C committee when choosing the name of the new countof operator: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3469.htm

                It was originally proposed as lengthof, but the results of the public poll and the ambiguity convinced the committee to choose countof, instead.

                • dataflow 3 hours ago

                  Is there any other example of "length" meaning "byte length", or is it just Rust just being confusing? I've never seen this elsewhere.

                  Offset is ordinarily just a difference of two indices. In a container I don't recall seeing it implicitly refer to byte offset.

                  • SabrinaJewson 3 hours ago

                    In general in Rust, “length” refers to “count”. If you view strings as being sequences of Unicode scalar values, then it might seem odd that `str::len` counts bytes, but if you view strings as being a subset of byte slices it makes perfect sense that it gives the number of UTF-8 code units (and it is analoguous to, say, how Javascript uses `.length` to return the number of UTF-16 code units). So I think it depends on perspective.

                    • wyldfire an hour ago

                      A length could refer to lots of different units - elements, pages, sectors, blocks, N-aligned bytes, kbytes, characters, etc.

                      Always good to qualify your identifiers with units IMO (or types that reflect units).

                      • AlotOfReading 3 hours ago

                        It's the usual convention for systems programming languages and has been for decades, e.g. strlen() and std::string.length(). Byte length is also just more useful in many cases.

                      • card_zero 3 hours ago

                        I can't read the starts of any lines, the entire page is offset about 100 pixels to the left. :) Best viewed in Lynx?

                        • zephen 2 hours ago

                          The invariant of index < count, of course, only works when using Djikstra's half-open indexing standard, which seems to have a few very vocal detractors.

                          • GolDDranks an hour ago

                            Fortunately only a few. Djikstra's is obviously the most reasonable system.