Sunday, February 24, 2013

Eclipse Open in New Window

Two posts in one day?  Crazy Jess!

So, I sometimes discover things by accident, and this is one of those times I clicked something weird and discovered coolness.  In eclipse you can right click the Project Explorer and select Open in New Window.  An entire new Eclipse workbench opens.  OK, so not a huge deal right?  Well, you can have "Data" perspective open in one window with all your hottest, awesomest SQL's ready to fire away, and a second window open with all your nasty java code.  Life is good.  I was tried of switching between perspectives and trying to find my SQL file.

Javascript alert is bad


Just a quick post.  I just decided to NEVER use the javascript alert function for debugging again.

  1. It's a pretty crude method of debugging.
  2. If you get an alert in a loop, get ready to close 100 pop ups.  (Some browsers are cool about this)
  3. Oops, I forgot to take it out when I deployed to the test system.  (Like I just did)
  4. There are probably other reasons, like what happens when you test your code outside of a browser?
Anyway, I already have a wrapper around console.log() that will be graceful if console.log is not available, so I need to remember to use that instead and forget about alert()!

Monday, February 4, 2013

Java private vs protected as a default for members

I was thinking today about an interview I recently sat in on.  The candidate was asked if they default their java member variables to protected for private.  He said private.  I have some other friends who advocate that too.

I have always been more in favor of protected.  I like to use inheritance and having protected members allows me to access those members directly.  This was in the context of a video game where I had a base sprite class with simple things such as x,y coordinates and an image.  Then I had several different types of subclasses like animated sprite and maybe even something specific as a monster class.  Having protected members worked well.

I think the answer to this question is really that "it depends".  I had a thought recently about lazy loading and protected memebers.  If your base class has a protected member that is lazy loaded (null until the getter is called), then if you try to access it in a subclass, it might be null!  If the member was declared private you would be forced to call the getter and everything would work out all right.  So if you are writing a database application or anything else where you use lazy loading, private is the way to go.