Rob Williams is a probabilistic Lean coder of Java and Objective-C. Rob is a DZone MVB and is not an employee of DZone and has posted 170 posts at DZone. You can read more from them at their website. View Full User Profile

A Few Thoughts on Code Completion

09.17.2013
| 11588 views |
  • submit to reddit

Before launching into some philosophical musings about what programmers‘ crack addiction to code completion means, a few observations about my path.

In 2003, I started using Eclipse. Before that I had been using JBuilder a lot. Eclipse launched claiming that incremental compilation was the future and anyone not using it was lost. You would see your errors as you typed. I remember not being that thrilled at that prospect, but I did find, over time, that with eclipse, I was able to get an environment going that was very fast. The wheels started coming off of my love affair with it when first the WTP project turned up lame release after release, and then, after adopting Maven, the plugin situation there just produced stunted, epileptic madness. Also, I got to try Xcode, and wow, I thought ‘this thing is so much faster and cleaner, if only it had a few more things, particularly TDD stuff.‘ Well it has that stuff now and it is no doubt, IMHO, the best IDE there is. Of course, I cannot write big data programs with it, or web stuff, but for mobile and applications, it‘s nuts.

Lately, as per my ranting ‘documentation‘ on here, I have been using IntelliJ, first as part of Android Studio, then for a project using Play and Akka. It drives me bananas because it‘s so slow. I can‘t stand to work in it. I prefer to just tab over to the console and have play run my tests. It‘s really stupid too and it gets crossed up easily, then if I change things in the project, I have to regenerate the project files, which seems so many pales past a diaper I can‘t even really say the feeling it evokes. Anyway, by every other measure, I think that IntelliJ has eclipse handily beaten. Its ‘Live Templates‘ are much better than eclipse‘s templates, which evolved not one iota in the 10 years since I started using them (note, evolved meaning more than some minute crumb toss of silly improvements).

Recently, I stuck my head back into Sublime Edit. The reason is because I was using Bootstrap and I ran into it somewhere, then I saw this tutorial and was kind of ________ (insert your preferred phrase along the lines of blown away). First off, this thing is stupid fast. Secondly, this tutorial shows you things happening that are very compelling. I started to imagine, if I used this for Play, or Akka, what would I miss? Of course, the answer comes back pretty quickly: code completion.

Code completion is pretty great and I have showered as much love and praise on it since it crept into development as anyone. However, today, I was thinking about it, and I got to thinking, it‘s pretty baby-like. Like the IDE is offstage cooing for baby to open his mouth and have each cut piece put in, then to ask for more once that one‘s been chewed up. Now, the counter argument to this is that since the C++/Java cataclysm, we live in a world where we are programming with hundreds of APIs all the time. I have been using Hadoop a bit lately. It‘s a perfect example of what OSS engenders: a big, rambling barnyard of crap, another project for every single little crack that needs some caulk. One of the reasons that Xcode and Apple are such a pleasure is you can learn a framework and then use it for most of your coding, rather than constantly going in and out of tons of little halfwit pseudo frameworks that practice different conventions and have no concept of binding logic (they don‘t know who else you are working with after all).

So I started thinking, could I do some coding in Sublime? and what would that be like? My highest thing in a development environment is Speed of TDD, period. Above all else, then after that, it‘s probably code completion. But I think there might be ways to live without it.

The Staging of Construction
If you think about it, code completion is really needed for two reasons:

  • you are either not familiar with the API of the thing you are using
  • you are not familiar because it was badly designed and failed its heuristic challenge

What would you think the spread of this would be? I would say at least 80% of cases contain some of b. For example, no sane person would debate the fact that Joda is better than the JDK‘s time/date functions. However, I don‘t think Joda is a good API from the perspective of heuristics because I‘ve used it countless times and I never remember all its quirky silliness. I can‘t even remember its concepts, yeah ok, Instant, Duration, etc., but how they map those concepts, to me, is not great, and does not leave a lasting impression.

So now, we‘re saying baby has to have his/her food cutup because the wild west of everyone gets API mindshare means you‘re never going to know hardly anything of what you are using.

