Java Heaps and Garbage Collection with some Zazz

Here is a presentation I put together about Java heaps and garbage collection to go into some more detail than just raising the heap size. I put in links to some great websites and blog posts that are fantastic reads if you are trying to tune your app’s garbage collector.

The best part though is the “wicked awesome” presentation tool Prezi. It is an infinitely zoomable moving twisting camera landscape thingy . . . its kinda hard to describe. But it makes PowerPoint look like two cups with a string between them. Just check it out.

You can view it fullscreen and Prezi lets you copy presentations and modify them. Here is the direct link to the presentation above if you want to copy it. You can download a self contained offline viewer of a presentation you own (or one you’ve copied).

Typed variables in an untyped world

First, off, I’m a static type person.  Sorry, but I like me some static typing. It makes me feel warm and squishy.  It makes my IDE more useful.  I can refactor an entire code base and go to sleep and not have nightmares.

Moving on, I’ve been using Groovy for unit testing a lot lately and have decided something. I like it. Its really nice to not have to deal with exceptions and be able to create lists and maps inline.  Closures kick butt.  Its really nice and easy. However, the lack of types that enable some of the cool things bug me, but they don’t have to.

Because groovy is a dynamic language you don’t have to provide the type of any given variable. This can be good and bad. Its sometimes convenient when you don’t know or don’t care what the type of a variable is.  However, in most cases, when you do know what the variable type is, it can be helpful to put type the variable.

// untyped, but it is really an ArrayList
def someVariable = ["1","2","3"]

// same idea but now you know the type
List someList = ["1","2","3"]

Now, of course, you could have deduced the type of someVariable given its assignment, but apparently your IDE is not that smart, at least Eclipse isn’t. Especially if its one of my types and not a built in type. One of the main reasons that I type variables is that if you explicitly type them, Eclipse can do auto completion on the method names of your variable.  If you use def to declare your variable Eclipse only gives you the default GroovyObject methods.  Not the best.

Also, providing types with method signatures makes it FAR FAR FAR more obvious what you are expecting of your caller.

Consider a method with the signature:

def someMethod(def thing1, def thing2, def thing3){
...
}

Mmmmmmyeah. I have no idea what to pass to that thing. I also don’t know what its going to give back to me.

Don’t get me wrong, there are times when you don’t know some of these things or its more convenient not to declare them statically, but I have found that if you actually know at compile time what something is going to be, you may want to grease back your hair with your back pocket comb in your black leather jacket and stick it to the man with a quick def, but you from two weeks in the future and the next guy to read your code will be much happier if you throw a few types in there.

Simple Interrupt Driven Multitasking with scripts

Compiling. Searching. Downloading with wget. They take a long time and are kind of boring to stare at. You have two choices. Choice one is to follow the xkcd model:

xkcd comic about wasting time compiling

xkcd comic about wasting time compiling

But once in a while, you actually have some other stuff to do. Maybe if you had a few minutes you could go a few emails closer to Inbox Zero or you could go watch something to make you smarter or go read something. Either way, if you’re like me and that guy from Momento and you try to do something else useful while your computer is working you will immediate forget that it was off doing your bidding and you will stumble across the idle terminal hours/days later.

Here’s a really quick solution. Put this script in your path somewhere.

#!/bin/bash

if [ $(uname) = "Darwin" ] ; then
  # osascript doesn't allow you to interact with the UI so just raise the terminal
  osascript < /dev/null 2>&1
elif [ $(uname) = "Linux" ] ; then
  zenity --title "Finished" --info --text "I'm done doing what you asked." > /dev/null 2>&1
elif [ $(uname) = "Cygwin" ] ; then
  echo "Left as an exercise for the reader. Helpful hints may be found at http://store.apple.com and http://ubuntu.com"
else
  echo "Unknown platform: $(uname)"
  exit 1
fi

I call it fin like that classy word at the end of old movies.

Then when you start a long running command run it like this:
bash$ go-search-my-whole-harddrive.sh ; fin
or
bash$ compile-my-kernel.sh ; fin

Then, when your thing is done, whether it worked or not, you will get some sort of indication that its done and you can get back to what you were doing.

I have really started to love this little script the last few days. One thing though, make sure that the other thing you start to do while waiting is an easily interruptable task or your brain will explode when the indication pops up. No one likes brain explosions.

Follow

Get every new post delivered to your Inbox.