Sublime to RubyMine to RubyMine + Vim to...?

As glamorous as the life of a co-contributor to a sort-of-kind-of-well-respected open source library is, I think one of the best perks is being able to cash in on the free, open source license of RubyMine. It took a bit of coaxing, mostly in the form of a lot of positive feedback from /r/ruby, and I was hooked after a few weeks.

A few weeks ago, though, I became mildly envious of my friends' at work who flew around the screens with Vim. I love keyboard shortcuts, always have, and the potential to make the editing process significantly faster was really attractive. Still, I love RubyMine's features, so... what was I to do?

Enter IdeaVim, the Vim emulator for RubyMine. Hallelujah, I have been saved! Real fast, I'll run through what I like best about this union.

RubyMine features I can't live without

  • CMD + Click on any method to go to its definition, even if it's in a dependency.
  • Right-click and there's an option to find all usages of a method.
  • Highlight and CMD + Option + M to extract code into a new method. It finds variables and makes them arguments. Fuuuuck! So cool.
  • YARD integration. If you annotate your methods, it will use the info to improve its code completion.
  • The best find/replace/rename options I've ever encountered.
  • Method calls get pointed out if I send the wrong number of arguments.

I know that's not much — it's sure as hell nowhere close to taking advantage of everything RubyMine offers — but they're all huge, huge game-changers. The thought of not having the ability to locate method source is brutal, I think it's a crucial option for anyone working with large codebases.

There are a few other features that are cool but just not for me. I use the test support on occasion but tend to want to run the same one or two specs repeatedly, not an entire file, so it's usually overkill. As for git, I find the CLI more comfortable, though its integration does seem fantastic. Finally, the Rails features are extremely cool but I rarely work with it, so they're lost on me.

Vim makes things faster

A lot of Vim users go crazy with plugins. It seems only natural, since every itch seems to be scratched by something that's very focused and sounds very helpful, but all that power comes with a steep learning curve. I think I'm mitigating that by focusing on the basics: fast movement around the screen and word/line deletion/replacement. You don't realize how much time you spend moving around the screen with some combination of mouse + arrow keys + ctrl/home/end until you start using EasyMotion (emacsIDEAs) in my case and get a hang of basic editing.

My Vim list:

  • emacsIDEAs is insane. I have it mapped to (CMD + J)(CMD + F)(char I want to find). It highlights that character all over the screen, replaces it with a character (a thru z) and then I hit that character to jump there on the page. Stolen from Google: Check it out It takes a little getting used to but it's very precise, very helpful.
  • Everything here. Everything.

That's it so far. It might not seem revolutionary but it's one of those "you-have-to-see-it-to-understand" things.

To those getting started with Vim + RubyMine...

I had some problems adjusting and still find some things a little annoying. My quick bullet-points for those who are new:

  • Remap the hotkey that switches from insert to normal mode. I went with (CMD + j)(CMD + j). For some reason, I always have to hit another key — any key — after switching modes for it to register the change. Having to reach up to escape constantly was a real buzzkill.
  • Remap emacsIDEAs basic word search. I went with (CMD + j)(CMD + f) and remember it like "jump" + "find". It's helpful because those two characters are always accessible.
  • Don't be afraid to turn off Vim mode if you're frustrated. The nice thing about the plugin is that you still have RubyMine backing you, so it's not like you're going back to Notepad in its absence.

In Conclusion

I imagine that if this post is read by anyone, it will be people considering the switch to either or both. If that describes you, my advice is to go for it but go slow, don't feel pressured to use every new feature at all once. While the Vim Master Race might push you to use ALL THE PLUGINS ALL THE TIME, I find that it's such a huge paradigm shift from a traditional text editor that a slow ramping up is helpful. Find the tools that are easiest to work into your workflow, gradually increase resistance. Right away, you'll find an improvement in your work, and in time, things will only get better!

For my next trick, I intend to get better with Vim away from RubyMine. I've been doing a bit with Rust lately and find the switch back to SublimeText like... barely a step up from Notepad, frankly, but I'm still struggling with folder navigation and window management in MacVim. It's a process, I'll get there.

