Saturday 6 December 2008

Start Draft Chunk16


Introduction
The Chunk 16 application draws a random picture to the screen about every second. It weighs in at a little over 100 lines and can be run as an applet, or an application, by simply clicking on the appropriate link. There is no need to struggle with applet permissions, digitally signing jar files or setting up a jnlp file for Java WebStart. As someone who uses Java on a regular basis, Processing is like a breath of fresh air and I wish I had discovered it sooner! In this chapter we will be looking at the basic construction of a Processing application and it should help clarify the basics of programming, so you are ready to tackle the special powers of Processing. We will just go through each topic and explain the basic syntax.

Comments
If you are anything like me you will want to dive in and get some coding done with as little fuss as possible. This may produce some good work but what happens months later after coding lots of other stuff and you have no recollection of this odd looking code? This is where comments come in.
Comments help explain what is happening in your code and should be used copiously. The five minutes it takes to write them now could save you hours in the future. I am one of the biggest culprits of writing uncommented code, so I know what I'm talking about!
There are three basic types of comments.
// spans one line so this is commented and will be ignored by processing
but this is not and will probably throw an error.
The oyher type
/*spans more than
one line and can contain anything you
like. Iy is very useful for testing if a statement in your code is really needed
and also for commenting out blocks of code you may use later but dont
need at the moment. */end of comment
I have used this on line 63 to comment out a line drawing block. I dont like what it does to the patterns but with a little editing it could maybe be improved. To enable the line drawing just remove the /* at the start and the */ at the end and run it, if you think you can improve it, go ahead, if you will maybe imptove it later then just make it into a comment again, otherwise just delete the block and maybe replace it with something else.
We will not be using the last type of comment as it is usually used to make HTML documentation for Java classes.
/**We have no classes here so we dont use it*/

2 comments:

  1. I don't fancy your chances of doing an idiomatically correct translation from 'if your anything like me' to the non regal we. However Darren has suggested that since there are so many of us we should write in the collective we.

    ReplyDelete
  2. Dont worry Martin,
    we are aware of the we constraint. This is just the first draft where I am just exploring what needs to be covered, I expect it to be well over the 2500 words and it will be cut down to a more concise rendering in the next phase.
    I cant see the comments topic warranting that many words in the final version...

    ReplyDelete