from Hacker News

Ask HN: How can I improve my naming skills in software development?

by ryansworks on 8/4/23, 8:29 PM with 6 comments

I feel like naming variables, modules, projects, etc is half our job as developers.

I’m curious how to improve at this? As a native English speaker without a formal background in languages I wonder if studying something like linguistics would help.

  • by gorjusborg on 8/4/23, 10:25 PM

    Forget naming, it isn't the problem.

    Think about what is important about the 'thing', not just itself, but the context the importance is attached to.

    I've found that people who have a hard time with naming aren't having difficulty naming, they are having difficulty with thoughts about the item and the system that surrounds it.

    Also, don't perseverate. Learn to refactor well, choose the best name that you can given the time you can spend on it, and move forward.

    Even if you come up with the perfect name, systems and requirements change, which mean names will too.

  • by wizofaus on 8/4/23, 8:57 PM

    Honestly the most important thing is that the names convey something meaningful to the other developers working on the codebase - so if in doubt ask them! I'd also say names that are easily searchable are that much easier to work with. On that basis coming up with the simplest/shortest name possible shouldn't necessarily be your first priority, as you'll likely come up with names that are already in use all through the codebase, often for quite different purposes. And to assist with auto-complete etc it's arguably better to have the more-likely-to-be-unique part of the name near the front, though English doesn't tend to make that the natural choice, esp. for functions where you typically want to start with a verb.
  • by RobinL on 8/4/23, 8:33 PM

    I find chatgpt quite good for this. Often purely the exercise of trying to phrase the question leads to clearer thinking, and chatgpt makes pretty good suggestions too
  • by squeegee_scream on 8/4/23, 9:59 PM

    I will sometimes give an obviously temporary name, like “foo”, if I can’t immediately think of something decent. That way I’m not slowed down. Once the code works I’ll update the name. For me, it can be easier to name these things after I’m mostly finished writing the code.

    If I can’t think of a decent name I’ll mention this in a code review comment to get others’ input.

  • by austin-cheney on 8/4/23, 8:39 PM

    The naming scheme I use is file path, then lexical scope within the given file, finally the name of the local function. This forces uniqueness. I use underscores between word groups and then camel case in each word group to prevent single word artificial restrictions without harming the convention or general legibility.
  • by mytailorisrich on 8/4/23, 9:16 PM

    You're overthinking this.

    Clear, descriptive names kept short. There's no perfection, that's fine, move on.