Happy coding!

A Simple API Request/Response Decision Tree

I threw this together for work. I think it’s easy to get lost when designing APIs, web/software/whatever, but keeping this in mind can help you stay focused.

http://i.imgur.com/hdqMaxa.jpg

A Java Crash Course for Ruby Developers, Part 1

(Part 1 of a multi-part series. Introduction.)

Welcome! Let's get right to it. This is going to be largely unstructured and reflects the current state of my Java experience, which is very little. It will hopefully help other devs who are getting started. I expect that:

  • You know some basics about Java
  • You know Ruby basics

I'm not going to mention many things that should be obvious, like... lines are terminated with semi-colons, Java is not sensitive to whitespace, etc,...

Let's do this.

#### Use an IDE for Development.

While you can use a text editor to write Java, every resource I encountered referenced some IDE or another. The two big ones seem to be Eclipse and NetBeans. I ended up with NetBeans, though I honestly can't remember why. Having just switched from SublimeText to RubyMine, this was a pretty easy transition for me, as NetBeans feels a hell of a lot like RM, but it might take some getting used to for you. (Incidentally, JetBrains are the developers of IntelliJ, a Java IDE that I imagine is pretty amazing. It's also not free, so...)

If this is your first time using an IDE, the key features that I can no longer live without are:

  • Command + Click on a method to find its definition.
  • Right-click a method and click "Find Usages" to find everywhere that it's used
  • Highlight, right-click, "Refactor" menu to easily move pieces of code into methods, new classes, sub/parent classes, etc,...
  • Built in test integration and compilation
  • Easy dependency management
  • Flagging unused variables and dependencies
  • Hints RE: object types required during method calls or class initialization

Focus on that and you'll adjust in no time.

Don't start from nothing. Find an open source project to modify.

Starting a new language can be daunting, especially something like Java that introduces some concepts that are very different from Ruby. I set my sights on GraphAware's TimeTree plugin for Neo4j, found where the public API endpoints were exposed, copied the methods, and started modifying from there. Anyone who learned HTML in the days before CodeAcademy and sites like it will probably have done this at some point.

Plan on writing tests.

Because Java is compiled, it's very annoying to test your code by poking at it in your app. Write small methods, test carefully, and you'll save yourself a lot of time. There's JUnit, which uses methods and simple assert methods to test behavior (sound familiar?) and there's also Cucumber-JVM, if you're more comfortable there.

Class Definitions

One of the hardest parts of figuring out Java for me was just reading the damn code. You should already know that Java is strongly typed, but... final? Static? Void? WTF? This ends up being very easy.

Basic class Signature Examples

The typical Java class signature looks like this:

public class MyClass {}

That makes sense, right? public, protected, or private define visibility, just like Ruby. The rest is self-explanatory. Java has single inheritance and uses extends, so:

public class MyClass extends AnotherClass {}

Interfaces

Instead of modules, Java has interfaces. An interface lists methods that must be implemented in the class. It deals with what is there but not how they will behave. (NOTE: In Java 8, you can define default behavior for interface methods. This helps you out in the event you want to add a method to an interface that is widely implemented.) A class that includes an interface looks like this:

public class MyClass implements MyInterface {}

At that point, any methods defined in MyInterface are expected to also be defined in MyClass. If they aren't and default behavior isn't provided in the interface, your code will not compile.

Interfaces are extremely helpful because when it comes to method signatures, you can say that a method expects or returns a MyInterface instead of MyClass. It would be like doing this in Ruby:

module MyModule; end
class MyClass
  extend MyModule
end

# Will return true
MyClass.new.is_a?(MyModule)

Ruby doesn't work that way; instead, we'd use respond_to?, but Java's way gets us to the same place by a different route: we are checking that a given object has specific behavior implemented. We care less about the object and more about what it can or cannot do.

There's a lot more to interfaces than I'm going to get into now, but this is a good start.

There is no initialize method, but...

Instead of initialize, you define a method of the same name as the class and do not include a return value.

public class MyClass {
  public AnotherClass myVar;

