Software Development (CSC 321 2016F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Outlines]
Reference: [Slack] [Ruby@CodeCademy]
Related Courses: [Rails Tutorial] [CSC 321 2016S @ EdX] [CSC 321 2015S (Davis)] [CSC 321 2016S (Rebelsky)] [CSC 322 2016F (Rebelsky)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
See http://www.cs.grinnell.edu/~rebelsky/s2d@g/
x, DON'T MAKE IT GLOBAL!What unnecessary repetition appears in the following code?
for (int i = 0; i < length(lst); i++)
{
printf(lst.get(i));
} // for
for (int i = 0; i < length(lst); i++)
{
printf(i + " of " + length(lst) + ": " + lst.get(i));
} // for
int len = length(lst);
for (int i = 0; i < len; i++)
{
printf(i + " of " + len + ": " + lst.get(i));
} // for
Ways to avoid unnecessary repetition.
Use a variable to name the result of a repeated function call.
int min(int[] a, int n) { int result = a[0]; for (int i = 1; i <= n; i++) { if (a[i] < result) result = a[i]; } // for return result; } // min
int max(int[] a, int n) { int result = a[0]; for (int i = 1; i <= n; i++) { if (a[i] > result) result = a[i]; } // for return result; } // max
What was bad about the code above?
How do we write it only once? Take a comparison function as a parameter. enum compare = { LARGER, SMALLER } int ultimate(int[] a, int n, compare comp) { int result = a[0]; for (int i = 1; i < n; i++) { switch (compare) { case LARGER: if (a[i] > result) result = a[i]; break; case SMALLER: if (a[i] < result) result = a[i]; break; default: break; } // for return result; } // ultimate int max(int[] a, int n) { return ultimate(a, n, LARGER); } int min(int[] a, int n) { return ultimate(a, n, SMALLER); }
Issue: Is it better to repeat the for loop.
int ultimate(int[] a, int n, comparator comp) { int result = a[0]; for (int i = 1; i <= n; i++) { if (comp(result, a[i]) < 0) result = a[i]; } // for return result; } // min
Ruby: Use yield in clever ways.
Note: Make is designed to help you write DRY instructions.
Similar classes.
An idea I found confusing is the cookies. In my understanding, cookies allow the server to identify returning users. What else am I missing?
How HTTP can be stateless but also use cookies?
I am having trouble understanding the relationship between marshalling and serialization. Serialization is when you turn an object into bits for storage. How does marshalling differ?
What's the relationship between HTTP and URIs?
How do websites scale? It seems like they share the load of computations over many virtual computers, but I'm not sure how all the information is stored and computed cohesively.
What's the relationship between the three-tier architecture and MVC? They seem very similar.