Swift Sugar: Ternary Operators – Optional Extension

In my previous post, I wrote some custom operators to function like the Objective-C version of ? : when checking for nil. It worked great, but custom operators ˘\_(ツ)_/˘.

Another approach occurred to me that takes care of the visual clutter that bothered me about this line:

let dependentParameter = optionalParameter != nil ? valueIfNotNil : valueIfNil

I realized that I could simply write an extension to the Optional class:

Read More »


Swift Sugar For Optional Ternary Operators

It is a common situation that an optional parameter is being passed into a function and that some other parameter needs to be set based on whether or not the optional parameter is nil or contains a value.

A typical way of handling this in Swift might be to use the if-let syntax as so:

func aFunction(optionalParameter: String?) {

    var dependentParameter = ""

    if let _ = optionalParameter {
        dependentParameter = valueIfNotNil
    } else {
        dependentParameter = valueIfNil
    //do something with dependentParameter

Read More »

How Markdown’s Typographic Choice Reflects John Gruber Perfectly

I love writing in Markdown.1 For a long time it has bugged me that a single ‘*’ surrounding text was the syntax for italics rather than for bolded text. I thought that this was a minor mistake by Gruber and I wondered if he ever regretted it.

I was further convinced about my feelings when I became aware that Microsoft Word allows users to create bold text by surrounding text with ‘*’s, and especially when I started using Slack a while ago and their very simple Markdown-like also creates bold text with single ‘*’s.

But finally, recently, something dawned on me. As I’ve been inconsistently blogging for the last couple of years, I’ve been watching my own habits and tics. I notice that I always want to emphasize words typographically to communicate the strength of my feeling. As with overusing adjectives and adverbs, I recognize this as laziness in my writing, and I often (try to) pull back, because it’s noisy and distracting to the reader.

John Gruber is a thoughtful, conservative2 writer and is famously restrained in his design choices. So what I finally realized is that, consciously or not, he designated the simplest syntax for his preferred form of typographic emphasis. And obviously , he would generally prefer the subtle emphasis to the “hey dummy I’m trying to get your attention” emphasis. Given this line of reasoning though, I wouldn’t have been shocked if he had not even supported combining the two forms, which allows for the “apparently my words aren’t good enough to make the strength of my feelings apparent to the reader” emphasis! This line of thinking is also perfectly consistent with Microsoft and Slack making bold emphasis the default for a single ‘*’.3

This realization, whether true of false, has changed my feelings about the ‘*’s entirely. I am glad he made it the way that it is, and I am quite doubtful that he has ever considered it a mistake.

I’ve heard and read multiple accounts from him discussing Markdown, but I’ve never heard him discuss this prioritization. If I’ve missed it somewhere, I’d gladly update this post to reflect that.

  1. I like it so much I even made a contribution to simpler syntax for tables though if you want to use this, I highly recommend Brett Terpstra’s reimplementation ↩︎
  2. In the best way sense of the word, writing out of strengths, not speculation ↩︎
  3. #NoOffense ↩︎