Transcript Who am I?

Opening comments
Annoucements
Office Hours: MGH 450, 2:00-3:00pm
Course webpage almost up!
http://www.cs.washington.edu/education/courses/cse143/CurrentQtr/AC/
Section swaps
• Make sure you get e-mail from me today on the section list!
• If you want to move out (or in) get it settled this week!
Newsgroup
• READ IT!
Basic Style Guidelines
Tip 1: Read the style guide and memorize it.
Tip 2: Stay consistent. If you do myVar, there should not be an
other_var. If you do if(cond) {, then there should not be
if(cond)
{
Tip 3: Use descriptive variable names. An ‘f’ is not descriptive
Tip 4: Don’t comment things in that are obvious:
cin >> f; // loads a value into f.  bad. Code clutter.
Tip 5: If you can’t remove all your comments and still understand
without much work, you probably screwed up. Count on your
variable names and function names to convey the bulk of the
information.
Tip 6: Quote from Amer: “If it isn't aesthetically pleasing, it's
probably wrong.”
Tip 7: If it doesn’t make sense to you, don’t do it.
Tip 8: Argue with me or listen to me. Don’t just ignore me.
Tip 9: Style is a religious issue. However, some religions are just
wrong.
Tip 10: The text book does not show good style. Follow it and die.
Homework 0 oddities
Bad
Good
int fToC( double );
int fToC( double fahrenheitTemp );
while( cond ) {
...
};
while( cond ) {
...
}
void main(void) {
double main(void) {
int main(void) {
double returnValue = x+y;
return returnValue;
int i=1;
while( i == 1 ) {
return x+y;
for(;;) {
while(true) {
while(1) {
Grouping of Related Items - 1
• Related lines of code in a function should be group together by
surrounding them with extra newlines and optionally comments.
int printHello() {
string name;
/* Prompt user for name */
cout << “Hello! Can I please have your name?”;
cin >> name;
/* Print out reply */
cout << “Hi! You enetered “ << name “ as your name”
<< endl;
return 0;
}
Grouping of Related Items - 2
• Related sets of functions and data structures (functions and data
structures that have high cohesion) should be groups in a module.
promptUser.h – Good
int promptInteger(string message);
double promptDouble(string message);
string promptString(string message);
promptUser.h – Not Good
int promptInteger(string message);
double promptDouble(string message);
string promptString(string message);
double fToH( double fahrenheitTemp );
ADTs and sensible data manipulation
ADT – Abstract Data Type
An Abstract Data Type (from my understanding at least) is what you call a
method of organizing data and the operations that you can use to ‘mutate,’
‘access,’ and ‘interpret’ the data.
Sensible Data manipulation
An Abstract Data Type is just data – an abstract description of a type. To
implement one in a language, often times the best way to do it is to have a
grouping of relevant data and a slew of functions that act on it. To make
things even cleaner, it is often times the case that you would want make it so
that you can only look at and manipulate the data through these functions.
Another idea that is not as related to ADTs, but can be helpful in their
implementation is that of functional programming. It is conceivable that you
could write fToC like this:
void fToC( double &temp )
where the convereted value would be placed back in the paramter.
However, it will often be cleaner to write it like
double fToC( double temp )
where the result is given back without affecting the parameter. Stick to this
and you will make your life simpler.