Wednesday, June 8, 2011

Classes!

There are two things exciting me today, so I decided I'd write about both of them. First of all, to resolve yesterday's cliffhanger, yes, I was able to see the supernova. Not by eye, but I was able to capture an imager of it using the imaging telescope at the Vis (another volunteer there told me he'd spent the night before trying to see it visually with the largest telescope at the Vis and had no luck, so I didn't bother looking for it visually).

I haven't had time to reduce the image yet due to the other thing exciting me, but hopefully I can show you all pretty soon what it's like to see a single star putting out more energy than an entire galaxy 25 million light years away.

The other thing exciting me is that I suddenly learned how to use classes in Python, my favorite scripting language. Classes are basically user-defined objects, and a definite step up in the abstraction department. The reason I'm so excited about it is because of the way it happened.

Now, before Tuesday, I'd never used a class in Python, nor did I understand them. I'd read the documentation introducing them before two or three times, but couldn't really make heads or tails of it. Then, Tuesday, as Dr. Takamiya and I were trying to pin down an unrelated bug in my code, I became painfully aware just how convoluted my data was getting in my script. Lists were stacked in other lists, which were stacked in still more lists, and it was becoming a nightmare remembering what was what while executing the script.

Finally I took a little break to think, and the thought popped into my mind “I think I need to use a class for this”. Remember, I had zero prior experience with classes up to that point. However, since we weren't really getting anywhere the way we were going, I went home to do some quiet thinking and see if this idea would pan out.

And did it ever! I found and read the documentation on classes again, and it's as if everything had clicked into place in my mind. I understood everything perfectly clearly. I had to run off to go up to Mauna Kea soon afterwards, but I had the same experience today when I took it up again. It still feels somewhat surreal, as if someone just flipped a switch in my mind. I see it as another case of the fact that sometimes, at least for me, I need to figure out something on my own before I can effectively learn it. I essentially came up with the idea, “I need to be able to do this in Python”, and lo and behold, there exists a method to do this. I'd never appreciated it before because I hadn't really needed like I did recently, but when I finally did, it came practically like second nature. (If you're interested, classes are basically what I said before, user-defined objects. You can use them as containers to store arbitrary data, which is mostly what I was using them for, but they're much more versatile than that. Hard to explain in a few sentences. Let's just leave it that they're really useful and handy.)

1 comment:

  1. Now if I could only find a good CCD-control software written in Python I'd be set... As for your revelation: It's amazing how easy it is to find what you need when you actually know what you are looking for, no? When Einstein was trying to figure out how to formally express his ideas for general relativity, he was banging his head up against the wall for years, until a mathematician friend of his pointed out that what was looking for sounded a lot like the advancements in differential geometry made by the likes of Riemann. Sure enough, differential geometry fit the bill exactly!

    ReplyDelete

Think I said something interesting or insightful? Let me know what you thought! Or even just drop in and say "hi" once in a while - I always enjoy reading comments.