  public MyClass(AnotherClass myVar) {
    this.myVar = myVar;
  }
}

That means that MyClass is initialized with one argument, an object of type AnotherClass, that will be referred to within its init method as myVar. Once instantiated, myObj.myVar will be set to this argument. For example:

# Define the variable
MyClass myObj;
# Instantiate the object
myObj = new MyClass(myOtherObj);
# call `myVar`, will return `myOtherObj`
return myObj.myVar;

There can be multiple constructors for a class

Java makes it possible to instantiate a new object using many different arguments, just define multiple constructor methods.

public class MyClass {
  public MyClass(AnotherClass myVar) {
    # do something
  }

  public MyClass(DifferentClass myMar, AnotherClass myOtherVar) {
    # do something
  }
}

Of course, the constructor methods would do something with those vars. Point is, you have flexibility in how you instantiate objects. This same rule holds true for methods.

Method definitions

Basic Method Signature Examples

Method signatures can omit visibility and will default to public but the best practice seems to always include it. They look like this:

public ReturnType methodName(FirstArgClass firstVar, SecondArgClass secondVar) {
  # Some code
  return # something here
}

Note that every method identifies not only what types of objects it expects but what it returns. To define a method that does not return anything, use the void keyword.

public void ReturnType methodName() {
  # do something but do not call `return`!
}

To define a class method, use the static keyword.

public static ReturnType methodName() { return null; }

Method arguments are typed

Method arguments follow the simple pattern of ObjectType variableName, separated by commas.

public String myMethod(String firstVar, int secondVar) {
  return firstVar;
}

There's not much more to it than that.

Variables

Variables are declared with types

This shouldn't have to be said at this point but:

String myVar;

That would allocate memory for a new String with name myVar.

Declarations can be assigned immediately... but this does not seem to be best practice

You can do this:

# assume `thisOtherMethod` returns something of type MyObj...
MyObj var1 = thisOtherMethod(anotherVar);

My IDE corrects me when I do this, though, so I get the sense that it's a best practice to declare first, then assign.

Instance variables

Define instance variables in the body of your class.

public class MyClass {
  public String myString;
  public List myList;
}

Those can now be assigned within methods. This is the equivalent of @var in Ruby.

Class variables

Define class variables using the static keyword in the body of the class.

public class MyClass {
  public static String myString;
}

Constants

Define constants using both static and final.

public class MyClass {
  private static final String myString = 'oh hai';
}

The final keyword indicates a value that cannot be changed.


That's it for now. Keep an eye out for part two. Hope this helps someone out.

A Java Crash Course for Ruby Developers, Part 0

I've been working with Neo4j for something like two years now. I started with Ruby and Neo4j.rb 2.3, which used JRuby 1.7.x with Neo4j Embedded 1.9, and learned Ruby, Neo4j, Rails, and the Neo4j.rb gem concurrently. Funny as it might be, I made it pretty far without ever writing much more than an extremely basic Cypher query for over a year. Phillymetal.com is built entirely on this stack but there's very little "graphy" stuff going on. Neo4j Embedded is so fast that working with the database has almost no overhead for simple find/return/traverse operations, so I was mostly exploiting the easy data modeling and schema-free goodness.

Things changed last year when I started contributing heavily to the Neo4j.rb gem, then got even more intense when I ramped up work on my own project. As performance became more of a concern, I started writing more Cypher to limit the number of queries in and out of the database. As it turns out, Ruby seems to be Neo4j.rb's biggest problem, but the fact is still that the REST API with Neo4j 2.1.7 is just not as performant as Java and Neo4j Embedded.

Enter unmanaged extensions and the Java API. Neo4j has a very cool feature: since it is open source and exposes a REST API, they provide an easy way to write your own plugins, "unmanaged extensions," that expose new REST endpoints. Once your data hits that endpoint, you can use the Java API to do all your work, then you return whatever you want back to your application. This gives you the best of both worlds: Cypher when you need it, Java API for the heavy lifting. Without exception, everyone I know who needs serious performance from Neo4j has told me that they fall back to this method.

