Chronology Current Month Current Thread Current Date
[Year List] [Month List (current year)] [Date Index] [Thread Index] [Thread Prev] [Thread Next] [Date Prev] [Date Next]

Re: [Phys-l] modern programming



On Jul 5, 2011, at 12:51 AM, John Denker wrote:

I wrote up the answer here:
http://www.av8n.com/computer/htm/modern-programming.htm

nice example, although I have to admit that the same example is much clearer in python. :)

On a different note, I always found the analogy with real-world objects to be less than intuitive...it just wasn't clear what was being talked about, and I always had a hard time seeing the real advantages. Then I saw what was, in my mind, the simplest example that showed a clear advantage. It is a class, from the Python Cookbook, which does temperature conversions (http://code.activestate.com/recipes/286226-temperature-class/). You can do:

t=Temperature(f=32)
print t.k
273.15
print t.c
0.0

t.c=21
print t.f
69.8
print t.k
294.15

internally, it converts everything to kelvin, and stores it there. then, for any conversion, it converts from kelvin to the others (the recipe also include Rankine units). The advantage is that, in this implementation, you only have to know how to convert to and from Kelvin from whatever units you're using. In a procedural program (like C), you'd have to have all of the different combinations (c to f, c to r, r to f, etc...) which is clearly less efficient.


bb



--
Brian Blais
bblais@bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/