Ambiguous Comparison Hint

Hi everybody! Today we would like to show you some new hint which will be available in NetBeans 7.3. It's called Ambiguous Comparison hint.

Its name seems to be quite fuzzy, but it describes exactly what the hint does. It tries to check all comparisons whether they are intended. Because sometimes you want to make a simple assignment, but you make a typo and comparison appears. It's really dangerous mistake because then your code doesn't work as expected. Your application can produce buggy results. So here is how it looks like:

Ambiguous Comparison Hint

But sometimes a comparison is really intended. E.g. in return statements when you want to return a boolean, so then the hint works as expected and no warning appears.

Ambiguous Comparison Hint

That's all for today and as usual, please test it and if you find something strange, don't hesitate to file a new issue (component php, subcomponent Editor). Thanks.

Comments:

What are you using for blue bracket near line numbers?

Posted by guest on October 17, 2012 at 12:11 PM CEST #

That is nice. But could you possibly change the hint text? If I read "ambiguous comparison" a junior developer would not know what you want of him. Plus some people may have problems reading English, so I would suggest to avoid words like "ambiguous" when a more common word can be used to express the same thing.

How about "Possible accidental comparison found. Check if you wanted to use '=' instead of '=='".

Always use clear explanations with simple instructions of 1) what is wrong and 2) how the developer can fix it. Otherwise junior developers will just ignore the warnings.

Posted by Tom on October 17, 2012 at 12:21 PM CEST #

guest: it's a new feature of Nb 7.3. It works out of the box.

Tom: Ok, we can definitely improve it.

Posted by Ondrej Brejla on October 17, 2012 at 01:07 PM CEST #

Nice feature. NetBeans just keeps getting better and better. I also noticed the CSS improvements in 7.3. Now, the "*" symbol in CSS is not being shown as an error. And vendor prefixes seem to be working, for the most part. Nice job, NetBeans.

Posted by Eli McMakin on October 17, 2012 at 09:24 PM CEST #

Why it marks this as accidental comparison?
switch(true) {
case($a == 0): // here
...
case($a == $b): // or here
...
case($a != $b)
}

Posted by guest on May 08, 2013 at 11:09 AM CEST #

Thanks for catching that, I filled a new issue - https://netbeans.org/bugzilla/show_bug.cgi?id=229529

Posted by Ondrej Brejla on May 09, 2013 at 12:05 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today