"Plastic. They've learned."
Python 2.5 takes a big step towards getting useful: the "with" keyword. Observe, automatic file handle handling:
with open("x.txt") as f:
data = f.read()
do something with data
This is pretty much just like C#'s "using" keyword, where putting any file I/O inside a "using {}" block ensured that you wouldn't have to sweat running filehandle.close() when you were done. I like this feature because it helps to abstract the details of doing decent programming maintenance, i.e., carefully avoiding the dangers of haphazardly hacking and slashing your way through system resources like Serious Sam.
I like the power to be able to have my scripts intuitively work with my intentions and achieve that rarest of goals, "do what I mean, not what I say". With fewer things said, there's less work for me to insist I make the script do, and, by extension, less work for the script to do incorrectly because I insisted it do something poorly.
Just about every program I write in any language ends up looking the same: get some data, open a temp file in a specific directory, write the data to the temp file, close the temp file, rename the temp file to a finished name. In just about every language, these steps are easy to do if you don't care about all the mistakes the built-in functions make and hard to do if you give a damn about data integrity and Serious Sam. Anything I can find in a language that's going to make it easier to do what I mean without having to explicitly say it is a blessing.
No comments:
Post a Comment