Skip to main content

2.3) Useful Coding Tips


Mutli-line Statements

It is not strictly necessary in IDL to split a line of code over multiple lines of text, if it is too long. Sometimes we do it as it makes the code easier to read. This is achieved by putting a "$" at the end of a line. This tells IDL that the next line is a continuation of the current line.

total = x + $
        y + $
        z

Is the same as writing.

total = x + y + z

Quotations in IDL

These are mainly used to denote strings. You can use either ' or " as long as you are consistent.

text = 'This is a string'
text = "This is also a string"

IDL will match pairs of the same quotation type, with the outer quotes denoting the limits of the string. This can be very helpful if we want to print a string containing quotes. Type the following on the IDL command line.

print, "It's useful to print strings with quotes in"
print, 'This is a "string"'

Comments in IDL

It is always useful to comment your code, to document what you have done. Comment lines/statements start with a semi-colon ";", these lines/statements are ignored by IDL.

; This is a comment to say the next line adds two numbers together
x = 2 + 4