Code Style and IDEs
[Part 7]


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.


Powerpoint and audio

Further info:

The Java code conventions are online at: Code Conventions for the Java Programming Language.

Interview with poet and coder, Richard Gabriel.

A series on writing good code by Janice Heiss: Part 1; Part 2; Part 3.

For some good books that will help with making your code clear, efficient, and elegant, see our Recommended texts list.


Quiz:

Look at the following code:

   System.out.println((new Point()).x);

What's going on is ____________________________.

  1. beyond me, my friend
  2. that we're printing the default x value of a Point object, but without giving the object a name
  3. that we're using the Point class in some way to get an x value without making an object
  4. 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();
   System.out.println(pt1.x);

but without the labelling. This is one rare case where we have a variable without having a lowercase name for it.



Further info:

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.


Quiz:

________________________________________ is a common feature of most IDEs.

 

  1. The colouring of keywords and other types of code
  2. The ability to distribute code directly to users when rebuilt
  3. A button that causes bluebirds and squirrels to clean up your office
  4. The option to explore hardware connected to your network for use in your code
  5. 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.


[Brief intro practical on IDEs]
[Homepage]