Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, October 18, 2010

Chasing down particles

I'm up late writing MATLAB code to analyze a whole load of particle tracking data. It's not exactly a fun process, but I can feel myself getting better at MATLAB. It's like the coding equivalent of eating all my asparagus. There are some great tricks you can do to slice and dice arrays with fancy indexing. But, ugh, the syntax for optional arguments makes me wince (and avoid using optional arguments, unfortunately).

But I'm still not in the habit of putting semicolons after everything. Despite studying Java and Scheme in high school, I never got very good with them or did anything practical. Right now, I'd say my native tongue is Python. Maybe if I get into automation, one of these days I'll clamber up on the big-programmer potty learn C/C++.

Sunday, August 10, 2008

Some programming resource reviews

Since I've been teaching myself, and especially since I've been flirting with several different sources rather than settling into a steady relationship with any particular one, I thought I'd share my impressions.

So you know where I'm coming from: I took AP Computer Science AB (Java) in junior year of high school. Then in senior year we had a semi-experimental Scheme class based on the classic SICP (see below), but nowhere near as hardcore. Because Java and Scheme are so different, and because I forgot a lot of Java over the intervening summer, this amounted to me learning to program two separate times with very little cross-contamination.

After that, I didn't write so much as a line of code for my whole first year at MIT. (Yeah, I know -- how could I?!?, etc.) But somehow a lot of vague programming ideas seem to have stuck in my brain, making it much easier to (1) learn a new language, and (2) re-learn programming in general. So I'm somewhere between 'rank beginner' and 'person who wants to pick up a second language after their first CS class'. This will affect my assessment of resources.

>> Learning Python, Mark Lutz & David Ascher

