Code Style and IDEs
So we've now covered most of the important core language features. Even with the most basic elements (primitive variables, operators, loops and branching commands) you could construct a wild variety of scientific programs, from "Hello Lab Colleagues" to landing someone on the moon.
This is, then, a good time to take a breather and to focus on making sure we're approaching code in the right way. Getting into good practice now will make staying on top of coding much much easier in the future. So, in these short slides we're going to look at coding style. We'll then look at some software to help you code.
The Java code conventions are online at: Code Conventions for the Java Programming Language.
Interview with poet and coder, Richard Gabriel.
For some good books that will help with making your code clear, efficient, and elegant, see our Recommended texts list.
Look at the following code:
What's going on is ____________________________.
- beyond me, my friend
- that we're printing the default x value of a Point object, but without giving the object a name
- that we're using the Point class in some way to get an x value without making an object
- something to do with vectors
Correct! We don't always have to assign a label to an object, if we're just going to use it once, though this is quite rare. Here we make
a new Point object with
new Point(), but rather than attaching it to a label, we just use it directly to get its x value. The code
is the equivalent of:
Point pt1 = new Point();
but without the labelling. This is one rare case where we have a variable without having a lowercase name for it.
If you're feeling very geeky, you could use one of the very old skool IDEs, many of which have a solid fanbase despite all the odds. These include: vi ("VI", or "v-eye"), and EMACS ("e-macs"). Ports are available for all major operating systems, should you be crazy enough to want to use one.
________________________________________ is a common feature of most IDEs.
The colouring of keywords and other types of code
The ability to distribute code directly to users when rebuilt
A button that causes bluebirds and squirrels to clean up your office
The option to explore hardware connected to your network for use in your code
A big red button labelled "Don't Push"
Correct! Building a system to distribute updates to users is possible, but it isn't a default IDE behaviour. It wouldn't be very wise anyhow; one wrong button push could distribute broken code to everyone (not that that's never happened!). The option to explore local hardware is also something not commonly built into IDEs, though it could kinda be done in, for example, Microsoft's IDE for their languages: Visual Studio. Bluebirds and squirrels are only controlled by the singing of Disney Princesses. If you happen to be one, you could probably build a plugin for Netbeans or Eclipse that plays an appropriate MPEG file, but this functionality isn't built into either IDE by default. Sadly.