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.

Why emacs is still in my toolbelt

When I first started out as a developer one of the crackpot nutjobs with whom I worked at the time convinced me that emacs was absolutely the best editor to use.  I didn’t really know any better and he was by far the fastest and most nimble code navigator of anyone else in the group so I gave it a try.  Many hundreds of hours of elisp hacking and a 37MB ~/.emacs.d directory later I am a fairly well worn emacs yeoman.  For many years I used nothing but emacs, cramming all sorts of language modes in it to make it do fun stuff and syntax highlight everything from shell script to Java to Ruby to InstallScript (insert vomiting in own mouth joke here).

I say, with no small amount of nostalgia, that emacs is no longer the development workhorse it once was for me.  I spend most of my time writing large Java projects and have fallen prey to the siren song of fancy IDE’s with their “Show me a list of all the places this specific method is called anywhere in my project” tricks and “Refactor this entire package hierarchy with all the file renaming and moving and even rename the getters and setters to reflect the new names” chicanery.  Emacs had a few tricks to make it look like it was doing these things but it was always kinda hacky and required a great deal of TLC to keep it working across JDK upgrades and switching projects with environment variables and jdk-* elisp variables that were just right.

All that said, you can have my emacs when you pry it from my cold dead hands, and here’s a glimpse into why:

  1. Zip file handling smooth as a baby’s butt
    Have you ever tried to open a zip file with emacs?  Give it a try, its awesome. It shows you a normal list of all of the files in the zip archive.  No big deal, right?  Now move the cursor onto one of the files.  Shows you the file, doesn’t it.  Not bad, huh?  Now try editing the file.  Let’s you edit it, doesn’t it.  Now try saving it.  Oh baby.  Right back into the archive where it belongs and you don’t even have temp files to clean up.  Seriously? That’s worth the price of admission right there.
  2. That’s what you’re computer is for, numbskull
    If I see one more person with their hands hovering over their keyboards in some weird way just so that they can type “Down arrow, End, BkSpace, BkSpace” over and over for every line in a 500 line file I’m going to scream.  I know emacs is not the only editor that does simple macro recording and playback, but if your editor doesn’t have that (yes, I’m staring at your Eclipse) then you most likely have wasted some time this week.
    “C-x-( <do your thing here> C-x-) Ctrl-u 500 C-e” and 500 lines later your done.  Menial tasks should not be done by people.
  3. Graphical and terminal mode
    This may be specific to you server developers out there, but sometimes you just need a decent editor on a headless server.  I know, I know, use vi. If I wanted to ask my editors permission to type a letter I would install Clippy (ducks).  Sorry, had to get that in there.  Having a workable dev environment on a headless server has been a huge help on many occasions where fun graphical wizbang is just not an option.
  4. Cross Platform
    Linux, OS X, Solaris, even Windows if I really have to, but emacs comes with me everywhere.  It always works and so does my well worn ~/.emacs.d directory of everything I’ve ever needed.  Its a great way to lower the cognitive load of jumping around all the time.  What good is your trust side kick if it doesn’t come with you wherever the fates may carry you?

The list really goes on and on.  The idea here is less about emacs specifically and having really amazingly good reliable all purpose text editor to sit next to your honkin’ cool IDE and fill in the gaps.  If you are a gainfully employed programmer and you use notepad.exe for anything, then you are a thief stealing from your employer.

I’ll be honest, I spend a lot less time in emacs than I used to, but every good carpenter needs a good hacksaw/screwdriver/nail puller/hedge trimmer/ladder/rotary drill/french coffee press/drop cloth/tire rotater.  Right?

xkcd emacs comic

Follow

Get every new post delivered to your Inbox.