Discovery by Tinkering
In my early days of programming, I worked on projects which required user input. I always wondered, “What if I enter a letter instead of a number?”
Well, I tried it…and it looked something like this
I always wondered how cash registers, health insurance websites, and other advanced programs were able to shirk this problem. Earlier this year, I worked on a project for my Java course where users entered birthdays and the program returned information about the season when they were born. As I clicked away at my keyboard, this old question rang through my head. “What if someone enters an invalid character instead of numbers for their birthday?”
Though my assignment was a simple one, this question was certainly not. I paused to think about this.
I ended up breaking night to figure this out and, after some hours of talking to myself, I found the solution! The input from the user is being entered in a MM/DD/YYYY format. This will be stored internally as a string. In Java, the String class has methods for returning characters from positions in a String literal.
By comparing each position in the String literal with a range of ASCII values, I was able to write code that would only run if values within a certain range were entered.
1 – 12 for the month, 1 – 31 for the day, and…well 1900 to 2100 for the year (just because)
One can learn much through experimentation. It opens your mind and gives you a different perspective to take while learning. It can also teach you a new technique. One time I accidentally hit Ctrl + Shift + Tab while in a Firefox window…not sure how. Since then, I’ve used this command to move one tab to the left (Ctrl + Tab moves to the right one tab). These commands can also be used to traverse tabs in the Sublime text editor, Google Chrome, and the Linux file browser.
By entering an invalid input in one of my projects, I received an error that made me suspect large scale software has ways of dealing with it and I wanted to learn how to emulate that in my own work. This is just one example of how tinkering can help one find patterns that will enable better understanding of a topic.
Often times we focus on reading a textbook cover to cover or hanging on every second of a tutorial. While these are certainly great learning resources, it’s important to take time and get a feel for a language, technology, or whatever you desire to learn more about.
Peaceful in action, manic in thoughts.
Coding Fanatic
PS: Check out my new podcast, Ambitious Computer Man, where I tackle some confusing features of computers and software. Send any questions to rick@codingfanatic.com and I’ll answer them on the show!
Follow me on Twitter @rclarkecf for more content daily!