At work, we're building an ambitious social media analytics platform that relies heavily on Neo4j. It's collecting a lot of data and revealing a lot of interesting connections. The front-end app is a client of the JSON API my team is building and the goal is for it to have the feel of a desktop app. This means it wants a ton of data very fast. Unfortunately, the combination of our query, the amount of data, the REST API, and Neo4j.rb just do not make for the performance we're looking for. Without getting into how much data we're returning, I can say that we've been seeing 1.5s responses when we really need something closer to 400ms.

I took some steps to improve performance but each time, I got smacked down. I patched Neo4j-core's Query class with an unwrapped method that returns simpler objects, I implemented the amazing GraphAware TimeTree plugin, I optimized the hell out of my query, but we were still having these issues; in fact, the 1.5s response mentioned above is AFTER these optimizations!

After hearing so much about the power of unmanaged extensions, I thought this might be a good opportunity to dive in. Problem was, I had never written a line of Java before. Hell, I had never successfully read a line of Java! Still, I knew what I wanted to do: take the complex Cypher query we're running, rewrite it in Java, return JSON that is usable in the app. To do this, I started looking for resources about Java that were aimed at Rubyists. I figured that with the popularity of both languages, there had to be something out there for Ruby devs looking to learn Java... right? Wrong. Everything I could find was about going from Java to Ruby. Coooool...

I figured I might as well dive into TimeTree to see if I could figure some of it out. I started with the API, since it was all I was really interacting with directly. https://github.com/graphaware/neo4j-timetree/blob/master/src/main/java/com/graphaware/module/timetree/api/TimeTreeApi.java has all the endpoints and figuring out what methods were being called was easy enough. It was also pretty trivial to expose a new endpoint, take a few params, and... make the whole thing crash. A lot.

A few searches and half a book on a plane ride later, I made it to a point that I was able to hack together my own unmanaged extension. In the span of seven days, I was able to write it, extract it from TimeTree, test it, and get it into staging. Our report now runs at around 400ms and I'm going to move more of our app's code into Java ASAP. Victory!

I'm writing this post and what I hope will be a few companion pieces for two reasons.

First, from a Neo4j dev's perspective, I want to illustrate the power of the Java API compared to Cypher. This is not a knock on Cypher in any way, because it is a fantastically expressive, readable, powerful language that I'm always happy to work with, but the superior control you have over your data within Java just can't be understated.

Second, separate from Java, I want to provide a resource for other people who may be in my shoes: Ruby devs who want or need to learn Java quickly but don't want to read through a book that spends a significant amount of time on familiar principles of OOP. As I work with Java, it's going to be harder to remember how I felt about it when I got started, so now is the time to do this.

I don't expect there to be more than one or two other posts about this and I doubt that either of them will be very heavy on Neo4j, if they're mentioned at all. Though I may mention it, it's really not much more than a reference for how I figured some things out. If you are an experienced Java developer, please don't blast me if/when I misstate details, since I'm still learning here.

I'm going to start working on the first piece of this immediately, so stay tuned!

2014: Best/Worst Year in Review

While this blog might not really show it, 2014 was one of the best and worst years of my life.

Professionally, it was a landmark year. In March, I left my job with Valiant Technology, the place that got me out of Philadelphia and into NYC. The end of my time with Valiant also marked the end of my time in that part of the IT industry after nearly 10 years. Goodbye, Hyper-V; hello, Heroku.The plan was to get a startup off the ground. It didn't exactly work out that way, but something even better happened: I realized how much I needed to grow by allowing Neo4j.rb to consume me.

Working with Neo4j and parent Neo Technology resulted in trips to Malmö, Sweden and San Francisco. It opened countless doors, helped me make lot of new friends, and helped me find a sense of both community and professional satisfaction that I've never really known. I wrote a lot of blog posts and made nearly 1500 commits on Github. Phillymetal.com relaunched, I participated in a whirlwind hackathon (that I'll link to when I move it to its new home), and just generally made a ton of stuff I'm extremely proud of. I put my ADHD hyper-focus to use and learned, learned, learned.

