Sunday, December 19, 2010

Why The PS3 Drives Me Crazy

Let me lead with a compliment. The PS3 is an amazing piece of engineering. The possibilities for this device are huge, which makes its overall sucking that much more sad. The best of the PS3 games clearly surpass its other console competition. Uncharted 2, for instance, is like being inside of a movie -- I can't say enough about it.

But that brings me to why I can't stand this device:

* every time you turn it on it requires a system update

* system updates block the entire UI ... oh you want to play a game? sitting for 10 minutes is pretty fun, too.

* the store is organized in ridiculous ways. you can't find anything. want to see the highest rated game demos? instead, they give you "A-F" "G-M" categories.

* buy something from the store. it doesn't download immediately. it brings you to a screen where you can decide to download it. bitch, i just spent $15 -- of course i want it now.

* the sounds in the store are super annoying. every selection is a really high pitched "ping" and scrolling through a long list will drive you crazy.

* the grid view in the store (which they use all over the place) has no linear navigation. you have to right, right, right, down, left, left, left, down, right, right ,right, down, left, left, left through it.

* when you download something from the store, there's no direct way to see that it's actually doing it -- you go all the way back out of the store to the "Download Manager"

* if you weren't sure it was downloading and clicked "download" more than once? yep .. you got it ... multiple concurrent downloads of the same fucking thing.

* if you want to remove a download from the download manager, you'd think "select it and then pick delete". instead when you select it, it takes you to a full screen that shows the icon and its file size. no options. if you go back out and instead hit the triangle button, THEN you get a menu of choices to "cancel" it.

* once you download something, it's not ready to play. you have to select it and then "install" it. are you serious? why in the world would i download something and not want it automatically installed?

* it's a total ui for nerds ... the FIRST menu item (after the login) is "settings," which has hundreds of advanced settings. why is that front-and-center? presumably after configuring it the first time, I never want to see this again.

* playing a blu-ray movie is a fun experience, too. you put the disc in ... and you sit ... and nothing happens ... so you start looking around, and the choice to play the movie is labeled something like "Play BD-ROM"

* the controls INSIDE a blu-ray movie are fantastic. there is no simple, common, controls ui -- it's every button you can possibly press in a tiny grid and you arrow over to the thing you want to press. i was pretty quickly lost in the controls trying to just navigate the menus reliably using the controller

* speaking of the controller, it took them quite a while top put out a system update that made it so your controller didn't just drain its batteries if you leave it sitting without remember to turn each one off. i'm still not sure that's the default setting even now.

* if you ever use the apps they provide in the "internet browser," you'll notice they're custom built for the PS3 and look TERRIBLE. them main menu labels on the youtube app don't fit in the buttons and all have ellipsis. it's BUILT for PS3. why would you custom build something that doesn't fit?

Wednesday, November 10, 2010

Switching from Subversive back to Subclipse

If you switch from Subversive to Subclipse, you will find that projects that were attached to subversive in existing workspaces will not offer you the option to Team=>Share... There are a couple workarounds for this:

Annoying and Tedious Way
  1. Before switching to Subclipse, Team=>Disconnect your subversive projects
  2. Uninstall Subversive
  3. Install Subclipse
  4. Team=>Share away

Annoying but Simple Way
  1. Toss everything and check it back out again with Subclipse

Atomic but Quick Way
  1. Uninstall Subversive
  2. Install Subclipse
  3. Quit eclipse
  4. Go to your workspace folder and run:
    find .metadata/.plugins/org.eclipse.core.resources/.projects -name 'properties.index' -delete
  5. Restart eclipse

Monday, February 22, 2010

Are Generic Methods evil?

Over the weekend I ran into an interesting design issue inside of ERRest. Java supports declaring generic methods that can perform a simple type inference:

public class NonGenericClass {
    public  T objectForKey(String key) { ... }
}

What this allows you to do is:

Person p = new NonGenericClass().objectForKey("person")

Notice that we don't have to cast to Person like you would if objectForKey returned Object. So ... is this bad form? The closest examples of Sun using type inference in the core libraries is Collections.emptyList(), which can give you a type-inferred List. The difference, though, is that this is an inherently safe operation. In the example above, that code is inherently unsafe. On the upside, your API becomes easier to use -- your users don't need to think about the cast. On the downside, you might say the API is misleading, implying that this operation is in some way typesafe when it clearly is not.

I came to a happy place with it. My decision was that if this API is impossible to make type-safe (think ResultSet.getObject(String)), and if that's fairly obvious to the user of the API, then taking advantage of type inference is OK and will just save your API users time.

One catch, by the way, is that javac appears to not like a double indirection of type inference:

public class ClassOne {
    public  T methodOne() {
        return ...;
    }
}