Let me pause for a moment to note the vast tragedy of this situation. The main reason its cosmically tragic, AFAIC, is that that is perhaps the main thing that objects were supposed to do that Structured Programming (methods) could not: as functions get more complex, their signatures grow beyond the 7 +/- 2 horizon (how many concurrent concepts a human being can keep suspended), and the ability to achieve any kind of fluency vanishes.

I have made this argument before, but the real genius of the modern version of Objective C is that through Categories, and its newer notation (esp. literals), it‘s kind of saying ‘let the user negotiate the last mile of making things more usable. And there‘s a ton of wisdom in that, because heuristics can often be impacted by need! I don‘t want to carry a ton of baggage when for what I am doing, I only need a small fraction of that.

Another possible solution to this is my favorite obsessive pattern: Builder. Bloch‘s Static Builder pattern largely make complex construction much more fluid and easier to navigate. Now, Builder is also PERFECT for code completion because the chaining this reference allows you to just keep going down and hitting . and getting another method to pick. One possible solution in ST would be to just program in a builder user plugin, that would read in the classes, grab the builders and parse them then suggest the methods. Or, it might make sense to just have a window that is open in a kind of sidebar configuration and as you start to go into the process of constructing or calling something, it would appear in that window, or its documentation, or maybe both.

Cocoa is one of the oldest and most mature frameworks, and by and large, code completion does not really make that much difference when using it. Partially because the methods are easy to remember, like ViewDidLoad or ViewWillAppear. But also, because you use them so many times, that you learn it and then don‘t really need much help with it.

Clearly, any kind of Lean consciousness about these matters has to see that the best of situations is but a tradeoff at this point: the programmer spent a few less seconds looking for a method call, but then, as tests were run and rerun in IDEs that are ludicrously slow, those savings were/will be bled back into the pool 100x over. People used to joke that C++ was the wrapper language. Wrappers are not bad things if they maintain fluency, especially on joints that are going to see a lot of traffic in the course of a long project.

Code completion is to IDEs as Outlook is to the PC: a boat anchor, encouraging people to just stay in their cabin, even as the ship takes on water from countless other directions. Until a native, blazing IDE is available for web development, finding alternatives to inline code completion might be the best escape hatch.

Excellent Thread Discussing Completion Options for Sublime

Published at DZone with permission of Rob Williams, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Adam Kerz replied on Wed, 2013/09/25 - 1:10pm

 I use Emacs for almost all of my development work, largely Python/Django, but also some SQL, Batch files, Shell scripts, html, css, javascript etc... and the only code completion that I have working on any (and all) of these, is to complete from words already within the current file.

This means that I don't have to re-type long variable names with my sometimes clumsy fingers and is a real speed improvement to me. For the most part, if I need to use a function/method that I don't remember or know well, I will check the documentation anyway to make sure I understand how it works and that there aren't any unexpected side effects. My Emacs config isn't setup to support lookup of documentation automatically, but I should do that as it would be much more important for me than better code completion.

I agree that part of this is due to the relative simplicity of the packages that I'm using, compared to some of the Java libs, at least. But not because they don't do complicated things, they do, they just have way better APIs (mostly). When I do Java, I don't use Emacs as I want autocomplete and pop up doco right there - of course, the reason for this want is also the reason that I do as little Java work as possible these days...

Adam

PS. On the note of incremental compilation, Django web apps have a simple runserver function for development that runs a http server its self, monitors all files for changes and reloads its self whenever one changes. This of course happens in under a second as Python is not Java and the same approach wouldn't work for Java. Means I can make a code change and see the result in my browser in seconds!

Rob Williams replied on Fri, 2013/09/27 - 8:57am in response to: Adam Kerz

Hi Adam:

Interesting. I love to hear stories like this.

It's certainly high time for a new generation of metrics studies: we have landed in a warped world where perception about productivity and reality are far apart.

I've just started fiddling with Python. Planning to move my blog to Pelican. As to the Django part, I will have to try that. I have been using Play, which boasts the same change/reload cycle. Nice, but then, running a unit test takes so long I forget what I'm testing.. Need speed on both fronts.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.