Sunday 31 August 2014

Efficient XQuery development (using IntelliJ)

Intro

tl;dr: We needed a modern IDE with high productivity features.

When I first started working on a project which used XQuery I didn't know the language at all. Just like the rest of the team. Step by step, by reading more about it, finding solutions to our problems on stackoverflow and generally using it, we started getting to know it. Most of the codebase in the project was Java. It seemed natural to use a good IDE for Java. Most senior people in the project had really positive experience with IntelliJ IDEA and they shared their knowledge and infectious enthusiasm with the rest of the team and taught us how to use it efficiently.
Still there was that part of the codebase that was written in XQuery. We tried out existing IDEs (Eclipse with XQDT, Oxygen) that did support the implementation that we were using (Saxon) and decided that they were not giving us the required support.
We expected something more than merely highlighting syntax and running the code (we did run and test it from our Java codebase). They didn't provide us with all the goodies that IntelliJ IDEA gave us out of the box for Java. Additionally switching between IDEs when developing each of the parts of our code didn't make much sense. And so we've decided to stick to IDEA. We've found one plugin but it looked like something abandoned in the middle of the work, was never released and was incompatible with the latest version of IDEA and the language. So we've found some nice highlighting settings for XQuery and lived happily ever after...

Not really. Our codebase started growing. Massively. The old way of navigation (find the function that you're using, find it's import, go to the file which it is in, find that function in the file, find another one because the one you've found was an overloaded one) didn't work that nice anymore. When you have over 300 files and you have to trace the whole path of execution it begs for a good navigation. Maintaining common code formatting and quality standards also becomes a big issue when your codebase is bigger. And anytime you  want to change the name of the function or variable (because it no longer reflects the behaviour) you have to find all the places it is used in and change them manually. Believe me, it can be a burden.

So why are you telling me about it?

All these problems led me to a refresher of formal grammars and reading about creating custom language plugins for IntelliJ platform. After some fiddling, checking how other plugins (especially Erlang) are written and finding time to put it all together IntelliJ XQuery Support plugin was born.

I'm sure that as a person already familiar with an IDE/editor that allows you to author XQuery code you probably want to know answers to a couple of questions before spending your time trying out JustAnotherXQueryIDE.
Let me answer these questions.

Why do I need another IDE?

These days almost every implementation of XQuery comes with it's own IDE/editor. Most of them give you syntax highlighting. Some of them support error highlighting/syntax validation. If you are lucky it even provides some means to deploy and run your code (or even debug). The question is then 'do I need anything else'?
In my opinion, yes! To develop code efficiently, you do need a lot more than that!

What's in it for me?

Today development is not simply a typing exercise. Projects usually have a huge amount of files which are all connected via imports and usually use some external libraries. To avoid huge decline in development productivity your IDE has to help you overcome this flood of text. It has to become smart. It has to help you get the most common and cumbersome tasks done as quickly as it is possible. Development is mostly reading, navigating and refactoring. And of course creating new code (with as little typing as possible). To do it effectively you have to have the right tool and know how to use it.
IntelliJ IDEA and products in the IntelliJ family are all designed to make developer's life easier. Development should be a pleasure. So what is so special about it? You can check some of the features of IntelliJ IDEA here.
I'm not going to list the features that you can find in all of these products. I'm going to focus on what IntelliJ XQuery Support plugin has currently to offer:
  • Syntax highlighting (with configurable colour schemes)
  • Invalid syntax highlighting
  • File structure view (outline)
  • Run your code
  • Code completion (syntax, variable names, function names from imported user files/available built-in functions)
  • Go to declaration (of variable/function; also from imported files and declared namespaces)
  • Usage search (show all usages of given variable/function)
  • Show help (for user code based on xqDoc, for built-in code based on documentation)
  • Show declaration
  • Show parameters (when filling in parameters of a function)
  • Rename refactoring (automatically renames all the references of given function/variable)
  • Safe delete refactoring
  • Configurable code formatting
  • Optimizing imports (removing unused ones)
  • Highlighting unused imports
  • Highlighting duplicate function declarations
  • Highlighting unused variables
  • Highlighting references to unresolved variables
  • Folding of functions, namespace declarations and imports (avoid unnecessary noise)
  • File navigation (easily jump between declarations)
  • Comment code
  • Code inspections
  • Code templates
As you can see the list is quite extensive and it's constantly growing. All of these additional (yellow) features are not common in the existing editors/IDEs. To know what you're missing you simply have to give it a try and you'll see that it was worth it.

Summary

I would say that there definitely is a need for another XQuery editor that is not tied to any specific implementation and has a potential to boost productivity of developer.
In next few posts I'll present what are the main features of the IntelliJ XQuery plugin and how to use these features to get your work done much faster.

1 comment:

  1. I read your article, very informative and userinformatic info are mentioned. For Prepaid Card Provider Company in UK also a Best Virtual Card Solution Provider Company in UK. Keepit up bro to share more article like that. Thanks for sharing this

    ReplyDelete