Shelter-in-Place Journal, Day 341

The biggest excitement today was cleaning up some of the code I’m passing along for Toastmasters. I have to wonder what, if anything, I was thinking in one place – the original code looked like this:

foo = ‘  this  that the   other thing’.split() 

The string was actually about 18 words long, with lots of extra spaces. It extended way past the right side of the screen, so the .split() was invisible. And I couldn’t figure out how foo became an array instead of a string for a couple of minutes until I realized what I’d done: written code that was not only inefficient but also hard to understand (I’m sure I cut-and-pasted the string in from somewhere – at least I hope I did).

I got the value of foo and put it into the statement, like so:

foo = [‘this’, ‘that’, ‘the’, ‘other’, ‘thing’] 

I had to break it into three lines to make sure each piece was visible, but that was easy enough – and now the code is obvious and faster.

Sometimes I wonder….