Code Learns
RegEx
Today I learned how to read and write regex. They are kind of a pain in the butt, but it seems like they can be very useful in the right situations. The trick, then is to recognize those situations, rather than wasting my/our time trying to find a complicated regex when a different approach would provide a simpler, cleaner, or even just faster solution.
One fantastic new infobyte that came with regex is the ability to find and replace in various ways. for example:
name = "First Last"
name.gsub(/([a-zA-Z]+).([a-zA-Z]+)/, '\1 M. \2')
=> "Last M. First"
Broken apart: First, gsub stands for global substitute. It basically finds the first input argument, and subs the second argument. Another, less complicated way of seeing this is here:
"hello world".gsub("world", 'how r u')
=> "hello how r u"
So, in our first example, the argument that we want to find is actually a RegEx, or regular expression. Once we tranlate our regex, we might be able to see a couple things going on here.
/[a-zA-Z]/
finds any single upper or lower case letter. Adding a plus sign to the end of that (/[a-zA-Z]+/
) finds one or more of any of the characters contained in the brackets. Effectively, what this does is find individual words.
After that, note the parens. These mark what’s called a “capture group”, and here’s what I think is the second coolest part: the capture groups are things you can tell to stick around, and stay the same when using gsub to replace parts of a string. If there’s more than one section of a string you want to replace, you tell your replacement argument so by numbering those sections, and coupling the numbers with escape characters: '\1 M. \2'
.
In our example, we are keeping everything on either side of the space, and replacing the space with “ M. “.
TDD
We also had a lecture on Test Driven Development, which was simultaneously inspiring and humbling for me. The instructor used many very simple steps (and, inevitably, a very thorough knowledge of and lots of experience with coding), to solve an exercise that would have taken my pair and I a few hours to solve as eloquently (if we had…) when we worked on it yesterday. It was late enough and we were fried enough that we just hacked out the simplest solution we could think of.
My take-away from that was that small, well considered steps can be very effective. We have the resources available to us now to be able to draw from when we run into knowledge gaps, which is a really fantastic way to learn.
Human Learns
I want to impress these guys! No dice yet. Not from my perspective, anyway.
I hear that’s common.
Today, we talked about “imposter syndrome”, as well as sexism and opression.
I imagine that the instructors, and other students, look at our code, and do the same thing I have when looking at what my peers have written so far: some bits are interesting, cool, impressive, and others I would have done differently.
That’s one of the cool things about this: there are so many ways to succeed, and enough to learn that most of the time, it doesn’t matter how you get to the solution, as long as you learn something from the process.
I had a hard time today with my pair. We got along just fine, but I got frustrated a couple times that we both had such different ways of approaching the problem. My way seemed better to me. Well, of course my way seemed better to me! Listening to my pair can help me understand different approaches to solutions, which can help me to stay flexible in my approach to later problems.
Goals
That said, one of my goals for tomorrow is to do it better.
-
I want to specifically communicate better with my pair; I feel like today I ended up not being able to express my thoughts very well initially. It got better as the day progressed, but I relied a bit more than I would have preferred on typing out the code, running it, and saying “see?”. If I can define my idea in english from the getgo, we can save a lot of time, and have even more fun.
-
I also want to continue to challenge myself to ask questions of the instructors. Today one of them approached me and my pair to see how things were going, and ended up helping us get through a really tough spot even more quickly.
-
Time boxing today helped so much! If you’ve never tried it, here’s how it works: You take a look at all the tasts you have in any given block (day, assignment, etc.) and estimate the time each piece will take you to complete. Stick to those time blocks, and when the time is elapsed, you move on. Come back to it later if you need to, but move on when your time is out.
-
I have got to remember to eat that damned grapefruit. I keep forgetting I have it, and not wanting to peel it, etc…