Index | Archives | Atom Feed

Be Careful Typing Swiftly

By default, Swift does not implicitly cast number types for arithmetic operators. For example, you'll get a compiler error for the following code in Swift:

var anInt: Int = 10
var aFloat: Float = 20.0
var result = aFloat / anInt

Instead you have to cast one of them to match the other, like so:

var anInt: Int = 10
var aFloat: Float = 20.0
var result = aFloat / Float(anInt)

I discovered this when I first sat down to play with Swift in the labs, but it quickly made sense to me as a design choice. It made me think a lot more explicitly about the underlying types and what I really want from the operation. This bit of code on GitHub would make the first code snippet work. I know it's tempting to use something like it to make life easier, but part of the beauty of Swift is the language forces you to think about types more explicitly. Doing so should result in better code, and will help get rid of a whole class of problems you may have down the road.


WWDC 2014

WWDC has come and gone. While the iOS 8 and OS X Yosemite announcements were great, and will change how we use Apple devices along side each other, the really big announcements were for once truly for developers. This included Swift (a new programming language), tools in Xcode (visual debugging, async testing, performance testing, etc.), beta distribution (TestFlight!), and so much more. I'm still only half way through the WWDC sessions I want to watch. It's going to take some time to digest everything. There's so much new stuff; it's truly mind-boggling. I'm sure all developers on Apple's platforms are very happy with this WWDC.

Most of all, this WWDC has shown us a new Apple. It's one that has finally been able to emerge from Jobs's shadow, and with more confidence and openness than ever. The keynote was bursting with confidence, and Craig Federighi is at the forefront of that. Apple even took Craig's hair and poked fun at it during the keynote. Apple's traditionally been very secretive. In previous years, WWDC videos and pre-release documentation were always under NDAs. This is the first time anyone can read up on and learn about all the new things. There are also more collaboration and openness between workgroups within Apple. Otherwise, features like Handoff between iOS and OS X wouldn't have been possible. Overall, I'm looking forward to using all the new tools and exploring all the new APIs, but most of all, I'm excited to see where Apple will take us in the next 3-5 years.

P.S. Given the advent of Swift, it's probably time to change my placeholder logo that's referencing Objective-C.


On Writing

I've decided to start writing more. Part of the motivation grew from reading blogs of other developers, such as Brent Simmons's amazing inessential. Writing has since grown on me and has become a lot more.

Writing, especially publishing on the web, was very difficult initially, but it has gotten progressively easier. Part of it may be due to more practice, but I feel most of the improvement from building rewriting into my writing workflow. For me, a thought rarely comes out right the first time and almost always needs rewriting.

I've started carrying a pen and notebook with me, as I noticed I solve some coding issues better on papers first. It is the same for writing. Writing the old school way removes the distraction of a computer and helps me focus better. It also forces me to do a rewrite when I transcribe it into my draft document on Dropbox.

As a result, I'm much happier with the final result compared to the first draft, and I'm also much more willing to publish it. I'm looking forward to writing and sharing more in the future.

P.S. My new found obsession of fountain pens may also be contributing to this. Maybe I'll write about it one day.


Website Migration, Again

In my previous post, I detailed my new setup. I initially chose to use the most popular distribution of linux, Ubuntu, for my DigitalOcean VPS. I made this decision because any problem or question I may ever have about Ubuntu has probably been answered on the web. It probably made some things easier for me on my first VPS, but after a bit of reading, I've decided to switch over to CentOS. CentOS is designed for enterprise use, and focuses on stability of the OS, which is perfect for servers. There are a few drawbacks, such as some packages being older, but nothing that isn't impossible to work around. With the announcement and patching of the Heartbleed bug/exploit, this is as good of a time as any to make this move. Even though I am not serving anything through SSL, I may in the future and don't want it to bite me later.

I started with taking a snapshot of the current Ubuntu server using DigitalOcean's web panel. I wanted to make sure I had a known-good configuration that I can fall back to if everything went to crap for some reason. I then created the new droplet, logged in as root, and started installing packages using yum. The only big issue I had to resolve was that CentOS only has Python 2.6.6, while I needed 2.7.* for Pelican. Since yum and some other things in the system rely on the system python, I had to install python2.7 in /usr/local/ Thankfully it was fairly straightforward to install using the make altinstall command.

Everything was smooth sailing from there. I updated my DNS entries to point to the new droplet. After that propagated sufficiently (I had a TTL of 30 minutes), I stopped the old droplet, took a final snapshot of it, and destroyed it. While it took a little bit of time for the migration, it was all very simple.


New Website

A while back I planned to start writing more. It started on Tumblr, but quickly fizzled out. I tried out Squarespace recently since I heard so much about them through the various podcasts I listen to. While it was nice and I would highly recommend it for many, it wasn't for me. They do have very nice templates and a great WYSIWYG system. Their iOS apps were great as well, and I used them to start a few draft posts. I just never got around to finishing them up on my computer and publishing them. I didn't like the fact that the only way to write and post on a computer is through their web interface. I like my native text editors too much, especially on the Mac, to give them up.

Then I realized VPS hosts are crazy cheap these days, with a basic plan at Digital Ocean coming in at $5/mo. There's also a ton of information avilable on the web to help if I bump into any issues. Here's how I've got everything setup.

This website and blog is generated using Pelican, a Python static site generator. I write the posts in Markdown and keep the drafts in Dropbox. Finished drafts are added to a git repository, which gets pushed to the servers repository. A post-update hook triggers Pelican to regenerate the site. Finally, nginx serves the content to the world.

The neat thing about this setup is I will always have a copy of all my writing, and switching platforms later isn't hard. I also have a solid handle on each part of the stack, or can find help through Google easily enough. The serving of the static pages is guaranteed to be fast. I can also quickly push updates and regenerate the site from anywhere I have access to an ssh client, which is pretty much anywhere I can get my iPhone/iPad/MBA online.

This isn't the right solution for everyone, but if you have some technical chops and want to have a personal website, there's little reason not to self-host. For everyone else, I can strongly recommend Squarespace. They have an amazing platform and really great templates that look and work well on both desktop and mobile platforms.


CMStepCounter Quirks

I've been playing with CMStepCounter in the iPhone 5s lately, and observed some interesting behavior. When I query the step counter minute by minute, steps occasionally get lost between the minutes. So sometimes querying steps for time1 to time2 and time2 to time3 results in a sum less than directly querying time1 to time3.

This looks like a bug with CMStepCounter or the M7 chip. I want to provide a consistent experience at least within the app, so for now I'm only querying for the smallest intervals I need, and summing those up for the less granular data points.

© Simon Yang. Built using Pelican. Theme by Giulio Fidente on github. .