public class ClassTwo {
    public  T methodTwo() {
      return new ClassOne().methodOne(); // this is a compile error in javac
    }
}

For some reason, javac is not capable of returning an inferred type for a method call to a method that returns and inferred type. You have to cast to T:

public class ClassTwo {
    public  T methodTwo() {
      return (T)new ClassOne().methodOne(); // this makes javac happy
    }
}

Incidentally, the Eclipse compiler is fine with the first one and doesn't need the cast. I think this is a javac bug, personally.

Sunday, May 17, 2009

Maclipse 3.4.2 Fixed ... More

You may have noticed that Java=>Editor=>Templates throws an exception with Maclipse ... That's because there is some code that presumes there is a non-null vertical scrollbar. With Maclipse, we autohide scrollbars on Leopard, which causes an NPE in that code. I avoided fixing this because it brought in an entirely new plugin that we had to hack, but it's just one line, so .. meh.. at this point, why stop now.

So to prevent that exception, you will want to grab the Workbench Texteditor UI plugin provided in the links area.

cd /Developer/Applications/eclipse/plugins && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.swt.carbon.macosx_3.4.1.v3452b.jar && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.ui.workbench_3.4.2.M20090127-1700.jar && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.ui.workbench.texteditor_3.4.1.r341_v20080827-1100.jar

Maclipse 3.4.2 Fixed

The build from last night was missing a MANIFEST.MF, so it wasn't exporting the plugin info properly. I think this would only be a problem if you do plugin development, but regardless, you should grab the new build.

Saturday, May 16, 2009

Maclipse Eclipse 3.4.2 Updates

Maclipse has been updated with all the changes merged in from Eclipse 3.4.2 finally. Links on the right, same install process applies.

cd /Developer/Applications/eclipse/plugins && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.swt.carbon.macosx_3.4.1.v3452b.jar && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.ui.workbench_3.4.2.M20090127-1700.jar

You may also need to remove your eclipse configuration/org.eclipse.osgi/bundles folder (which contains the unjar'd SWT jnilibs).

Wednesday, January 21, 2009

Never hashCode on a mutable value Revisited

In the "Never hashCode on a mutable value" post, I talked about the pitfalls of using a mutable value in your hashCode/equals computation. Another subtle variant of this is using a Comparator for a mutable value in a TreeSet (or other similar data structures). Because the set is sorted internally, and optimized based on that sort information, if you change the sorted value of one of your objects in the set, it can "disappear" if you attempt to .contains(..) check it later. I wonder how many more of these stupid mistakes I'll find ...

Monday, January 19, 2009

Slow PS3 Wireless Connection

props to this guy ... if your PS3 wireless connection is ungodly slow, change your router from Mixed to G-Only. it's stupid, but it was about a 10x speed boost (... back to normal, basically).

Open Type can't find your class?

I ran into an annoying case when switching frequently between workspaces and doing some really mean things to a couple of them with swapping out external frameworks repeatedly. Somehow I managed to corrupt my type caches in Eclipse so that the Open Type dialog would just be missing some entries (which is REALLY annoying, I might add). This would also manifest as java type completion not working for the missing classes. Maybe there's a nice way in Eclipse to do this, but I couldn't find it, but you can toss your type caches. Quit Eclipse, go to workspace/.metadata/.plugins/org.eclipse.jdt.core and remove *.index and savedIndexNames.txt. When you restart Eclipse it will rebuild the entire type cache and life should be happy again.

Monday, November 24, 2008

JSEditor is gone, but not really

JSEditor disappeared from Adobe Labs and is not only available inside of Flex Builder, but it turns out that the install site is still there and is actually the same version included in Flex Builder. You can add the install site: http://download.macromedia.com/pub/labs/jseclipse/autoinstall/site.xml and it will install. You will probably need to set JSEditor to be your editor for *.js

Friday, November 21, 2008

Maclipse Eclipse 3.4.1 Updates

Maclipse has been updated with all the changes merged in from Eclipse 3.4.1 finally. Links on the right, same install process applies.

Thursday, November 20, 2008

Never hashCode on a mutable value.

public class Terrible {
 public static void main(String[] args) {
  HashSet people = new HashSet();
  Person originallyMike = new Person("Mike");
  people.add(originallyMike);
  System.out.println("Terrible.main: Contains Mike? " + people.contains(new Person("Mike")));
  System.out.println("Terrible.main: Changing stored name from Mike to Adam.");
  originallyMike._name = "Adam";
  System.out.println("Terrible.main: Contains Mike? " + people.contains(new Person("Mike")));
  System.out.println("Terrible.main: Contains Adam? " + people.contains(new Person("Adam")));

 }

 public static class Person {
  public String _name;

  public Person(String name) {
   _name = name;
  }

  @Override
  public int hashCode() {
   return _name.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
   return obj instanceof Person && ((Person) obj)._name.equals(_name);
  }
 }
}
prints:
Terrible.main: Contains Mike? true
Terrible.main: Changing stored name from Mike to Adam.
Terrible.main: Contains Mike? false
Terrible.main: Contains Adam? false
HashSet uses the hashcode of your object to select the bucket for your object. If your hashCode changes, the object effectively disappears from the collection for the purposes of API calls like .contains(..). So do yourself a favor and never use a mutable value in your .hashCode (which also, incidentally, means that you can't use a mutable value in your .equals(..) since those two methods are required to be mutually consistent).

Wednesday, October 29, 2008

Saturday, October 18, 2008

How does WOSwitchComponent actually work again?

(from the mailing list, but it really should have been a blog post :) )

jad WOSwitchComponent and walk through and explain to yourself why WOSwitchComponent doesn't show the same instance of a component for every session in your app, particularly given that there will only be one instance of a WOSwitchComponent on a given parsed page (meaning that if there's a WOSwitchComponent for an element in your Main component, there will only be ONE INSTANCE of WOSwitchComponent servicing that slot on the page for all of your users). Prepare to get a much deeper understanding and appreciation of how WO works and how clever the original authors were.

