volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Shouldn't the generated file names use dashes instead of underscores? #605

Closed bradleypeabody closed 5 years ago

bradleypeabody commented 5 years ago

I realize that due to posts like this: https://stackoverflow.com/questions/35694137/file-name-convention-for-compound-words there is a tendency to think that using underscores to separate words is a convention. However, underscores are used for build tags and related functionality like tests. Tables that end with words like "test", "windows", "js", "os" and a number of others, will produce broken output, I believe. (And you'll also find that the vast majority of the file names in the standard libraries mentioned in the post above are in fact uses of build tags, not files named after multiple words.)

To avoid this, why not use dashes as word separators? e.g. "the_table" -> the-table.go (and its test in the-table_test.go).

aarondl commented 5 years ago

While it's true that many of the filenames that use _ in the standard library are build tag related, the only examples of multi-word files with a separator in the standard library indeed use _ and not -. Though a large portion choose no separator at all. I think that in code filenames in all languages use _ as an anecdotal observation. It's also true that the sql table names themselves use the same separation so when you look for the table made by: create table the_table (...) you can find it by ctrl+p/find or what have you for the_table. These are the reasons why we originally chose the suffix.

It's also true that table names are pluralized where build tags are never (appengine, test, amd64 etc) and so the chance of conflict is much more unlikely, if you don't have pluralized table names there are naming collisions in the generated code I believe.

This is to say I'm against the change because it creates dissonance between table name and filename, and I don't think that its a problem with "properly" named tables. Note that sqlboiler is an opinionated piece of software, just like it prescribes that your FKs should be named like: othertable_id, it expects your table to be named: good_names instead of good_name since a table is a collection of those objects, not just one. If when following this naming convention there are still conflicts with build tags commonly used in Go we can think about this again.

bradleypeabody commented 5 years ago

Okay understood. Most of this I agree with, except the table pluralization - IMO while I realize a lot of people do this, I've only seen bad things come from it. The idea of just using the same name everywhere makes a lot more sense IMO (and avoids random pluralization inconsistencies in the English language from polluting your code). This is also not a huge deal breaker, so yeah, make sense to close for now and see if more attention is warranted later.