Sunday, September 23, 2012

Whoa -- IOS6 Safari Caching

I've often suspected that Chrome did cache rather too tenaciously, although I am not 100% on that. But it seems iOS6 has gone beyond the whole hog, and caches HTTP POST requests:

http://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results

Whoa. Well, this kind of thing is a reason to be _very_ explicit in our HTTP response headers. Let's always set the Cache-Control header. Cache-Control: no-cache is a good default. For POSTs, at least.

Friday, September 21, 2012

Weird Eclipse Open Resource Matching

In Eclipse's Open Resource dialog, "*TEU", or even "*TEvalU" should match 'DjangoTemplateEvalUtil.java', should it not? Well it does not. My little theory is that the 'E' is used up by the 'e' in 'Template'. Which must be seen as a bug.

However, "DTEU" matches on the subword initial capitals. I'd say 'go figure', but hey. 

Can't trust anything these days :). It looks minor, but it's really a pretty serious problem, if you rely on your names to be able to find stuff. And not wasting time trying to figure out why something that you feel should be found. If it matches "DTEU", you're expecting it to match the looser (loser) pattern "*TEU".

Tuesday, September 18, 2012

1/86400 Hz Blogging

Why not write a blog a day? There is no shortage of subjects. There is a shortage of time. Maybe set a limit on time for writing each blog. 20 minutes, perhaps. Go.

Well, a posting deserves a relevant subject line; so this may have to do for today. That's 2 minutes... I could do 10 each day. Micro-blogging, I think, that is.

Monday, September 17, 2012

Eclipse Great Feature: Move Updating References And Commit

Some of the lists in Eclipse allow for bulk operations on them. Find references is one of them.

