logoalt Hacker News

qouteallyesterday at 5:05 AM5 repliesview on HN

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".


Replies

pveierlandyesterday at 6:48 AM

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.

show 1 reply
groundzeros2015yesterday at 7:41 AM

Long names become burdensome to read when they are used frequently in the same context

layer8yesterday at 6:47 PM

When you’re juggling inputBufferSizeInBytes, outputBufferSizeInBytes, intermediateRepresentationBufferSizeInBytes, it becomes unwieldy and cumbersome.

I once had a coworker like that, whose identifiers often stretched into the 30-50 characters range.You really don’t want that.

ivanjermakovyesterday at 10:06 AM

When the same name is used a thousand times in a codebase, shorter names start to make sense. See aviation manuals or business documentation, how abbreviation-dense they are.

throwaway2027yesterday at 5:33 AM

Isn't that more tokens though?

show 3 replies