Today's Programming: Ruby and Python
By EricMesa
- 3 minutes read - 527 wordsI don’t know how long I intend to keep doing this, but I decided I wanted to document my programming as I went along. So yesterday I worked on Scratch and here’s today’s entry.
Ruby
A while ago I got a bunch of kids’ programming books in a Humble Bundle. I tried showing Ruby to my oldest, but I did it one year too soon (she wasn’t yet reading as well as she is today and couldn’t type as well as she can today) so for now she’s not into programming. But I was curious to see how it was presented since the book uses a story to present it (quite different from the Python book in the same bundle). Went through chapter 2 today and, so far, it seems that Ruby is pretty readable like Python is. That said, I’m not sure puts makes more sense than print, but maybe if I delve into the history of Ruby, I’ll understand why it’s puts? The author of this book uses snake case for variable names. I wonder if that’s because it’s the Ruby standard to use snake case instead of camel case or just to make it easier for the kids following along. I *did* really like the built in next and pred methods on numbers. Definitely more readable than a var++ or var = var + 1. Or rather, if you don’t have decades of programming experience (as I do), I think it’s just a faster bit of cognition to see var.next and understand it vs the older ways of doing the same thing.
Python
Snowflakes with Sam
Snowflake wreath
Yesterday I did a bit of Scratch art with Stella. Today Samuel and I used Python’s implementation of the Turtle module (as in the Turtle programming language that was the Scratch of its day - you can get raw Turtle on Linux with the KTurtle program) to draw snowflakes, again following a Raspberry Pi tutorial. Above was the final result of what we came up with. The tutorial challenge at the end was to make snowflakes all over the place in different sizes. Instead, I decided we should make a wreath since snowflakes make me think of Christmas (even though it almost never snows here on Christmas). You can see our code on Github. Here’s a video of what it looked like while it was drawing:
The “turtle” drawing the snowflakes
Amortization Program
Recently, because of all the new, low interest rates, I had to calculate how much we have left on the mortgage vs what we’d save after a refi (plus costs). So I loaded up the program to do the calculations. Recently (I think on Python Bytes) I heard about the Decimal module which does more accurate math than the floating points that Python normally uses. It often isn’t a big deal, but over a series of calculations it can add up. It made a sub-$100 difference on the sum of how much interest I would pay over the life of the loan, but better to be more accurate than less accurate. I made a 4.1 release of my Amortization program as a result.