There was stress — a shitload of it. If not for the patience and support of my amazing girlfriend, who also left her job for the big ???? of freelance life only to end up in a fantastic new role of her own, I'd have been homeless or living on some generous person's couch sometime around September. I had some lucky breaks along the way (thank you, Utpal and Michael!) and just this morning, I accepted a full-time offer that came largely as a result of my obsessive open source work, dedication to not being shitty at things, and a whole lot of luck. This whole rags-to-something-better-than-rags story will make a better post sometime; for now, the point is that I feel as though it was all worth it because I no longer feel like I'm treading water in an industry that doesn't really have a future for me.

That was the good. It was a banner year, one I'll remember as a massive turning point thanks to the new opportunities and irons on the fire as we enter 2015. But if it was to sit on a scale, if I heaped in every single positive event, big and small, every tiny victory and massive conquest, and condensed it into something tangible, I don't think it could outweigh the single moment of devastation that occurred on January 29, 2014: my mom died of cancer. It crept up on us barely 8 months after it reappeared from 15 years of remission. Melanoma. She went into the hospital with stomach pain one night and was gone the next.

I haven't really written much about it and other than a post on Facebook and some time off of work and I don't think I've even typed it out in months. Seeing it on the screen still kind of feels like a shock. Things changed immediately after it happened: I couldn't handle life in the office, I couldn't deal with other people's schedules or attitudes — hell, I just couldn't deal with other people. A lot of my behavior since then — the decision to switch fields and work by myself from home, the unblinking focus on code, the freezing of every music project, silence on so many public tragedies that normally would have found me engaging in debate — I wonder how much of it was influenced by this. So much of this year was spent trying to process what happened. When the smoke cleared enough for me to see the other side, I think my priorities had changed. I found myself wanting to provide for my father, in whose household my mom was always CEO. I'm so much less interested in drama and dealing with personalities, which made me unwilling to pursue recording bands or playing shows or arguing politics or social issues. I'm filled with regret for things I never said or did. I like to think that I'm more careful with words, more deliberate with actions.

Even now, the world is darker, dirtier. It's as if everything is just slightly out of tune and I feel that dissonance all around me, subtle and unnerving; a constant, creeping vibration, profoundly wrong on a visceral level. For months, I kept waiting for my phone to ring and for someone to say, "Chris, we made a mistake! She's here, she's doing great!" Like a superhero who refuses to stay dead, cause nobody really stays dead, right?

No, the world doesn't work like that, and this is a part of life that every child eventually has to deal with. It's just frustrating that it should happen this year. I feel robbed of the opportunity to show her how things are working out, that her unflinching support and confidence for nearly 30 years wasn't misplaced. It's an incomprehensible feeling, to be so angry an existence itself but not really having anyone or anything specific to blame.

I try to reserve my blog for helpful things, how-tos and records of triumph, or at least cool things I come across as I go, but it didn't seem right to let this year close out without documenting 2014's twisting river of successful and failure. I don't mean to reduce the loss of my mother to some sort of apologue, but if I had to try and explain why I wanted to present this publicly, it would be to make a statement about the interconnectedness of all things. More than ever before, I am aware that we are all products of innumerable people's decisions and actions, nature's amorality, random coincidences, good and bad timing, and a whole lot of generous people. No matter how hard we work at things, we can take a step back and think about what led up to the opportunities, taken and missed, that shape our lives. Hard work is important, but so is awareness of the influence of everyone and everything around us; more importantly, we should take inventory of how cruelly fate could work out, how much worse things could always be.

I think of all the ways it could have been worse, of kids robbed of their parents as children, or kids who never know their parents, or kids who know their parents and hate them or are hated by them. My mom would tell me to think back on this year and be proud of my accomplishments, look after my father, love my friends and girlfriend, and do everything to the best of my abilities. She'd tell me to focus not on loss, but on success, the future, and the things I do have instead of the things I don't. It's a process, I guess, one I've never been very good at, but I'm doing my best, and I guess that's all anyone can really ask for.

subscribe via RSS