Wednesday, June 24, 2009

Smartest Guy in Class

He deserves a little publicity, for displaying his superior cognitive abilities, twice in two weeks!

First time: c. Last Week

The lesson was about differentiating two methods used to display output, namely println and print. The former includes a newline character at the end of the output so subsequent output would appear on the next line, while the latter doesn't. To demonstrate, an example with 4 statements using print method (each displaying a single word) were used to print a single line of text, consisting the 4 words. Another 2 statements using println were then used to show subsequent output texts in separate lines.

He asked - with regards to the first 4 statements using print - why should he use 4 statements to output a single line of text, when he can very well use just a single statement?

For the benefit of those not familiar with programming, here's an analogy to illustrate:

The Lesson: I am going to show you how to use this knife. To cut a fruit, say an apple, I hold the knife like this, and I cut like this, like this, like that, and there - I have slices of apples to eat!

The Question: Why can't I just take the whole apple and bite into it?

Second time: c. This Week

The lesson was about the dangers of integer division resulting in zero. For an easy example, say one has 2 floating-point variables, x and y. The value of y, is a tenth multipled by x. If the statement is written as y = (1/10)*x, the right-hand side expression will always be zero, because integer division of 1 by 10 always results in zero.

He asked - why can't he just divide x by 10 directly?

Again, for the benefit of those not familiar with programming, here's the analogy:

The Lesson: Here's an important precaution when using the juicer. It is important to cut the fruit, say an orange, into small chunks before putting them in. If the pieces are too big, the juicer can't juice them properly.

The Question: Can't I just squeeze the orange juice out with my hands?

Why, yes you can! Bravo, kid.

No comments: