WG - Document best practices for code quality tools #43179
Replies: 12 comments 55 replies
-
Yes please, let's try and consolidate the various opinions that have been thrown around on disparate channels :)
Definitely +1 for an ADR - this will allow us to easily refer to the rules in the future |
Beta Was this translation helpful? Give feedback.
-
Proposal: Prefer
|
Beta Was this translation helpful? Give feedback.
-
Proposal: Prefer constructor injection over field injectionField-level injection @Inject
MyBean myBean Forces your beans to have package-private scope within a class. Additionally, its difficult when mocking beans that use field injection to know/understand what the dependencies of a bean are. Using constructor injection private final MyBean myBean;
public MyClass(MyBean myBean) {
this.myBean = myBean;
} is a little more verbose, but it allows proper scoping/encapsulation of dependencies within a class, plus it is explicit as to what is required in order to instantiate/use a class. |
Beta Was this translation helpful? Give feedback.
-
Proposal: Minimize the usage of Lambdas when writing build-time initialization code@gastaldi Can fill in details (https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Quarkus.20Anti-Patterns/near/466380624) @franz1981 feel free to add more context here as well. They are also difficult to debug when things go wrong. |
Beta Was this translation helpful? Give feedback.
-
Proposal: Never use
|
Beta Was this translation helpful? Give feedback.
-
Proposal: If you mostly have non-reactive endpoints which do most of the work, consider using a single event loop vertx instance, or at least leave half of the cores available to the blocking sideThis is especially valid if the load is not very high; it can easily reduce the power consumption by more than 30% and the CPU usage by 15% or more. From @franz1981: https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Quarkus.20Anti-Patterns/near/466519026 |
Beta Was this translation helpful? Give feedback.
-
Proposal: Logging: Use the static
|
Beta Was this translation helpful? Give feedback.
-
Proposal: Logging: Don't use log guardingSomething like if (Log.isDebugEnabled()) {
Log.debug("Debug something");
} isn't needed, as the If you need to include something which is expensive to compute, use the variant log methods that take parameters: Log.debugf("Debug and output something thats expensive to compute: %s", someMethodThatComputesSomethingToOutput()); |
Beta Was this translation helpful? Give feedback.
-
Proposal: Logging: Don't use String concatenation in log messages. Use proper format methods.Don't do: Log.info("value: " + someValue); Instead, do: Log.infof("value: %s", someValue); |
Beta Was this translation helpful? Give feedback.
-
Another benefit of doing this work, is that we can point IDE devs to the source of truth and they can update their software accordingly. |
Beta Was this translation helpful? Give feedback.
-
Question: How about test logging?Should I mock the logger (verification is against special methods / white box) or should I configure the logger to log in-memory and make my assertion against the in-memory data? |
Beta Was this translation helpful? Give feedback.
-
What about RoutingContext vs Context/UriInfo ?With Quarkus 3.x the http layer is mapped through Vertx and JAX-RS stuff is not used anymore if I’m not wrong. So RoutingContext is always filled and available. I had occasions when injecting Context gave me null. Is it a good practice to inject RoutingContext by default then ? |
Beta Was this translation helpful? Give feedback.
-
In https://groups.google.com/g/quarkus-dev/c/Rb-WAzCNuVw, we discussed about how we could document Quarkus best practices and ultimately transform as a set of Sonar rules (obviously, they could be integrated in all sorts of tooling).
The goal of this working group is to come up with this set of best practices.
I suggest the following process:
Approved best practices
...WIP...
Beta Was this translation helpful? Give feedback.
All reactions