So the magic is WOComponentReference + WOComponentDefinition + WOComponent. What happens is that when your template is parsed, it gets parsed into a bunch of WOComponentReferences. If you understand WOAssociation, WOComponentReference is like the equivalent concept for components. That is, you have a handle that says "I represent an AjaxInPlace with a set of bindings" but it's not a stateful instance, it just describes how you're going to use it.

During parsing an entire tree of these is built up. It represents your parsed template without state. The sort of interesting part is that these things actually extend WODynamicElement, so they LOOK like components from the outside.

What happens is, and this is the kind of neat and clever part, is that at runtime, you say pageWithName("MyPage"). You get a new instance of the top level component. For each parsed element on the page (a WOComponentReference), the framework will walk down the tree and say "give me a stateful peer for this WOComponentReference for a component of this name, and use this set of bindings". It's here, btw, that it can decide whether subcomponents get new instances or come from the shared pool. Then the part that I DIDN'T know about -- the way these are connected is that the new instance of a child component is pushed into a dictionary in the WOComponent parent keyed off of element ID, so the framework can walk down the parsed tree and say to the parent, "give me your child component with the elementID x". If this component has already been materialized, the component will hand back a subcomponent from its dictionary. If one isn't there, it will make a new one and push it into the dictionary. So this starts to make sense, now, why you always get a new top level component instance -- it's the root of the state tree. There has to be a root node to hang all these stateful components off of. The magic method for all of this is actually WOComponentDefinition._componentInstanceInContext(context), btw.

So fundamentally, there's this stateless tree of elements that represents my entire parsed page and there's this stateful tree of WOComponent instances that represent the actual components of the page. So in normal components, the structure of your page is basically predetermined -- you have a bunch of WOConditionals, WOStrings, AjaxInPlace's, etc, all in a tree and page state determines which path through this graph you take. WOSwitchComponent, though, is a crazy twist on this. WOSwitchComponent DYNAMICALLY determines its page structure -- that is, the "parsed side" is indeterminate for a WOSwitchComponent. And if you look at WOSwitchComponent, this is exactly what it's doing. When you ask for a "SomeComponent", the cache doesn't return to you a WOComponent of the class you asked for, but instead a WOComponentReference -- those stateless handles. It's clever as hell. When it needs the component to work on, it looks up the correct instance of WOComponent based on the reference that it has cached (that is shared by everyone!) by asking the context().component() for a child with the current elementID, and will make one if it doesn't exist. So WOSwitchComponent takes advantage of this peer concept and basically builds this structure up itself on-the-fly. When this clicked for me, it was a "woah .. that's really slick" moment.

All of this finagling on my part was because I wanted to implement a new type of component that would allow you to, for instance, create a component on your page that would act like an "embedded page," where instead of having the result of invokeAction replace the entire page, it would instead just replace the embedded page component. To do this, you have to muck with page structure on-the-fly, which is pretty similar to what WOSwitchComponent does, but changing over time. So I just pulled up WOSwitchComponent and thought "I'll just base my code on this - -should be pretty easy" except that I looked at WOSwitchComponent and decided that it's impossible that it actually worked right :) But it does, and I began my quest to find out how :)

