Tuesday, 5 May 2020

The Figure Eight Analogy

There are lessons in web development that one can glean from the simplest things, and today is one such example.

The Figure Eight Knot is as simple as they come. Primarily used by fishermen, it also has uses as a sailor's knot, mostly as a stopper. It's so simple that most people can probably figure (geddit?) out how to do it by referring to the illustration below.

The Figure Eight Knot.
"Probably" being the operative word. Some people have difficulty. It's not that they're unintelligent; more like their minds aren't really wired that way.

Back in my days as a low-ranking conscript in the Republic of Singapore Navy, I was once tasked to teach some newly-arrived seamen how to tie that knot (among other knots). So there they were, each with a length of rope, waiting for me to demonstrate. I had a cup of coffee in one hand and my piece of rope in the other, and proceeded to tie that knot using whatever I had at my disposal - that one hand.

One moment I was holding a rope end, and two seconds later, I was holding a Figure Eight Knot. If you didn't know better, it was like magic.

They asked me to do it again, slowly this time. I did so, several times, slowly. Still with one hand, as I contentedly sipped on my coffee.

That's when they got frustrated. They thought I was showing off. And they might be right, if I thought tying something as simple as a Figure Eight Knot, even one-handed, was anything to be impressed at. If they thought that was showboating, I wonder what they'd have thought if I started tying it while blindfolded.

Because that is certainly possible. More possible than most people probably realize. Why? Because once you get past the visual aspect of tying knots, you develop muscle memory and begin to be able to do it by feel. It's not a conscious thing.

But either way, they were barking up the wrong tree. They were supposed to be understanding how the knot is tied by observing where the end of the rope went in relation to the rest of the rope. They certainly weren't supposed to watch my hand, or fixate on the fact that I was tying it one-handed!

Now on to the web development equivalent...

Sometimes when learning code from a programming mentor, something similar happens. The programmer types really fast, not seeming to need to look at the keyboard as he or she produces large segments of code. It's not something for the trainee to emulate, because the programmer has already developed familiarity with the keyboard and that particular IDE, using customized shortcuts and personally-placed screen widgets.

The trainee should be focusing on the code produced on-screen and how it works. Not which fingers are pressing what buttons! You're learning how to code, not how to type!

Finally...

The lesson to learn here is, sometimes when trying to learn something, what's really important is the end result. How you get there is certainly negotiable. There are many ways to tie a Figure Eight Knot, and it doesn't really matter how as long as you get the end result.

Same with a typed segment of code. The compiler only cares about the code it's processing. It doesn't care how quickly you typed it, or if you used a few shortcut keys to copy-paste it, or if you used some fancy voice recognition parser to speak those commands.

Remember, focus. On the end result.

Gr8 seeing you, m8!
T___T

Wednesday, 29 April 2020

Social Justice League: A TeochewThunder Project

During the Circuit-breaker period introduced by the Singapore Government to combat the COVID-19 outbreak, many Singaporeans found themselves at a loss as they adjusted to a life without socializing, dine-in options and various other services. I had my own problems, which I won't go into here, but cabin fever wasn't one of them.

You see, I'm a programmer. And one thing about the introvert stereotype that's often applied to those of my ilk - there's a discomfiting amount of truth in it. I'm comfortable enough around people, but it's when I'm imposing my will upon a hapless machine to do my bidding that I'm truly at home. Suffice to say, being made to stay home didn't bother me nearly as much as most others.

The time spent staying home resulted in me catching up on an awful lot of code. And I completed projects, some of which I had started years prior to this.

Social Justice League

One of them was a browser-based game I had written in using jQuery - Social Justice League.

And yes, that name is a ripoff of the Justice League. But it's nothing like the comic or the movie. In fact, it plays more like a desktop version of Magic: The Gathering.

How did I get that idea?

Back in 2018, I was playing this really awesome card game. It's a mobile app, Stormbound. And that's where I derived most of my inspiration for gameplay. Each card needs a certain amount of points to play, and what card you play against is also a factor. Certain cards have certain attributes that can be incredibly powerful in conjunction with other cards, or against other cards.

Stormbound

Sometime around then, the SJW phenomenon had exploded all over USA and Canada. People were yammering on about Safe Spaces, intersectionality and micro-aggressions, and seemingly engaged in some obnoxious competition to see who was more "woke". Every day, on my news feed, all sorts of really bizarre shit just popped up. Some terms kept coming up, such as "mainsplaining", "Participation Trophy" and "Virtue-signalling".

That's when I started thinking: what if each of these terms were their own card, and I could play them against each other? What if I could literally play the Race Card, Victim Card and Gender Card? What would I call the points used to play those cards? Woke points.

When those cards got attacked and lost, I would call it being Triggered.

When they were returned to the deck like Magic: The Gathering, instead of calling it The Graveyard, I would call it The Safe Space.

Heck, this game just about wrote itself as far as concept was concerned. The terms I kept reading were now being put to good use. Feminazi, Snowflake, Keyboard Warrior, Tone Police, Whitewashing... all these were terms I now turned into cards.

Plenty of my friends were pretty enthusiastic about coming up with suggestions once I pitched the idea.

Coding begins...

After the conceptualization had started to take shape, it was time to stop thinking, stop talking, and just do it.

The Interface. First of all, I needed a visual layout in which to place the cards. This took the better part of two weekends as I hashed out what worked and what didn't. HTML and CSS is easy in principle, depending on what you want it to do. But manage I did.

Gameplay. And then came animation and Human-computer Interaction. What did I want users to click on? What would happen when they did? And how would they understand when they were to click, and on what? How could I design the flow in a way that made sense?

Cards

Cards. The visual aspect of the cards was simple enough. Since I wasn't planning to profit off ths game, I was quite comfortable using free stock photos from Pixabay. The various stats had to be arranged nicely, and there had to be three different sizes - the large one for more information, the medium one for representation in the player's hand, and the tiny one for the deck. But no, it was the game mechanics that I had to be very careful with here. Nothing game-breaking or totally useless.

Early on, I figured out that attempting to code animations by hand for such a big project was just asking for a lot of grief. So I learned jQuery UI. Best investment I ever made. After all, I was already using jQuery.

After I had coded the layout and the visuals and the main animations, all that was left was providing special abilities for each card... all forty plus of them.

Distractions, and eventual completion

While two years passed in the meantime, it's not like I had an entire two years to do this. Between work and learning new stuff, it was a struggle to find time to work on this. Sometimes I would achieve a lot in one spurt of enthusiasm, and other times I was just too tired. There were shiny new things to learn too - Ruby, ReactJS, D3, to name a few.

And then I got married, and things took a back seat for a while. I'd work on Social Justice League maybe once every few months. The inevitable happened; the project began to gather dust.

In the second week of the Circuit-breaker period, I sat down seriously and took stock of where I had left off with Social Justice League . And found, to my astonishment, that there wasn't that much left to do. Some cards needed to be coded, and others were ideas I discarded. All I needed was a little time.

And time was something I had an abundance of now.

It was done sooner than I expected. Sure, I'm a better coder now than I was in 2018, but even back then, I had the sense to write my code in such a way that I could recycle whatever I needed, and produce new functionality with a bit of copy-paste-editing. Over the course of a few hours, the last remaining cards were coded into the system.

The final piece.

I was done. Social Justice League was no longer "in progress". It was ready to play.

Aftermath

Words can't adequately express the emotional release that came from finally completing something that I've incubated in my mind for so long. Sure, Social Justice League is nothing ground-breaking. There's tons of room for improvement. It's nothing more than an amalgamation of cultural references packaged in snarky homage to self-righteous SJWs everywhere. But I made it. It's mine. Even if no more than ten people ever play it, I've completed a sizeable (by my standards) project.

At the risk of sounding dramatic, it's like this great weight has been lifted off my shoulders. Could I have done anything different? Of course. But that's no mean feat considering just how crap I was two years ago.

The sweetest thing about this whole deal was, I learned. My command of JavaScript probably increased exponentially. And being forced to use jQuery UI to handle the animations, added a new tool to my ever-growing arsenal. I made mistakes along the way, and learned from them.

No matter how Social Justice League is received by the world, it's been great.

Play your cards right!
T___T

Saturday, 25 April 2020

One Missing File

When undergoing the tech job interview process, sometimes it's the little things that trip you up. This is an amusing (and hopefully educational!) tale of one such incident.

I received a phone call from a tech company (which shall remain unnamed) and what would you know, I forgot that why I had even applied for the job and when. Somehow I recovered from that boo-boo and managed to have a coherent conversation with my phone interviewer about all things tech. The interview concluded with the interviewer telling me that she would get back to me after processing our conversation with her team.

A few days later, I received an email which contained a PDF - specifications for the code test I needed to pass in order to progress in the job application. After taking a gander, I was blown away. Now this was a fun one. Instead of asking me to answer a series of technical questions that made me feel like I was studying for an exam, this tech company wanted me to create a simple web application using no frameworks and libraries. For me, this meant HTML, CSS and vanilla JavaScript.

So the weekend arrived, and I spent most of it coding. I gave it my best. Proper indentation, proper spacing, clean code, code test coverage. Made sure the solution fit the specifications as stated. Tested the solution on multiple browsers and screen sizes. At the end of it, I even wrote a ReadMe file.

No zip files allowed!


GMail flatly refused to allow me to attach a zip file, thus I uploaded everything to a GitHub repository and sent them the link. They replied by politely asking me to set the repository to Private after downloading my code, and I acquiesced.

One week later...

I received an email from those guys informing me that "we have decided not to move forward with your application", which in layman's speak, simply meant that I had failed this round.

No matter. I asked them; since my code was presumably not up to their standards anyway, would they mind if I continued my work on the web app and reset the repository to Public? Their response was to ask me to continue setting the repository to Private.

Now this befuddled me. Ostensibly, they had originally asked me to set the repository to Private so that other candidates they might be evaluating did not copy off my work. But now that I'd failed, why did it matter if anyone copied my work? They would be copying something that wasn't up to the mark, after all.

I obsessed over this, going through my code and trying to figure out where it was lacking. I even added my ex-boss as a collaborator and asked him to help review it. And he pointed out something that caused me to facepalm.

Oh, FFS.

I was missing one file. Not just any file. I was missing index.html! I'd checked my solution before uploading but somehow neglected to re-check after uploading.

Oh, FSS. Of all the stupid mistakes I could have made...

As errors go, this was really elementary and I was horribly embarrassed. I probably will never speak of this again, but at least it makes for a good story.

The takeaway from all this

Don't get carried away by enthusiasm. Maintain a healthy amount of detachment, because if you're too close to the issue, chances are you're going to miss something that will be glaringly obvious in hindsight.

Stay hungry, stay foolish. But not too foolish!
T___T

Sunday, 19 April 2020

Why some things should not be automated

We live in a world that is increasingly being automated. Mundane tasks such as ordering food and buying groceries is now done via means of Food Delivery apps. Trips to the bank have long been supplanted by online banking services. No longer do you need to stand in line to purchase a movie ticket - mobile apps make this a huge convenience.

In the software industry, where software developers are responsible for much of this automation, it comes as no surprise that many work-related tasks are now subject to this very same automation. Automated DevOps is a thing. Manual testing still has its place, but test-driven development via automated testing is the de facto standard. Linters now beautify and neaten huge chunks of code at a click of a mouse button, a task that used to be manually carried out by the more obsessive of us.

Yet I say, some things in life should not be automated. Yes, they can be automated and indeed many people are already doing so, but my contention is that they shouldn't. Because the very act of manually doing them is what gives those acts meaning, and builds character.

Developing good habits

To give this some context, I'd like to relate an anecdote from last year.

My first-ever wedding anniversary was coming up, and I was stressing out over what would qualify as an acceptable anniversary gift. Like the average unimaginative guy, I was leaning towards jewelry, but my taste in aesthetics has always been horrible. And then my wife called me while I was at work one day and told me she had decided to buy another phone for some reason or other. She'd narrowed it down to two models, but couldn't decide and wanted an opinion. The first model cost 700 SGD and had a lot of features. The second model cost half that, had all the features she needed, but she was afraid it would be obsolete in a year and didn't want to risk wasting her money.

700 SGD? Shit, I could handle that.

I told her to head for the top drawer of the cupboard in our bedroom, look in the bottom left corner of that drawer. In it was a white envelope containing exactly 720 SGD. I told her to use that to buy her phone. I also informed her, quite gleefully, that this was her anniversary gift.

In one move, I had achieved a few objectives. I had gotten my wife something she actually wanted for an anniversary gift, and the beauty of it was, I hadn't needed to choose it, or even buy it myself. And my wife now thinks I'm some kind of miracle worker who can produce extra cash out of nowhere.

But that's enough bragging about how clever I am. The real question is - how did I happen to have that envelope of cash lying around just for this occasion?

Squirreling money away

You see, I have this habit of squirreling money away. 2 SGD a day amounts to 730 SGD a year. Over time, I'd simplified the formula to 10 SGD every five days, or just 60 SGD a month. The 720 SGD in the envelope was cash I'd squirreled away for the year of 2017, and forgotten about until that point!

It's not like I even needed the money. But years of being financially strapped and slaving away for cheap-bastard sweatshop bosses had ingrained this little habit in me. Even now, drawing more than twice what I used to earn as a web developer, I've refused to let go of this tendency to put cash aside.

Every month, my tenants pay me more than that 720 SGD in cash. I could quite easily put one month's rental in the envelope and forget about saving petty cash for the rest of the year. It would be convenient, and quite doable. And perhaps utterly disastrous in the long run. The only reason why I find it so easy to save money when other people have all sorts of problems, is because I've made a habit of it. It's something I do without thinking because I do it regularly and constantly. Were I to ease up just for the sake of making it even more convenient, sooner or later, I would lose that habit simply because I allowed it to atrophy.

Drawing a bigger paycheck can properly screw up your ability to live with less money. Or, if you retain the habits you developed when you were a lot poorer, make you a heck of a lot more resilient.

So yeah... I didn't automate that task. Or perhaps I did, but in a very manual way. Does that make sense?

Giving acts meaning

Since I began life as a working professional roughly two decades ago, I've been paying the Womb Rental. And by that, I mean that amount of money I give my mother every month. Some like to call it Parental Protection Money or Uterus Tax, but to each his own.

It wasn't always this way. When I was younger, I found this a drag and kept thinking of ways to smoothen the process. Maybe give her access to my bank account so she could draw the money herself? Maybe set up some kind of automated monthly payment to her bank account from mine? Or give her a whole lot of money at one shot so I could go for months without going through all that hassle?

Mom vetoed all of that shit. She wanted me to personally hand her cash, every month. It didn't matter how much, as long as I could afford it.

Funds transfer

At that time, I didn't understand. Wasn't my way more convenient for everyone involved? Why the insistence on the manual method? But after so many years of doing this, it's starting to make sense. As outdated as I think my mother's worldview is, and as desperate as I am not to turn into my parents, I'm beginning to think Mom may have had a point there.

You see, it wasn't about the money. It was never just about the money.

What my mother wanted was for me to get used to having to consider her needs at least once monthly. To get used to contributing to her finances ever so often. To prepare me for the day I would have to truly step up. My software developer mindset would have gotten in the way of all that.

And it's worked. Well, kind of. I take it as a challenge to remember to pay the Womb Rental on time. Every time my mother has to call me to remind me because I missed the date, I consider it a personal failure, and resolve to do better.

To Conclude...

Efficiency may be one of the ultimate goals of programming, but it isn't everything. It makes life easier immediately, but sometimes we need to look at long-term effects.

I really should automate this signoff,
T___T

Tuesday, 14 April 2020

Google and Apple's Proposed Collaboration on Contact Tracing

Whassup!

Remember TraceTogether, the app for contact tracing that's supposed to help Singapore in these trying times?

Collaboration!

Well, apparently Google and Apple are belatedly getting into the act. They just announced that they will be partnering to produce such an app that will work on both their platforms. I assume that means sharing resources and producing some cool shit, such as Bluetooth-based technology for aid in contact tracing.

Singapore's equivalent

And I hate to sound like a nationalistic jackass here, but we got there first. That's right - I didn't have a hand in the creation of TraceTogether, but it is my country and my industry that produced it and I'm feeling unreasonably proud at this moment.

TraceTogether

Other countries have asked if Singapore would license the code to them, and our Minister of Foreign Affairs, Vivian Balakrishnan, had this to say.

"We believe that making our code available to the world will enhance trust and collaboration in dealing with a global threat that does not respect boundaries, political systems or economies."


I don't like the guy (can't even remember why right now) but that is one awesome response. We're making this beauty open-source, thus making Singapore's work even more relevant to the world at large.

A possible problem with Google and Apple's proposed collaboration

Privacy has been kind of a hot-button issue ever since Google started using location tracking. Sure, we could always turn it off, but the fact remains is that Google collects a lot of data about its users. And users have absolutely no reason to believe that this won't be abused in the future. I mean, look at the state of the world as it was even before the Coronavirus outbreak started.

How do we balance a user's right to privacy with the immeasurable potential to save lives? There's no clear, correct answer. Even Singapore doesn't have the answer, though I think TraceTogether is a sensible compromise many of us can accept. However, I'm not going to offer the typical American response and declare that Singapore's solution works for every country simply because it works for Singapore. This is something every country needs to decide for themselves.

Eye in the sky.

Even in Singapore, there are those who refuse to install the app because they don't trust the Government not to abuse the privilege. They're concerned about their privacy and possible intrusions into it despite the fact that the COVID-19 situation in Singapore is getting worse, and everyone's lives, not just their privacy, is being threatened.

To these people, I say: It's not about you. It's not about what kinky porn you've been viewing on your phones or what embarrassing private business you've been up to. This is about all of us. There's a bigger picture out there, and you're not seeing it. It's all well and good to be prepared to die for your privacy. Are you prepared to let others die, as well?

Think about it. Stop thinking about yourselves for maybe one goddamn second.

Remember, stay safe out there!

Break out of the outbreak!
T___T