2019-Feb-12, Tuesday

千矢

2019-Feb-12, Tuesday 08:55
dorchadas: (Pile of Dice)
A few days ago I posted on Facebook about Yasuke (弥助), an African man brought to Japan by the Portuguese who became a retainer under Oda Nobunaga, and [instagram.com profile] thosesocks replied and asked if I had heard about the RPG Thousand Arrows (chiya, written as in the subject line), and I had not. I looked at the kickstarter page, and it looked interesting but I had some concerns, and on Saturday between Lunar New Year events we met for tea so I could hear more about it.

Tabletop RPG nerdery )
dorchadas: (Warcraft Face your Nightmares)
Yesterday, I had to maintain broken code!

So for background, months ago I completed a Random Quote Machine as a Free Code Camp project, but I'm reworking it as part of the revamped curriculum. As you can see if you click that link, it no longer works at all, and after a bit of exploration I discovered it's because the quote API I used is no longer serving data. "Alright," I said, "I'll find a new one."

That took some doing because I had to find an API served over HTTPS to avoid cross-domain requests, but eventually I found one that worked and then it kept displaying "undefined" for both quote text and author. Why? Why was this happening?

Well, it turns out that not every JSON object is formatted the same. Emoji embarrassed rub head I was using the object keys from the original API which didn't exist in the new API, so I went through the code and changed all the old keys to the new keys and it worked! Then I realized that was a bad solution, set two variables to the new author and text keys, and used those variables to display the data. Much more maintainable!

Of course, just now I realized what I should have done is split off the display code into a function invoked when the AJAX call is successful, so I'd only have to change the function call's parameters and the function would handle everything else itself. And indeed, I'm going to go do that next. This is why functional programming is a thing, so you're not search-replacing variable names and risking something getting screwed up (why isn't my code working at all? Oh, right. Let me just change "reponse" to "response"...).

At least this is a problem with a solution I figured out and implemented myself, rather than hours lost to not typing one }. I should treasure this feeling.