Interesting opinions about coding in academia presented here.
My opinion on coding is that code should read like prose, but instead of verses (~code paragraphs) one should use function calls. Kent Beck's books implementation patterns and test-driven programming are good reads (e.g. his thoughts about symmetry in code). Hm, perhaps it could be a thought to learn test-driven programming before object-orientation?
Have you ever thought about that precise naming of methods (or comments for code paragraphs) increases in difficulty with number of lines (i.e. harder to name something that does a lot of stuff)?
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Wednesday, February 20, 2008
Friday, January 4, 2008
Dining Philosophers and Quarreling Kids
Concurrency in general and in particular making concurrent processes smoothly share resources are hard programming problems. The classic problem illustrating concurrency is the dining philosophers problem where the shared resources are forks. The problems the philosophers can get include resource starvation, deadlock and livelock. (Note: dining philosophers has a slight resemblence of the game of musical chairs)
The quarreling kids problem
A much less classic but way more realistic concurrency problem is the quarreling kids problem, i.e. when providing N resources (e.g. food or toys) to M kids (who might be either spoiled, tired or hungry) several situations can occur:
An obvious solution approach could be to let the kids select resources themselves, but that will typically make the kids that selects first happy and the rest less happy and start quarreling, and if the kids select resources at the same time that also typically leads to quarreling during selection process.
A second approach is to provide non-discrete resources that are of infinite divisible nature, but that has unfortunately practical lower boundaries.
A third approach is to provide personalized (heterogeneous) resources, so every kids gets what they anticipate, but this requires both detailed knowledge of each kids preference and is impractical due to either limited resource budget, limited resource availability or possibly other reasons (e.g. nutrition?).
So what might work?
A) Provide homogeneous resources (where N ≥ M and N mod M == 0) could work, this way the kids are likely to feel that they are fairly treated.
But what if there are fewer resources than kids (N < M)
B) Provide resources that supports and encourages communication and interaction, i.e. where sharing pays off (e.g. in a more or less continuous sport like soccer or a turn-based board game)
This sounds awfully politically correct, what is the point?
The point is that solving the quarreling kids problem most likely requires solutions that:
But what is the computational analogy for solution 2?
The quarreling kids problem
A much less classic but way more realistic concurrency problem is the quarreling kids problem, i.e. when providing N resources (e.g. food or toys) to M kids (who might be either spoiled, tired or hungry) several situations can occur:
- N < M
- Typical result: Quarreling kids since some kids doesn't get any resources
- N ≥ M and N mod M != 0
- Typical result: Quarreling kids since resources are unevenly distributed
- N &ge M and N mod M == 0
- Can go smoothly, but can lead to quarreling kids if:
- the resources differ, e.g. in type, size, shape or color
- the order/speed resources are distributed in
- the resources doesn't match the recipient's expectations (stereotypical: the girl doesn't get the pink colored and the boy doesn't get the blue colored)
An obvious solution approach could be to let the kids select resources themselves, but that will typically make the kids that selects first happy and the rest less happy and start quarreling, and if the kids select resources at the same time that also typically leads to quarreling during selection process.
A second approach is to provide non-discrete resources that are of infinite divisible nature, but that has unfortunately practical lower boundaries.
A third approach is to provide personalized (heterogeneous) resources, so every kids gets what they anticipate, but this requires both detailed knowledge of each kids preference and is impractical due to either limited resource budget, limited resource availability or possibly other reasons (e.g. nutrition?).
So what might work?
A) Provide homogeneous resources (where N ≥ M and N mod M == 0) could work, this way the kids are likely to feel that they are fairly treated.
But what if there are fewer resources than kids (N < M)
B) Provide resources that supports and encourages communication and interaction, i.e. where sharing pays off (e.g. in a more or less continuous sport like soccer or a turn-based board game)
This sounds awfully politically correct, what is the point?
The point is that solving the quarreling kids problem most likely requires solutions that:
- Avoids resource sharing by having dedicated resources to each kid (e.g. a pair of skates each), like in A above, or
- Provides resources that are being competed for under a set of communicated and agreed-upon cooperative rules as in soccer, or waited for under as set of cooperative rules in a turn-based board game, like in B above. (Without cooperation quarreling about resources will occur)
But what is the computational analogy for solution 2?
Friday, April 13, 2007
IDI Open - Coding Contest - Apr 14
Quote from the announcement:
"IDI Open is a contest for teams of programmers of all skill levels, from those who are taking their first course in programming, to mad skill code monkeys. Each team can consist of up to three people, using one computer to solve the given problems. The programming tasks in the contest is similar to those found in NCPC (NM i programmering) and TopCoder, but the simplest problems in the set will be easier. You will be asked to write programs that takes an input problem definition and calculates a solution. The programs may be in Java, C or C++. Usually, there are around 9 problems, some easy, some medium, and some hard"
Note: IDI is the Department of Computer and Information Science at Norwegian University of Science and Technology (NTNU) here in Trondheim
"IDI Open is a contest for teams of programmers of all skill levels, from those who are taking their first course in programming, to mad skill code monkeys. Each team can consist of up to three people, using one computer to solve the given problems. The programming tasks in the contest is similar to those found in NCPC (NM i programmering) and TopCoder, but the simplest problems in the set will be easier. You will be asked to write programs that takes an input problem definition and calculates a solution. The programs may be in Java, C or C++. Usually, there are around 9 problems, some easy, some medium, and some hard"
Note: IDI is the Department of Computer and Information Science at Norwegian University of Science and Technology (NTNU) here in Trondheim
Subscribe to:
Posts (Atom)