Session 6
Growing a Java Program in Small Steps
CS 2530
Intermediate Computing
See Spot Run
Eugene does a daring bit of live programming, following
this script
roughly.
Students ask questions, become enlightened.
NOTE: I'll pull the script out into lecture notes with more
and better formatting as time permits.
Notice the style of programming: I took small steps. At each
point, I had a working program for a subset of the
requirements. In addition to always having a working program,
this way of growing a program has several benefits, including:
- Small steps means more chances for success. Many small
successes is a great way to build my confidence.
- Trying to solve too many big problems at once is hard when
I don't understand the whole solution yet. I can use what
I learn on each small step to implement the next step.
This, too, increases my confidence.
- Writing code to check my result at each step means that I
can be more confident that my new code works, and running
the old checks means that I can quickly find code that I
have broken when I make a change.
How you program is up to you. I suggest you consider using this
style whenever you are learning a new language or platform, or
when you face a difficult problem you've never solved before.
Many programmers, including me, program this way almost all the
time!
Programming Style
... Java programming has a style shared by the community of
Java programmers. Some conventions came from the creators of
Java, and others came as programmers wrote a lot of Java code
and wanted to share ideas and code.
... naming things:
- ... capitalization: primitive type versus built-in class
- ... capitalization: class versus variable
FieldPanel fieldPanel;
-
CamelCase
- ... instance variables before methods in class bodies
... format and white space (similar to the C world)
- indentation
- braces and blocks
- whitespace
... some of the programming style you see is my style...
... some for class and some for me.
Consistency is important. It can make unfamiliar style bearable.
Wrap Up
- Reading. Read a couple of short sections on basic
Java:
and a couple of short sections on writing Java programs:
Finally read this short section on
objects and object-oriented programming,
to prepare us to shift our focus from Java itself to OOP.
- Homework. Coming soon.
Eugene Wallingford .....
wallingf@cs.uni.edu .....
September 7, 2012