investAPI icon indicating copy to clipboard operation
investAPI copied to clipboard

Use deprecated option for deprecated properties

Open olsh opened this issue 2 years ago • 1 comments

На данный момент для deprecated полей используются комментарии, например так https://github.com/Tinkoff/investAPI/blob/59952c395316a2ba426b5fd0b75257714d015ceb/src/docs/contracts/orders.proto#L73

Недостаток этого подхода в том, что сложно узнать о том что поле deprecated (пока не прочитаешь комментарий) и его не надо использовать. Особенно сложно об этом узнать в уже написанном коде.

Предложение использовать опцию deprecated вместо комментариев https://protobuf.dev/programming-guides/proto3/#options

deprecated (field option): If set to true, indicates that the field is deprecated and should not be used by new code. In most languages this has no actual effect. In Java, this becomes a deprecated annotation. For C++, clang-tidy will generate warnings whenever deprecated fields are used. In the future, other language-specific code generators may generate deprecation annotations on the field’s accessors, which will in turn cause a warning to be emitted when compiling code which attempts to use the field. If the field is not used by anyone and you want to prevent new users from using it, consider replacing the field declaration with a reserved statement.

int32 old_field = 6 [deprecated = true];

В таком случае многие статические анализаторы, Java, C++, C# будут подсказывать что поле не стоит использовать.

Так же, было бы неплохо при deprecation какого-то поля, всегда указывать что можно использовать взамен. Например тут https://github.com/Tinkoff/investAPI/blob/59952c395316a2ba426b5fd0b75257714d015ceb/src/docs/contracts/operations.proto#L157

olsh avatar Jan 14 '23 15:01 olsh

Правильно. Плюсую!

ivan-volnov avatar Jan 27 '23 13:01 ivan-volnov