...Comprehensive, I suppose. It's the O'Reilly book, which gives it lots of reputation points. It goes into a lot of detail about basically everything (I'm reading it online, but the dead-tree edition is quite hefty). Tables of built-in integer and string functions, that sort of thing. Even -- get this -- more than one chapter on getting Python to run on your system, choice of IDE, and how to run programs you write from a variety of situations. This makes it surprisingly useful as a reference, for a book with the word "Learning" in its title.

The thing that bothers me about this book is that it can't seem to decide where it's aiming. It's definitely a programming book, not a computer science book; but it's in between "dense comprehensive tutorial/reference for people who already know what they're doing" and "learn programming from scratch using Python". For example, it explains the ideas of iteration and recursion, gives very basic examples, and discusses the general sort of situation in which you might want to use them -- and then a minute later it hits you with a lot of jargon and dense stuff. Curious approach.

Perhaps some of the confusion is because the authors are trying to take a "quick survey first, then dig into the details" approach on each section, and their definition of "section" is too short, leading to a confusing rapid alternation between the high view and the details.

I'm only up to the section on classes and OOP so far, because I've started to run into stuff I never learned or have forgotten; so I can't comment on the GUI section or anything like that, but I'm sure everything else is quite comprehensive.

>> Structure and Interpretation of Computer Programs, Abelson & Sussman

Ahh, the classics. Especially the classics that are available online, for free, in full, under Creative Commons, and not in a really irritating interface!

This is a hardcore nerdy book. It doesn't teach you computer science, it ties you down and throws computer science at you thick and fast, but in a totally awesome, non-evil way. It's really not a programming book, either -- the authors go out of their way to teach you the absolute bare minimum of Scheme syntax to handle the concepts they're presenting. This is kind of irritating if your goal is to be able to do practical things quickly (ha). But if your goal is to achieve nirvana, you could do a lot worse than this book.

Read the footnotes. They are snarky, and competently so, unlike the lame attempts at humor you see in most textbooks.

>> Teach Yourself Scheme in Fixnum Days, Dorai Sitaram

This is a straight-up no-frills tutorial for people who already know how to program, more or less. Reading this after having taken a SICP class was pretty interesting: I kept going "Hey! That piece of syntax makes it really easy to do X thing we were always beating our heads over in class, because SICP HATES SYNTAX OR SOMETHING." Hooray for actually doing things with Scheme. I'd gotten the (not entirely wrong) impression that Scheme was good for nothing but theoretical interest and formalism with a dash of AI.

I'm not sure whether to recommend reading this along with SICP. On the one hand, I tried it and got really confused. Part of the charm of SICP's syntax starvation is that it actually helps you figure out how to do things; they simply refrain from teaching you the four other ways to do it. On the other hand, Scheme can actually do stuff that's not all abstract and theoretical and weird, and this teaches you how to do that.

>> [pdf] How To Think Like A Computer Scientist: Learning with Python, Downey, Elkner, and Myers.

This, I think, would be a good book for a (dedicated) beginner. It starts right at the beginning with the very fundamentals, and keeps a great balance between new concepts and new syntax. I haven't gotten very far at all in this book, mostly because I've spent so much time on the O'Reilly Learning Python book, but I like it very much so far.

Plus, how can you say no to a book that's written in LaTeX? Seriously, now.

>> Project Euler

Oddly enough, none of the above books have enough exercises in them. Teach Yourself Scheme has none at all. Learning Python only has a few, once every five chapters or so, and they're all about catching tiny nitpicks that trip you up. SICP has plenty but they're geared toward teaching CS principles, not coding practice. How To Think Like A Computer Scientist has good ones but not many of them. I googled around but the only thing I found that wasn't too advanced was FizzBuzz, which wasn't enough.

Enter Project Euler. It's a site full of math puzzles, varying in difficulty from "ludicrously easy" to "frackin' impossible", and set up such that you basically have to solve them by programming. Things like "find the ten-thousandth prime number", too big to be solved by hand. Excellent!

The site is obviously run by people who know what they're doing -- all the problems are very unambiguously stated, with examples, and the site keeps your score for you. Once you've solved a problem, you can look at the discussion thread where other people post their code and discuss alternative methods. The other people, by the way, are brilliant, and come up with all these elegant methods and neat optimizations for you to imitate.

Saturday, August 9, 2008

Look Mom, Tags! And a Coding Trance!

[Before I start, let me admit that I am still very much a programming n00b. Everything that excites me is probably old hat to the majority of the coding population.]

I like tags very much. They are a million times better than folders. 'nuff said.

I've been writing a tagging system. It's nothing special -- just something that pairs up items and tags, and can do some of the same kinds of lookup that the tagging systems on blogs can do. Have been wanting to do this for quite some time, so now I feel all accomplished :D

I haven't finished testing the thing yet, so there are probably a lot more mistakes hiding in there, but most of the ones I've caught so far have been pretty similar. I tend to confuse the actual tag object with the tag's name, and refer to one when I should refer to the other -- kinda like confusing the phrase "scientists are people too" with the tool that lets you do this. Same thing with confusing tagged items and the objects they contain. These are pretty easy to fix.

There are a couple more functions I want to write -- eg, I haven't got a thing that lets you organize the tags in order of frequency of usage (as they are in the sidebar). But I've got the majority of what I wanted. (And no, that doesn't include a GUI. This is strictly text-based, Python-command-line stuff.)

I guess I'm kind of excited because, back when I was thinking about teaching myself to program again, a tagging system seemed like kind of a big challenge -- one I could do relatively quickly, but a challenge nonetheless. And now I'm about 90% of the way there. It's astonishing how fast you can learn to program when you've already learned to program twice before! ^^

This is also the longest block of sitting-and-writing-code time that I've spent in quite a while. I seemed to fall into a sort of trance -- very focused, very losing-track-of-time. This is an interesting mindstate (not to mention a very productive one!), and I'd like to get into it more often. (It helped that some people over on the XKCD forum turned me on to the streaming lyricless music from Blue Mars, which bills itself as "music for space travelers". Despite the word "mars" in their title, I think they really mean "music for headspace travelers". I find it quite relaxing and focusing.)