Scripting News, the weblog started in 1997 that bootstrapped the blogging revolution...
Programming philosophy -- factoring
As you're writing a complex piece of software, you have the opportunity to break chunks of code out into separate procedures or functions, or write the code inline. I think programmers tend to do too much inline, and should modularize or factor more.
A few reasons why factoring is good.
Giving a block of code a name and a parameter list is like having a comment that's part of the program structure. It's a chance to say clearly to a future reader what the code they're reading does. It's a way to communicate.
You get a new slate for local variables. A fresh mental stack frame. You can give things shorter names because they'll only be used in a small scope. No guesswork when reading the code about where these values might be used, and less temptation on the part of future maintainers to reuse something that might not be reusable for all time. A chance to avoid future code fragility, breakage. (Think of it as the programming equivalent of defensive driving.)
You get to use a return statement to get out of the code. That makes error checking simpler, easier to follow in the code. Simplifies the code.
Even if there are just one or two lines in the function today, you never know.
Managing complexity is what building maintainable code bases is about. The easier it is to understand the building blocks, the higher you can build your castle.
If you do it well, the calling code can be simpler, it's functionality totally clear. It can almost read like haiku. Real-time code, in order to work, often has to attain that level of simplicity.
And if the problem comes up again, you can just call the function. That makes your code smaller and easier to work on. It's also like solving a puzzle. Satisfying.
But strike a balance. Too much factoring can obscure functionality.
Make sure that the layer you add makes sense in terms of what the software actually does. Introducing an unnecessary layer of abstraction is something a new contributor has to learn, and even you may have to relearn it at some point, as your code base gets huge, you tend to forget how you put it together.
It's been a really awful summer for movies, at least the ones I've gotten to see -- they've all been terrible or just boring. So I decided to change my strategy and avoid the blockbusters and science fiction movies that I had been going to, and go to movies that the critics liked. So I went to see Blue Jasmine over the weekend and The Butler yesterday.
About Blue Jasmine, I keep hoping someday Woody Allen will make another of his classics like Annie Hall, Manhattan, Hannah and Her Sisters. Or even one of the total comedic farces like Bananas or Take The Money And Run. Zelig!
Blue Jasmine didn't do it for me. I didn't care about the characters. Never got into the plot (not much happened). There wasn't much for the mind. A few nice visuals, but they were both cities I knew well (NY and SF). Eh.
The Butler sounded like just my kind of movie. Politics! Great ideas. History. The White House. Race. Forest Whitaker, Oprah Winfrey, Cuba Gooding, and cameos from Robin Williams, Vanessa Redgrave and more. And the NYT loved it. But it was awful. A stitched-together set of scenes. None of the characters got us to care. The laughs when they came were forced. I don't want to spoil what little plot there is, but this one didn't hold my attention either. I was sitting in the theater working out programming problems like the guy in the funny graphic.
It was a little like Forrest Gump (hey another Forest) but that was good entertainment. Maybe it's time finally to stop treating that period of history as magical. Maybe if there had never been a flashback to the sixties before, then perhaps this might have been an interesting movie. But this idea has been done so many times, and done better. The Butler is proof that it's enough already, at least until someone has a fresh approach.
There was one nice thing, they cast Jane Fonda as Nancy Reagan. Anyone who loved Reagan is very likely to hate that idea. But they did make Reagan look pretty good, compared to Nixon who was a drunken asshole in the movie, so there's that.
I'm still waiting for the Great Movie of 2013. Even a good one would be nice.