Skip to main content
18 votes
Accepted

What does 'syntax vinegar' mean

"Syntactic sugar" is a common term for syntactic constructs added to a language primarily to make certain constructs easier or more pleasant to use. "Syntactic vinegar" is the opposite, making the ...
Dave Sherohman's user avatar
12 votes
Accepted

Is calling .sort() in the constructor a violation of the guideline that a constructor shouldn't do work?

Is calling .sort() in the constructor a violation of the guideline that a constructor shouldn't do work? Not if .sort() must be called in order to construct a valid object. What is a valid object, ...
Robert Harvey's user avatar
6 votes
Accepted

Highlighting importance of order when using short-circuited conditions

Why ? In C, C++, Python, Java, C#, Groowy, and Swift (historical order of appearance), and certainly in many other languages as well, the usual logical and-operator (mostly &&) works with ...
Christophe's user avatar
  • 78.4k
6 votes

Is calling .sort() in the constructor a violation of the guideline that a constructor shouldn't do work?

The misunderstanding is that you don't have a List of authors (unless author order is important, such as in academia - but then you'd never even think of calling sort on that List), but rather you ...
user313961's user avatar
3 votes

Is the process of building a model from a dictionary necessarily the builder pattern?

Your approach to constructing the PhoneModel from the rawPhoneData dictionary does share some similarities with the builder design pattern, but there are some key differences. Builder Design Pattern: ...
Jimmy Kurian's user avatar
3 votes
Accepted

POLA, Constructor and Getters

does it violate the principal of least astonishment to return a List of authors sorted by last name? It does not violate astonishment, if you document that is what your method does! A list is indeed ...
Erik Eidt's user avatar
  • 34.2k
3 votes

Is it a code smell to put selection strategy concerns in an enum class?

As long as your text value is a technical value, that can never change, there is no problem with this pattern. However, if you are talking about autocompleting input, this seems to be a text used in a ...
mtj's user avatar
  • 2,040
3 votes
Accepted

Is it clean to place method for comparing 2 objects of same class into that class?

The generally-accepted idiom for such methods in Java is based on the Java Object equals() method, which accepts a different object for comparison: public boolean equals(Object obj) Indicates whether ...
Robert Harvey's user avatar
3 votes

Highlighting importance of order when using short-circuited conditions

&& and || at least in java (and I guess in groovy as well) mean that the operation is short-circuited, i.e. as you said the right hand side will be evaluated if and only if it's necessary. &...
Vadim Samokhin's user avatar
2 votes

What's the computational complexity of the Groovy unique() method?

Indeed complexity is O(n^2). For deeper explanation of how we arrived at O(n^2): Pretend input is [1 2 3 4 5 6] Outer loop iteration 1: answer == [ ], t == 1 Outer loop iteration 2: answer ...
Jose Quijada's user avatar
2 votes
Accepted

Is the process of building a model from a dictionary necessarily the builder pattern?

The builder pattern uses a builder class, which with one final call gives you a fully built object.  The implication of this is that the type system prevents un- or partially constructed (built) ...
Erik Eidt's user avatar
  • 34.2k
2 votes
Accepted

Is it a code smell to put selection strategy concerns in an enum class?

There is nothing inherently wrong in placing more small, self-contained member functions for MemberCategorys and Strings inside the MemberCategory class (yes, in Java, an enum is nothing but a special ...
Doc Brown's user avatar
  • 209k
1 vote

Test-doubling a file path in Java/Groovy

I ended up doing the following: create a PathProvider that has two methods: getBaseInputPath getBaseOutputPath It is defined to be: class PathProvider { String getBaseInputPath() { ...
Mike Warren's user avatar
1 vote

Test-doubling a file path in Java/Groovy

One way is to exploit that Groovy allows parameters with default values. RequestBodyModel parseRequestEvent(APIGatewayProxyRequestEvent request, Constants constants = new Constants()) { byte[] ...
candied_orange's user avatar
1 vote

POLA, Constructor and Getters

does it violate the principal of least astonishment to return a List of authors sorted by last name? Any practical implementation will astonish you! scroll down to read more!! Maybe its not ...
Ewan's user avatar
  • 77k

Only top scored, non community-wiki answers of a minimum length are eligible