PMD xpath rule to warn about the use of equals() on BigDecimal - pmd

Could someone suggest a PMD xpath rule to warn that calling the equals() method of java.math.BigDecimal will check for both value and scale which usually (unless for some engineering type apps) might be a mistake. Since 1.0 not equals 1.00, one should use compareTo.

It looks rather complicated with PMD but FindBugs already has a rule for this.

This will be difficult with XPath as the violation is on the method invocation but you need information about the type of the object. A Java based PMD rule might the way to go.

Related

The usage of FQCN in TYPO3

I would like to know if there is any downside to using use instead of using a FQCN to refer to classes in TYPO3.
No downside really. You only need to be careful if you use two classes with the same name which only differ in their namespaces, but that is documented in the PHP documentation.
The advantages are obvious : improved readability, less typing. Many IDEs will help you with using use.
Just use the FQCN in PhpDoc comments.
There are some places where you must use the fully qualified name of classes:
In #var annotations of class members that are also annotated with #inject
In controller action parameters that do not use type hints
Maybe more places, don't know
If you don't use the FQCN, reflection stops working in these places, so dependency injection fails, and type conversion for parameters of actions does not work ("Could not determine type for parameter foo of myAction" or something similar is the exception message).
I've heard that there were attempts to make non-FQCNs work in these places, but they seem to have failed.

How to find the usages of a Scala class'es constructor in IntelliJ?

Is there a possibility to find the usages of a Scala class'es constructor in IntelliJ?
When using "Find Usages" on such constructor, it also applies to every usage of the class'es signature (since the signature is shared between the class and its constructor).
You can do this in IDEA(my version is 2020.2.4) Find Usages Settings...:
I don't think IDEA allows you to do it directly, but you can kind of achieve this by temporarily adding a new parameter, compiling and looking at errors (this will "find" pattern matches using this class as well).

Scala formatter - show named parameter

I have a relatively large Scala code base that does not use named parameters for any function/class calls. Rather than going in and manually entering it, which would be a very tedious process, I was looking at a formatter to do the job. The best I found is scalariform, but I'm not sure whether I can even write a rule for something so complex.
I'm curious if anyone has ran into a similar problem and found a powerful formatter.
The Scala Refactoring library might be something you could use. You will need some knowledge of Scala's Abstract Syntax Tree representation.
Why do you want to use named parameters throughout your code base? I like IntelliJ's default which is to suggest to name boolean arguments (only).

Find all the type casting in project

I just want to find all the type casting done in my project.could some one give me starting point for that.
I don't think that Eclipse can do that.
I think that you could possibly use PMD to do this sort of thing; e.g. by defining an rule based on an XPath that selects AST nodes that correspond to typecasts.

Is the performance hit with using MooseX::Declare mainly encountered during startup?

Is the performance hit with using MooseX::Declare mainly encountered while it does its initial magic (i.e. "translating" the definition into standard Perl syntax)? i.e. once the compile and initial runtime setup is complete, is there a performance difference in calling a MooseX::Declare method vs a method defined via traditional declaration?
The answer is yes and no. Since MooseX::Declare uses MooseX::Method::Signatures to do parameter unpacking and validation, there is a runtime overhead compared to not validating parameters at all.
But if your idea of "traditional declaration" includes validating the number and type of your parameters (and it should if you want robust code) then there's no reason to think that the validation MXD/MXMS does would be any slower than the validation you would do yourself.
MooseX::Declare is a compile time conversion of declarative syntax to "true" Perl code. All of its overhead is at compile time.
The runtime overhead you speak of would be Moose type validation and coercion. Both of these are optional: you do not need to specify a type qualifier, and you do not need to specify is coerce. If you use neither, your runtime performance should be very close to what it would be without MooseX::Declare's magic.
So in runtime terms, it's win/win. You only pay for the features you use. Type validation is something you would have to do manually anyway, and coercion, while definitely a performance hit, is enabled on a per-argument basis.