joffrey-bion / livedoc

A not-so-annotation-based documentation generator for REST and websocket services
MIT License
4 stars 2 forks source link

Remove common suffixes #119

Open ST-DDT opened 6 years ago

ST-DDT commented 6 years ago

The java classes usually have suffixes based on their type.

These suffixes might be:

These suffixes don't add any value to the documentation (only noise) and thus are removed by me.

Currently you have to annotate all of those classes to omit this suffix. (Which adds noise to the source code)

Suggestion

Have a built in list of common suffixes that should be removed.

Alternative

Allow specifying a custom post processor, that can replace project specific suffixes. (This is already possible (but complex), if you just use a custom JsonLiveDocController, that cleans the result of the original one)

joffrey-bion commented 6 years ago

Interesting. I'm usually against systematic suffixes/prefixes in my own projects, because as you said they add noise, and not only to the doc but to the code itself, especially for -DTO. Usually, packages are sufficient to avoid having to use prefixes/suffixes. If the name of the type makes sense without the suffix from the documentation's point of view, then why not remove it from the code itself? On the other hand, we could imagine situations where such a suffix is used for a reason and we dont want to remove it, like a custom map type ThingByEndpoint mapping Endpoints to things. I guess that is why I would rather not enable prefixes/suffixes removal by default.

Regarding the -Controller suffix, it is actually necessary to describe what the class is (BookController is not a book, it is a thing that manages requests regarding books, whereas BookDTO is in fact just a book, the fact that it is serialized and sent is independent from the fact that it is a description of a book). In the case of the controller, simply removing the suffix is kinda confusing because we would be writing "Book" when talking about the "Book API". But here, replacing the -Controller suffix by API could indeed make sense and look nicer in the doc.

In any case, I like the idea to make post-processing of the data easier, even if, as you said, it is already doable using a custom controller to serve the Livedoc. For instance, we could provide a generic post-processor interface and a few built-in implementations like prefix/suffix removers for instance. By default, they would not be added, but the user could add them easily in Livedoc's configuration.

The goal would be to enable the user to customize Livedoc with an effort that is proportional to how much you change the default behaviour. Overriding names should not require a hundred annotations, nor should it require the user to visit the whole doc structure to update tiny bits.

ST-DDT commented 6 years ago

Interesting. I'm usually against systematic suffixes/prefixes in my own projects, because as you said they add noise, and not only to the doc but to the code itself, especially for -DTO.

Is there a good online resource explaining/showcasing you naming schema? I currently review what I consider best practice, so I'm interested in other concepts as well.

joffrey-bion commented 6 years ago

Is there a good online resource explaining/showcasing you naming schema? I currently review what I consider best practice, so I'm interested in other concepts as well.

Sorry I had forgotten to answer your question in this respect. I don't know of any online resources about this, I'm sorry. I tend to follow the Clean Code philosophy from "Uncle Bob" (aka Robert Martin), but I don't know his stance on systematic suffixes. I've just seen too many MyInterface + MyInterfaceImpl pairs and they annoy me everyday at work. That's why I'm against suffixes by default, unless there is a good reason to have one.

Inevitably, a given type from the domain may need to be represented in different shapes depending on where it is used (as DTO for 1 or 2 different APIs, as internal domain model, etc.). I'm usually in favor of using packages properly to classify these representations of the same thing, while keeping the same name for the same thing.

That being said, with the absence of aliasing in the imports in Java, I realized it makes sense from time to time to add suffixes in order to avoid cluttering the code with fully qualified names when 2 versions of the same thing are used in the same file (in converters typically). It's a shame this feature still hasn't made it to the Java language, even though it has been asked for years.

Anyway, this post-processing feature of Livedoc is on its way (at least in my head for now). I just need a bit more free time for this ;)