Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Xintong Song
Thanks for starting this discussion, Yangze. My personal preference for either singleton or non-initiatable classes is to use enum wherever it is possible, because it's briefer is safer. On the other hand, I'm also against private constructors. To my understanding, for most if not all

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Yangze Guo
Thanks all for the valuable feedbacks! @Gael @Dawid Thanks for the explanation! I think you are right that this discussion is about a non-instantiable class that contains only static methods. @All My major proposal is actually to stick to one of two approaches in Flink. It seems that most devs

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Jingsong Li
Hi, thanks for starting this discussion. I am +1 for using the private constructor for util class. We don't need to change it. I think few libraries use the enum, such as guava, common-utils, or even JDK, the private constructor is widely used. I don't quite understand why a util class is an

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Dawid Wysakowicz
Hi all, First of all I very much agree with Gael. The discussion is not about a Singleton pattern. Secondly, similarly as @Timo and @Gael I find the pattern very confusing. Each time I see it I have a hard time figuring out why there are no enumerations in the enum. This is my preference though.

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Gaƫl Renoux
Hi One small remark here: you should not call this a Singleton. For most people, a Singleton would refer to the implementation of the GoF Singleton pattern, where you have a single instance of the class (see for instance the corresponding Wikipedia page:

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Timo Walther
Hi, honstely, I find using enums is more of a hack. `enum` stands for enumeration and is meant for listing flags or options. Using it for singleton patterns is just abusing a concept due to certain implementation details and less code. I feel this topic is like using Lombok for generating

Re: [DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Piotr Nowojski
Hi, I don't mind one way or the other. I guess enum way is somehow safer, however did we really have any issues with our current approach with `private` constructors? I mean, you are mentioning that using reflections could overcome private constructors, but is that a real concern in our code

[DISCUSS][Code-Style] The approach to implement singleton pattern

2020-09-25 Thread Yangze Guo
Hi, devs, Recently, in the PR of FLINK-19179[1], we have a discussion about how to implement singleton pattern in Flink. Currently, most of the utility classes implement singleton pattern through the private constructor. Seldom utility classes leverage the enum mechanism. From my perspective,