This allows for the following extremely useful procedure to work: you move and/or rename your Java type definition. This causes uncommitted edits. If you're a mis-en-place, clean, only-does-one-thing-at-a-time operator, you'll just do a commit all to commit these changes. But, if you're like me, you usually discover out-of-place types (classes, interfaces) while working on something else. Anyhow; there may for many possible reasons be uncommitted changes that you're not ready to commit. This makes it difficult to separate the files to commit from the files to keep 'dirty' (let's not consider the case where the same file contains both kinds of changes right now).

That's where for move refactoring operations, the 'Find References' feature will (may?) work fine: the list of found references seems to allow bulk commit. Select all the files you want, and then pop up (left mouse button click or Ctrl-click) the contextual menu. Team > Commit, and you will have your referencing occurrences committed.

This leaves the moved definition file changes, unfortunately. So of course the commit-all is really preferable, if appropriate for your situation.

It would be great if Eclipse would give you an option like: "Would you like to commit all the changes caused by your last action, File moved?".

And if it'd separate relevant changes from irrelevant changes in the same file, that'd be magic.

And if it'd allow selecting actions to commit, from a list of recent actions, that'd be more magic.

Anyway, there is actually a simple two-thirds-of-the-value solution for this: list files in "mtime" (last changed time) order, and allow selecting a range to commit. (Deleted files will be an wrinkle, though.)

I have some more tips on moving files in Eclipse, but they'll have to wait.

So that's that. Consider this a first in a (potential, no promises) series of Eclipse workflow posts. I'd like to know if there are already such things written, so please comment if you know.

Sunday, September 16, 2012

Incredibly Useful

Browsed through the Amazon Kindle Press Conference video (at https://www.youtube.com/watch?v=VYi1jZXz9Kg). Bezos reading (I had to correct the lousy auto-transcripted lines):
"King Stanis, lord of Dragonstone, younger brother of the late king,"
15:02
"Robert, has dark blue eyes and only a fringe of the black hair remaining on his"
15:06
"head"
15:07
"circling behind his ears like the shadow of a crown (crab?)"
And then he comments:
15:10
incredibly useful

Couldn't help an amused laugh, sorry to say. I guess I am a chuckler-at-fantasy. Anyway, the feature seems very nice.

Friday, September 14, 2012

Quick Whine #1: OSX Open File Dialog

Ways in which the OSX Open File Dialog is lame. Partial screenshot showing perpetration:


(A small detail first: the (American) date format is lame. ISO is the appropriate format. Mea culpa for not fixing settings, of course.)

Why no file sizes? Why no thumbnails? Why no preview? Why leave the huge space to the right unused?

And if these defaults are designed such as to, I don't know, leave the regular Joe Non-Power-User with a soul unperturbed, why isn't there a small 'settings' icon to click? Or the usual Cmd-Comma for settings?

Thursday, September 13, 2012

Eclipse Call Graph (You Can Sometimes Get What You Want)

Just stumbled upon a blog post. The usual list of the usual tricks. All the usual shortcuts mentioned, refactoring, Find Type, etcetera. Yawn, seen it, used it.

But at the end of the section I was reading, the Ctrl-Alt-H key combination in Eclipse was mentioned, which shows a static Call Graph (a tree really). Yes!

The thing is that I've been wanting this and been looking for this, but not been able to find it, and given up. In my Eclipse, it's not shown in the context menu, oddly. That's some really bad 'discoverability', grumble, grumble. So I thats why I make a blog post simply to repeat the message. 

Thanks Cygni blogger, whose name I've forgotten already! (Not in English: http://cygni.se/2007/11/27/eclipse-tips-och-tricks/.) 

I Need a Word Here


Is "declarativeness" an acceptable word? Doesn't sound very good, doesn't roll off the tongue. Where do you put the stress?

"Declarativity" is easier to say. So let's use that.

The concept is useful, though. It could be phrased as "level of declarative expressivity". Or "aggregate expressivity of available declarative features". Etcetera.

---

Well, Google seems to bear this out:

Declarativity: About 24,100 results
Declarativeness: About 10,600 results

---

Declaration-oriented? Declaration-prone? Declaration-expressive?

Sunday, September 9, 2012

Nothing To See Here


This post is a stand-in for "Drafts 48 -- Published 35; Timeout", which is a stand-in for "10 BPM", neither turned out good enough. What I intended to do was to just take stock, try to philosophize a bit on blogging, and make a feeble declaration of purpose. Well, this is the stock of drafts, below. If any one/s of these seem interesting to you, comment. The ones named '(Untitled post)' are the surprise boxes, I guess.

Drafts 48 -- Published 35; Timeout
7:13:00 AM

"Any Obstacles?"
9/8/12

Mood Maintenance
Edit | Delete
9/7/12

Rantom Opinions
9/7/12

M-CPS
9/7/12

Jquery Ajax "Accepts" Parameter
9/4/12

Parse JSON Into Existing Instance
8/28/12

Eclipse F5 Disaster
8/28/12

10 BPM
8/28/12

Jesus H. Cox
8/13/12

Stack Overflow Strategy
8/13/12

The Fresh Eyes Documentation Sync Strategy
8/13/12

Force Start
8/13/12

Motivaion
8/13/12

Knowledge Encoding Is Impossibly Hard
7/6/12

Is "Help" Possible
7/6/12

JBoss Meditation Blur Event
7/6/12

Postprandial Tiredness
7/6/12

(Untitled post)
7/1/12

Juno & June
6/29/12

(Untitled post)
6/29/12

(Untitled post)
6/29/12

(Untitled post)
6/29/12

(Untitled post)
6/29/12

Friday, September 7, 2012

Juno II, The Brightening Up

Back in Eclipse Juno, incidentally, had to use a new Eclipse due to a mysterious error with a cryptography module not getting found. Stopped using it a couple months ago because it seemed to have small bugs. Possibly one of them was that Subclipse seemed badly integrated. The small file status symbols didn't show; or sometimes all files appeared with the question mark symbol making me think it didn't work.

But today it is looking fine, after both things happening at first; no symbols, then question marks. Then after a restart and a "Could not write metadata for '/RemoteSystemsTempFiles' modal dialog, and a while, and now they are showing. It might be the synchronization command I invoked was needed to finally get them showing.

So if you're seeing the same thing, just be a bit patient, do a 'Synchronize', and your day may brighten up some.


---

Oh, no, not bright. Installed the 'm2e' Maven Plugin (I think). Going from not finding "javax.persistence", to:


 The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

And 'java.lang.Object' would probably be the most resolvable class in Java. 

---

Had to explicitly convert the project to a maven project. Odd, because: 
1) the .project had a couple of maven-related settings; maven2Nature and whatnot. 
2) ISTR that .pom files are auto-detected? I probably remember wrong. 

Better. 

...except: 

maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: default, phase: initialize)
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: create_db_and_user, phase: initialize)
Plugin execution not covered by lifecycle configuration:
 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution:
 create_test_db_and_user, phase: initialize)

Great. Well,  I believe we had at least the copy-dependencies those to support an old ant project setup, copying maven lib dependencies into some folder for ant to deal with, so that might be ok.

...maybe I should have installed m2eclipse instead? I thought they were practically the same thing. But 
here is an article that begs to differ: http://java.dzone.com/articles/migrating-m2eclipse-m2e

Ok, so how do I uninstall m2e and change to m2eclipse? The menus give no clue. 

...ah got it: select "Install Software..." menu item; the install dialog contains a "already installed" link. It has "Uninstall..." buttons. Of course, why didn't I think of that first? 

Selected the two items that seemed to have to do with m2e. (Restart, problems saving state modal dialog...)

---

Ok, Eclipse Marketplace, what have you got for me? m2eclipse-wtp seems to be the closest match for m2eclipse. ...ouch, "unsigned content". 

Let's try the other one, "Install New Software...". m2eclipse-wtp -- what the, it contains only m2e? Maybe I can't get an older m2eclipse with Juno? 

-- 

The blog I found above has a nice article here: 
which seems kind of relevant; for instance this passage: 
However, the problem is much more widespread than m2eclipse. It’s very similar to issues adressed in Andrew Spencer’s post, only more so since if we don’t upgrade, we may have to keep an Eclipse instance for each project, that has to be shared between all team members. Right now, I don’t have any solutions for this problem, apart from changing the code to keep in synch with the tool.
---

