google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library

Home Page:https://flatbuffers.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Package names in generated Kotlin code should be lowercase

pnq32 opened this issue · comments

commented

According to the FlatBuffers style guide, namespaces should be formatted using upper camel case. For example:

namespace MyGame.Sample;

When compiling this schema for Kotlin using flatc version 2.0.0, the generated files have the following package specification:

package MyGame.Sample

Unfortunately, this violates Kotlin's coding conventions:

Names of packages are always lowercase and do not use underscores (org.example.project). Using multi-word names is generally discouraged, but if you do need to use multiple words, you can either just concatenate them together or use camel case (org.example.myProject).

This seems to encourage Kotlin developers to use lowercase names in the original namespace declarations, which is obviously not ideal. Therefore, I would argue that uppercase namespace literals should be translated to lowercase (or camel-case) Kotlin packages, just as it is done with snake-case field names.

In #4972, this was already discussed for the Java case. Due to the fact that Java packages are directly tied to the directory structure, however, no suitable solution could be found. For the Kotlin case, this limitation is gone:

It is not required to match directories and packages: source files can be placed arbitrarily in the file system.

Coming back to the initial example, I think it would be preferable to keep placing the files into MyGame/Sample, while beginning them with package myGame.sample. Possibly with a command-line option that can be used to get the current behavior back. What do you think?

Note: That way, users who want to stick to the recommendation that the directory structure should follow the package structure with the root package omitted would have to perform some copying, but they would have to do so to get rid of the directories representing the common root package one way or the other.

I think this is fine, if you want to do a PR for it. Each language should output things in the preferred style of the language, so it sounds like this is a short coming in Kotlin.

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.