Incidentally, I THINK (haven't verified yet) that the third parameter to the constructor of a WODynamicElement, which I've always sort of wondered its exact purpose, is your stateless-parsed-element-peer. So you're being handed the reference to your stateless equivalent in the parse tree. This is my theory, at least. This gives you access to the structure of your children components, which during the R-R loop can also be used to access the stateful peers, etc.

So anyway ... That's the long story that probably nobody else cares about, but I think it's sort of a fascinating aspect of WO, because it's this crazy and clever underpinning that makes the entire framework function that I really had no idea about the inner workings of.

Thursday, October 9, 2008

iPhone Layer Edge Antialiasing

Apply your rotation transform to that layer and look how beautiful it is in the simulator -- nicely antialiased rotated layer edges. Drop it on the phone and you might be surprised to find that it looks like crap. It turns out that layers don't have antialiased edges on the iPhone, so just keep that in mind if you're planning on using layer rotations, especially.

iPhone Image Benchmarks

There are two functions you can call for encoding UIImages on the iPhone -- UIImageJPEGRepresentation and UIImagePNGRepresentation. For my app, I was curious about the performance of the two image formats. I ran some tests on JPEG with various compression qualities, PNG, and Simulator vs iPhone 3G on 2.1.

The image tested was a 320x416 image (about 120k JPG @ max quality) of line drawing, repeated 10 times for each scenario and averaged. For the writing tests, the images were encoded and then written to disk. For the reading tests, the image is read and then drawn to an offscreen bitmap to make sure the bytes were actually read off the drive.

Note that q=0.0 is max compression, min quality; and q=1.0 is min compression, max quality.

Simulator Writing
jpg, q=0.000000, 0.018185 seconds avg
jpg, q=1.000000, 0.017662 seconds avg
png, 0.034456 seconds avg

Simulator Reading
jpg @ q=0.000000, 0.005052 seconds avg
jpg @ q=1.000000, 0.000838 seconds avg
png, 0.021330 seconds avg

iPhone 3G 2.1 Writing
jpg, q=0.000000, 0.255950 seconds avg
jpg, q=1.000000, 0.265089 seconds avg
png, 0.592170 seconds avg

iPhone 3G 2.1 Reading
jpg @ q=0.000000, 0.138772 seconds avg
jpg @ q=1.000000, 0.049013 seconds avg
png, 0.065347 seconds avg

Conclusion
In this test scenario, JPG writing is about 2.3 times faster than PNG writing on the 3G regardless of quality. On the flip side, JPG reading at max quality is 1.3x faster than PNG, but 2.1x SLOWER than PNG at max compression.

So if we take the best quality comparison, JPG is 2x faster to write and 1.3x faster to read. You'll have to compare image quality in your particular case, but JPG seems to win hands-down for me.

You can also look at the comparisons between iPhone and Simulator and prove to yourself that you should definitely not use the simulator to judge anything about runtime performance of your app on the real device, which I don't guess anyone REALLY had to tell you.

Wednesday, July 30, 2008

Note for the New Version

There is a new Maclipse build that incorporates the disappearing cursor patch from the SWT guys (https://bugs.eclipse.org/bugs/show_bug.cgi?id=241671) that will be in 3.4.1.

The catch, though, is that it requires a patch to the jnilibs, which might break when you launch eclipse because the jnilibs are already "cached" in your bundles folder. If your Eclipse crashes right on startup, toss your "eclipse/configuration/org.eclipse.osgi/bundles" folder, which will cause it to unpack the jnilibs from the jar again at startup. I may be able to set a custom version number in our SWT build to force this to happen, but at the moment, I didn't want to mess with it.

Monday, July 7, 2008

SWT issue

If you grabbed the SWT plugin after I switched to github, grab it one more time. When I imported into github, I rooted my branch at the R3_4_maintenance branch of SWT, but apparently that has all kinds of other commits in it (in particular some broken ones :) ). I have since switched back to my original baseline of the v3448f version of SWT (which is what ships in 3.4):

If you're following along at home, the new github link to my branch is:

https://github.com/mschrag/maclipse_swt/commits/mschrag_v3448f

Easy Jar Updating

From Anjo:

cd /Applications/Eclipse/plugins && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.swt.carbon.macosx_3.4.0.v3448f.jar && curl -O http://webobjects.mdimension.com/wolips/preview/org.eclipse.ui.workbench_3.4.0.I20080606-1300.jar

Sunday, July 6, 2008

All of Maclipse is on GitHub

The Equinox Executable plugin (which adds support for double-clickable eomodels opening in Entity Modeler, for instance)

http://github.com/mschrag/maclipse_equinox_executable/commits/mschrag_R3_4_maintenance

The Workbench UI plugin:

http://github.com/mschrag/maclipse_ui_workbench/commits/mschrag_R3_4_maintenance