Tried the "Discover new m2e connectors" link in quick tip. I don't know what those are, because nothing showed up. 





Wednesday, September 5, 2012

Jquery Ajax And POSTing JSON


This snippet of code:

var ajax_params = {
  type: 'POST',
  url: dst_url,
  contentType: 'application/json',
  dataType: 'json',
  data: dto_obj,
  error: function(jqXHR, textStatus, errorThrown) {
    console.debug("Error...");
  },
  success: function (data, textStatus, jqXHR) {
  }
};
$.ajax(ajax_params);




_still_ gives me encoded gibberish on the server, not JSON. But the Content-Type header seems to be correct, from debugger: Content-type=[application/json, null].

Good and necessary jQuery debug technique: step into the $.ajax() call and look at the calculated parameters.

But it's easier to use XMLHttpRequest directly.

----

Conflicting answers on Stack Overflow:

answer1 says don't pass a string, pass the object; wrong, apparently.
answer2 says pass the serialized string.

Guess which answer I happened to read first.

So; to be clear, this is what works: "data: JSON.stringify(dto_obj)". 

Stack Overflow


Some exercises. Exercise 1. What is wrong with this piece of code: 
try {    runSubs(objectFieldValue);
} catch (java.lang.StackOverflowError e) {
   System.out.println("[StackOverflowError] objectFieldValue: " + objectFieldValue);
   throw e;
}
Answer: the println() will of course overflow the stack too. (EDIT: seems it was the code I was debugging that caused this; i.e. the toString() contained some circularity. I wrote some simple code where a similar print statement seems to _not_ overflow. Although it should, the '+' gets compiled to a call to a string concatenation/append, doesn't it?)

What is wrong with instead doing just:
try {   runSubs(objectFieldValue);catch (java.lang.StackOverflowError e) {
   throw e;
}
...and setting a breakpoint at 'throw e'?

Answer: Well, nothing wrong per se; but you won't be able to see anything in the (Eclipse) debugger: it simply can't handle those stack depths. Maybe if you set a small stack allocation, but then you may get false positives.

So. If you didn't know it before, debugging StackOverflowError is a pain.

One might of course use some flags or counters or stuff, and handle the stack overflow further out. Cumbersome.

If you've got any good ideas or solutions, please don't hesitate to comment.


Tuesday, September 4, 2012

While Multicore Gently Weeps

Started file search for "*TRANS*" in Eclipse. Twice. Unintentional wildcard pattern, I wanted to find "*TRANS*" literally. Each gets stuck in one file, like forever. 100%CPU each. Canceled both; or tried to. The other is still "File Search (Cancel Requested)".

It's a shame that it's not widely recognized that half of the benefit of threads is to always be able to cleanly cancel them. It helps realize the benefit of thread as background workers.

By cleanly, I mean that locks and resources held should be released, too.

Of course, in the case of file search, subprocessing could probably be used almost as well; just that internal caches and file editing state might not easily be made available to a subprocess.

---

Now at least one of them is gone. But the other persists, searching that file in vain. (There must also be something wrong with the (regex?) pattern match engine or something. I've happened upon regex patterns that would Pattern.compile into exponentially (or even worse?) time-consuming matchers. Unkillable, too.)

---

Ok, now (perhaps 10 minutes later) the other one died. 

Eclipse Even Weirder Console Link


Logging this: 

...(code: 200)(TheClass.java:92): null

to the console. Link gets me a popup: "Source not found for 200).TheClass". (And you have to do your "OK" click, like "yes that's OK".)

Eclipse can do advanced refactorings, but it can't get this (regex?) text match thing working right? Just kind of perplexing, that's all. 

It's a very nice and useful feature, be very nice if it worked better. I have an earlier post on this here.

EDIT. A solution can be to surround the parenthesized link text with spaces. Worked in this case, at least! 

Monday, September 3, 2012

Proposing a Improvement to the Override Annotation


The Java "@Override" annotation should have a "Class[] value() default {};" allowing you to be more specific about where the overridden method is inherited. The "default {}" is to be backwards compatible; and also to not force you to do it; and for non-branching inheritance paths, where it is not needed. (Or could it be useful even then? Discuss.) Note that multiple 'sub/super-type paths' could be involved, even where there may be only one 'original' method type declaration. 

Small thing, but nice-to-have. In Eclipse, you can already navigate to it using Cmd-T (or corresponding). But it just might be nice for readability, and refactorings could probably use it in some cases. 

Anyway, it would be more expressive. And aesthetics matter.

This will of course happen really soon, just because I suggested it, but never soon enough; so how about using this simple annotation while we hold our respective breaths:


@interface Overriding {
   Class[] value() default {};
}

Maybe @Overrides is better. It's one letter shorter. 

We could also implement some library code to walk the classpath and perform actual checking using reflection. It's not trivial, so I'll leave it as an exercise for the reader.