Best practices for naming variables etc

I’m new to Hugo and I’m wondering if there are some best practices / recommendations for naming variables etc.

Knowing Hugo itself uses e.g.:

.Site.BaseURL
.Site.Data
.Site.DisqusShortname

it seems to use PascalCase.

Is it recommended to follow up on that? e.g. using:

.Site.Data.Persons.Person123.Firstname

However looking at the frontmatter vars it seems camelCase:

draft: true
publishDate: 2020-05-10T18:00:15+02:00

I’m trying to to build my site with some consistency and I guess Hugo itself use some convention for PascalCase vs camelCase at different places?

The reason why the above looks like it does is because that is Go’s way of exporting fields/methods in a struct (BaseURL is a method, I think) – if if was camelCase, you would not see it.

My 50 cents on this is that I

  • Prefer camelCase
  • But for a new project, I wold probably recommend lower case snake_case.

You remove a whole giant set of potential upper/lower case issues by going the lower snake_case route.

1 Like

I second that_motion.

Thanks!

Interesting :slight_smile:

My json data files are indeed snake case as well.
But it felt quite inconsistent when doing something like:

---
engineManufacturerId: audi
---

{{ $engineManufacturer := index .Site.Data "engine-manufacturers" .Page.Params.engineManufacturerId }}

Full name: {{ $engineManufacturer.full_name }}

This way it’s quite a mix of namings :slight_smile:

Its a new project so I probably will follow your advise by using snake case like:

---
engine_manufacturer_id: audi
---

{{ $engine_manufacturer := index .Site.Data.engine_manufacturers .Page.Params.engine_manufacturer_id }}

Full name: {{ $engine_manufacturer.full_name }}

Then my own vars, data and other namings are consistent.
The only exception are then some hugo vars but I can live with that :slight_smile: