Case Status
Log In


(really) bad Swift
  • RSS Feed

Last modified on 8/6/2018 5:47 PM by User.


(really) bad Swift


I've used a lot of languages in varying degrees over the years, but as anything-but-a-coder. Until working on my iPhone app, the last project coded and shipped was in HyperTalk. 

As a "real" programmer, Swift has had its moments. Here's my collection, curated for humor. (I've been a professional QA tester for half my career, I assure you these are not representative of what is checked into our repository).

Swift Playgrounds

Apple created an iPad-only app that is an interactive tutorial for learning Swift. Its probably good for any reasonably literate kid, or any sufficiently motivated lover of games. [I'm working on the  "Learning to Code" track]

The concepts are introduced gently, and the code problems are Logo-like: kids learn by telling a funny looking duck how to walk around a maze. 

The default mascot, "Byte" looks like a flightless bird that was mugged by a Cylon snorkel… but my daughter thinks it is cute, and wants to give it a try. Works for me, I'm not the target audience of the mascot.

Experienced coders will probably think the maze architecture is too PG-rated. Byte will not blindly follow commands that involve falling off the edge, nor get damaged for walking into walls. In today's tech scene, it seems too much like the start of programming autonomous navigation, especially since Byte returns no complaints or errors. Your punishment for bad code isn't a compile error, or a crash, or mission failure. Instead you suffer by watching Byte faithfully execute whatever erroneous Swift code you passed in.

That makes the possible solutions rather permissive. You can write code that checks for gems on every square, or flips the switches on-and-off as much as you want. If you run the code in "Fastest" mode, Byte will remind you too much of a Roomba YouTube video. 

Hey Ben, where's the bad code?

(short version)

In today's puzzle, the lesson added gate properties, so you can enable/disable them. The puzzle suggested that the maze wasn't passable without controlling the gate state. The gate is a chokepoint at the middle of the maze. Going in from any span means coming out facing the original span. The lesson implies you can't solve the problem without turning off the gate.

After writing a expected solution to the problem, I accidentally reset the page... which means I couldn't go into the next lesson.

While re-implementing the solution, I realized there was a way to solve the maze puzzle without turning off the gate. The gate goes to a little 1x2 island, so you have to go to the non-gate square, turn around, and then return to the main island. 

So, as long as you make relative turns after you arrive on the small island *and* when you return to the main island, you can navigate by way of a round trip thru the gate.

The solution is more like a script, but it did remind me a lot of dealing with the rotating maze squares in Wizardry:

When you step on these tiles, you will wind up facing a random direction not of your choosing. Once you step off, camp and use DUMAPIC to be sure of your new direction before you progress through the maze once more, or you are likely to become very lost.

Hardly the shortest solution, but it works, even if someone turned off the maze safeties.