Sometimes you have to create object with multiple parameters, for example:
data class Project(
@JsonProperty(ID) val id: String?,
@JsonProperty(TITLE) val title: String?,
@JsonProperty(DESCRIPTION) val description: String?,
@JsonProperty(STATUS) val status: Status?,
@JsonProperty(LOGGING_STRATEGY) val loggingStrategy: LoggingStrategy?,
@JsonProperty(CREATE_TASK_STRATEGY) val createTaskStrategy: CreateTaskStrategy?,
@JsonProperty(VISIBILITY_STRATEGY) val visibilityStrategy: VisibilityStrategy?
) {}
Wouldnât it be swell if we could append trailing comma to last parameter? (At least to constructors, but it would be nice for functions too)
This would help during adding new entries, reordering items and of course in version control.
It would be consistent with how we do enums now:
enum class Status {
OPEN,
CLOSED,
PENDING,
}
It seems that it would not be a breaking change (to my untrained eye).
Is it relatively easy to do, or does it make grammar sigificantly more complex?
It doesnât seem to be one of the most popular ones, so weâre not seeing this as a high priority issue, but itâs definitely something that weâre considering.
Well, itâs not a great new shiny thing that attracts tons of attention. Itâs just minor improvement, that makes coding flow considerably smoother. Itâs good to know it is beeing considerered. Iâll be waiting!
EDIT:
Wow, you really have lots of amazing things to choose from.
Any new language features that we introduce into Kotlin are added in major releases (1.2, 1.3) and controlled by âlanguage versionâ switches. The new syntax will be enabled only if you choose to switch your project to the new language version.
This is nice discussion by the way, I will post it here just in case someone wants to check it out:
Yeah, in scala case it may cause lack of backward compability, but Kotlin is a bit different beast. In the end it all depends on implementation, there are many flavors of trailing commas.
I use this frequently when writing tests in Groovy to include/exclude test cases. Itâs really nice to not have to always âclean upâ that trailing comma.
The survey results arenât very good for this. See the blog post:
We shouldnât have put âOptional commasâ and âOptional trailing commasâ under the same feature (my mistake, sorry), as itâs actually two features, so the results there are difficult to interpret.
I would have voted against optional commas, but the ability to put in trailing commas would be very nice indeed. Something I certainly miss from both C# and JS.
One of the most tempting cases of trailing commas is in listOf() and arrayOf() etc. If collection literals are implemented, I would say that there would be much less people concerned about this feature.
In addition, the poll actually forces people to choose two features (linebreak commas and trailing commas) together, which might not reflect opinions too well.