Whenever you store a value that has a unit in a variable, config option or CLI switch, include the unit in the name. So:

  • maxRequestSize => maxRequestSizeBytes
  • elapsedTime => elapsedSeconds
  • cacheSize => cacheSizeMB
  • chargingTime => chargingTimeHours
  • fileSizeLimit => fileSizeLimitGB
  • temperatureThreshold => temperatureThresholdCelsius
  • diskSpace => diskSpaceTerabytes
  • flightAltitude => flightAltitudeFeet
  • monitorRefreshRate => monitorRefreshRateHz
  • serverResponseTimeout => serverResponseTimeoutMs
  • connectionSpeed => connectionSpeedMbps

EDIT: I know it’s better to use types to represent units. Please don’t write yet another comment about it. You can find my response to that point here: https://programming.dev/comment/219329

  • state_electrician
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    4
    ·
    1 year ago

    Variables, meh. As long as the code is clear, I don’t mind too much about naming. For config options? Absolutely.

    • deadcream@kbin.social
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      I disagree. Every time I see duration: Long in code I want to find whoever wrote that and bash them on the head because what the fact this Long is? If unit is not immediately obvious in some way in current context (not necessarily as variable name), your code is not clear, period.