Monday, May 11, 2009
One cat, a chihuahua, and a turtle
Friday, April 3, 2009
A high-level language on the JVM
Alex Payne: I think programmers who’ve never worked with a language with pattern matching before should be prepared to have that change their perceptions about programming. I was talking to a group of mostly Mac programmers, largely Objective-C developers. I was trying to convey to them that once you start working with pattern matching, you’ll never want to use a language without it again. It’s such a common thing that a programmer does every day. I have a collection of stuff. Let me pick certain needles out of this haystack, whether its based on a class or their contents, it’s such a powerful tool. It’s so great.
Robey Pointer: I wanted to talk a bit more about starting to use Scala. It definitely wasn’t a flippant choice we made over a few beers one night. We actually agonized over it for quite a while. Maybe not agonized, but certainly discussed it for a long time. One of the biggest draws for us to Scala as opposed to another language, was that once you’d started writing in a really high level language like Ruby, it can be difficult and kind of annoying to go back to a medium level language like Java, where you have to type a lot of code to get the same effect. That was a really big draw for us. With Scala we could still write this really high level code, but be on the JVM.
That's from an Artima interview about the guys behind Twitter evaluating Scala.
It sounds about right to me. Scala is adventuresome in the high-level features it gives you access to, e.g. pattern-matching, higher-order functions, and mixins. However, it runs and is integrated with the JVM, so you can always use a Java library or write in low-level Java if you run into performance issues or need some API that Scala doesn't provide.
Saturday, March 14, 2009
SMTP relaying from OS/X
relayhost = mail.vc-graz.ac.at
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
smtp_sasl_security_options = noanonymous
Note that if your mail relay runs on port 26, you can put the port number on the relayhost line, like this:
relayhost = mail.vc-graz.ac.at:26
Friday, March 13, 2009
Ivan Krstic on security-friendly languages
Now, while I’m already grossly overgeneralizing, I think the first group is almost useless, the second group is almost irrelevant, and the third group is absolutely horrible at explaining what the hell they’re talking about.He and the commenters then give some good introductory links.
Wednesday, March 4, 2009
Installing top-level code with JavaScript's eval
http://piecesofrakesh.blogspot.com/2008/10/understanding-eval-scope-spoiler-its.html
The following page also discusses the problem, but has a really good collection of comments:
- window.eval, what I tried to begin with
- window.eval, but with a with() clause around it. Some people report better luck this way.
- window.execScript, a variant of window.eval
- window.setTimeout
- adding a script tag to the document
What I did in each case was try to use the technique to define a function foo() at the global scope, and then try to call it. I tested these browsers, which I happen to have handy:
- Safari/Mac 3.1.1
- Firefox/Mac 3.0.6
- Firefox/Linux 2.0.0.20
- Firefox/Windows 3.0.3
- IE 6.0.2900.xpsp_sp3_gdr.080814-1236 updated to SP3
- Chrome 1.0.154.48
- window.eval: FF
- window.eval with with: FF
- window.execScript: IE, Chrome
- window.setTimeout: Chrome, FF, Safari
- script tag: IE, Chrome, FF, Safari
- The window.execScript function is available on IE and Chrome, and when present it does the right thing.
- The window.eval function only works as desired on Firefox.
- Adding a with(window) around the window.eval does make a difference, but I couldn't get it to do precisely what is needed for GWT. In particular, GWT does not have a bunch of "var func1,func2, func3" declarations up front, but such vars are assumed in some of the other web pages I read.
- I could not find a synchronous solution for Safari. Instead, setTimeout and script tags work, but they won't load the code until a few milliseconds have gone by.
- Script tags work on all browsers.
- Surprisingly, I couldn't get setTimeout to work on IE. From some web browsing, it looks like the setTimeout callback might run in the wrong scope, but I didn't investigate far. On IE, execScript is a better solution for the present problem.
if (window.execScript) {window.execScript(script)} else {var tag = document.createElement("script")tag.type = "text/javascript"tag.text = scriptdocument.getElementsByTagName("head").item(0).appendChild(tag)}
For the versions that install the code asynchronously (setTimeout or script tags), I changed the window.foo() line to be:function installFoo() {var script = "function foo() { alert('hi') }"// varying part}installFoo()window.foo()
window.setTimeout(function() { window.foo() }, 100)
// window.evalwindow.eval(script)// window.execScriptwindow.execScript(script)// window.eval with a withvar $w = windowwith($w) { $w.eval(script) }// setTimeoutwindow.setTimeout(script, 0)// script tagvar tag = document.createElement("script")tag.type = "text/javascript"tag.text = scriptdocument.getElementsByTagName("head").item(0).appendChild(tag)
Friday, February 6, 2009
Why not inject dependencies "manually"?
MockService mock = new MockService();
Client client = new Client(mock);
client.go();
assertTrue(mock.isGone());
private ClientFactory() {}
public static Client getInstance() {
Service service = ServiceFactory.getInstance();
return new Client(service);
}
}
Monday, February 2, 2009
Private dependencies in Java
The most common cases of this issue are addressed by using DNS-based package names. This approach doesn't work, though, for diamond-shaped dependencies. Imagine that component Lib is used by both A and B, and that both A and B are used by an application App. App then depends on Lib through two different paths: App->A->Lib and App->B->Lib. There are several ways to cope with this multiple dependency, and it's not solvable in general. A good component distribution system can help you manage the difficulties, but it won't solve it outright.
Within this set of problematic cases, there is a large subset where it would actually work fine for A and B to get their own separate copies of Lib. Having two copies around has its down sides, such as he memory and program-size of the resulting bundle being larger. However, the robustness of the overall application is frequently higher because both A and B are using the version of Lib that they were developed against. For those cases where the trade off looks good, one question is, how can it be implemented in Java?
I know of two general approaches, and would love to know what else is out there.
One approach is to rename A's preferred version of Lib to use different global names than it originally did. All packages in Lib are renamed to somewhere else, typically underneath A's chunk of the global DNS-based name space. Simultaneously, all references in A to something in Lib are updated to point to the new location. This approach is supported by a tool called Jarjar. To make a long story short, we've tried this approach with some of GWT's third-party dependencies, and we have roughly a 50% success rate so far. For some libraries, such a renaming Just Works.
Other libraries have trouble, because somewhere there is some class reference that Jarjar doesn't know how to rename. For example, Jetty includes XML configuration files that have class names embedded in them, and Jarjar doesn't rename those by default. Arguably it is questionable style to program this way, but for one reason or another some libraries do.
This leads to a second approach: load the library in a separate class loader from its client. That is, instead of A accessing Lib directly, it creates a class loader and loads Lib in that separate class loader. This approach has the beauty of reliably putting the implementation of Lib in a separate name space from the rest of the application. However, for it to work, there must be an interface to the library still included in the main application. This leads to two significant limitations of the approach. First, the library must have a small enough interface that it is practical to maintain all of these interfaces. Second, the interfaces still have the dependency hell problem, because they will be in the main package and can conflict with each other.
It's a nasty problem in general, one that it would be great for a language to address more thoroughly. I know that the OSGi system used by Eclipse has some support for this approach, with its heavy use of interfaces and subsidiary class loaders. I don't know the details of how it works, though, because it comes in the context of a bunch of other component-related features that I have never had time to study.
