Ruby Screenshot of the Week #24: Quick Fix Previews



First of all, NetBeans 6.0 (final) was released this morning. Go get it!



So let's talk about 6.1 :) I just updated the quickfix infrastructure such that we can automatically generate previews for how the hints will modify the source. I've also added some new hints.



Let's start looking at the user.rb file in the sample Depot application. If I place the caret inside one of the if blocks, a lightbulb appears:






NetBeans offers to replace this if-block with one where the "if" is a statement modifier. This idea came from the excellent "Exploring Beautiful Languages"
blog
by Luis Diego Fallas, where he implements NetBeans Ruby hints -- in Scala!






Here's the new preview functionality in action; instead of just applying the fix I invoke the Preview and get the following dialog which shows what the fix will do:






Preview is particularly useful for larger source changes like Extract Method.



Here's another method from the same file:






Obviously, we can apply the same "convert to statement modifier" here, but look at the first suggested fix:






NetBeans will convert "if negative condition" to "unless", and "unless negative condition" to "if" to make the code more readable. This was also shown by Luis in his blog entry. Here's the proposed fix:






and we can apply the other conditional cleanup as well to end up with a much simpler statement:






There is one more recently added hint: Check for accidental assignments.






At first I got a lot of false positives for this hint, since many Ruby programmers seem to like to intentionally assign in their conditions. But then I updated the rule to only complain if the variable being assigned to had already been seen in this scope, and that seems to do the trick perfectly. Newly assigned variables are intentional side effects of the assignment, and assignments to existing variables are likely bugs and should be avoided.

Comments:

Estimated Tor:
Congratulations for this work, which is historical.
I would like to initiate a free project, with calculations and graphical representations, it wanted that it work in the desktop, in the web and in the mobile phones, taking advantage of the code the possible maximum.
Would it be a good option to use NetBeans + J/Ruby + JavaFx?.
Thank you for everything. :-)

Posted by Juan M. on December 03, 2007 at 11:16 PM PST #

A big thank you to you and the Netbeans 6 team for all the great work, it really has become quite a gem! A gem, get it :)

Now for the nagging: I have a question about the RHTML editor. Is there a philosophy behind the indentation resetting to the start of the line after every enter? For example, if have:

[tab][tab][tab]<div>

And then press enter, my cursor will be at zero tabs again. Should it not go to four tabs automatically? Or maybe three tabs so I can indent it myself. The same happens in Javascript code blocks.

Posted by Alex on December 04, 2007 at 03:01 AM PST #

This rocks. Keep up the awesome! :)

Posted by Shadowfiend on December 05, 2007 at 10:28 PM PST #

Hi Tor. I could tell you NetBeans is currently the best ide around for ruby and rails, but you already now that :)

A question: How do you pop-up that sugerences? I try to click the icon but then a breakpoint is set on the place i click.

Also, i wanted to ask you if will NetBeans support ansi colorization any time soon? I work with the excelent autotest script inside Netbeans, wich is great because, when an error happen, i can click in the autotest output the link to the file failing. Sadly, al ansi output is written and not interpreted, so all color is lost.

Thanks!

Posted by Emmanuel Oga on December 06, 2007 at 09:12 PM PST #

Thanks for your comments!

Juan, that sounds pretty ambitious, but yes, you should be able to do that with a combination of those technologies.

Alex, no, that's not intentional - it's this bug:
http://www.netbeans.org/issues/show_bug.cgi?id=109262

Emmanuel, to pop up the fix suggestions, press Alt-Enter. (This is also shown in the Source menu as "Fix Code..."). Support for ansi terminal escapes in the output window is definitely on the todo list.

Posted by Tor Norbye on December 12, 2007 at 07:21 AM PST #

I'm still using netbeans beta2 because it's the last version where reformatting rhtml worked for me. In many files 6.0 final will just take lines and add an additional level of indentation every time I hit format.

Posted by aph on December 15, 2007 at 12:51 AM PST #

Hi, Tor! Something is happend with last versions of NetBeans - it doesn't want to use that colors, that I pointed in the color schema (just ignores). The version that works fine for me is 20071202220810.
Thanks!
(P.S. it looks like the situation with HAML, remember I've written about it?)

Posted by ruby.freeman on December 17, 2007 at 09:07 AM PST #

I'm a big fan of what you are doing with Netbeans. I've been using all the beta versions and just upgraded to 6.0 and have been trying to evangelize it around the office, but I've got one funny bug that always hurts my demos. I've Googled everything and can't seem to find a fix. For the most part the applications runs very quickly on Windows XP (dual processor), but when I right click on the Ruby project (to migrate or open the console) the drop-down takes 15 seconds to open. I'm not exaggerating. I just timed it. I saw this with the last version as well. Anyone ever heard of this? I like the app so much I've been working around it, but I was REALLY hoping 6.0 would fix it.

Posted by Michael Holloway on December 19, 2007 at 01:16 AM PST #

Hi Aph, I will look at those RHTML formatting bugs soon. Just stuck doing something else at the moment :)

Freeman, is this an issue with Ruby files, or RHTML, or HAML (or all?).

Michael, every time you run migrations or code generators you're starting a new Ruby process. For JRuby, the startup time is a significant delay. This is something they're working on but won't be fixed very soon. We're thinking of having a "JRuby server" which processes requests immediately rather than having to start a new VM and go through Ruby initialization every time.

In the mean time, you can get around this by just switching to native Ruby / C Ruby (see the Options dialog, Ruby > Platform).

Posted by Tor Norbye on December 19, 2007 at 01:26 AM PST #

Thanks for the fast response. I should have noted that I am running native Ruby -- not JRuby. Also I just went back and checked and Beta 1 doesn't have the problem. Just Beta 2 and 6.0 full. Also, this is not when I run something from the drop-down. It's the actual drop down. I right-click on the project and wait 15 seconds for the menu to pop-up. No kidding. I think I'm going to head back to Beta 1 for now, but I will keep checking. You guys are doing some cool stuff. Thanks.

Posted by Michael Holloway on December 19, 2007 at 01:38 AM PST #

Oh! That sounds like something I've not heard about before. I'd really appreciate it if you could generate some thread dumps while the IDE is blocked and mail it to me (tor.norbye@sun.com) - or attach to a bug report.

To generate a thread dump, use the "jps -lm" command to get the process id of the NetBeans process, and then "jstack <pid>" to generate the thread dump. Cut and paste the result. This is all from the console, and should be described in more detail here:
http://wiki.netbeans.org/wiki/view/GenerateThreadDump

Basically a thread dump will show me what the IDE is so busy doing during those 15 seconds so I can see what code is hot to pinpoint the problem. Generate a couple of dumps during the time so I can distinguish between code that randomly happens to be executing while the dump was taken, and code that is still processing between the two so is likely a bottleneck.

Posted by Tor Norbye on December 19, 2007 at 01:43 AM PST #

For anyone keeping score at home.
1. I sent Tor the thread dump.
2. He took note and suggested a short-term workaround of shortening my path variable.
3. I took his advice and found a reference to a non-existent folder.
4. I removed it and cut the wait to a fraction of a second.
5. Tor is the man!

Posted by Michael Holloway on December 19, 2007 at 05:19 AM PST #

Post a Comment:
Comments are closed for this entry.
About

Tor Norbye

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