Podcasts

Podcast Episode 40 – whoami, an identity crisis

In this episode, I come back from my almost seven month hiatus to wonder about what this podcast should be and if I am putting out the kind of content that my audience and the audience at large is looking to hear. I talk about my original plans for the show, what I see in the podcasting space as a whole, and where I could go in the future. In the end, though, I am looking for feedback.

Leave a comment or tweet me @PeteOnSoftware and let me know. Should I:

  • Keep it up
  • Change it up (become more narrowly focused… if so, on what)
  • Give it up

Links Mentioned in this Show:

Gimlet Media

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.

Swift

Swift Extension Methods

I’m doing this code in the latest version of Xcode that is available as of this writing, Xcode 7 Beta 6. It does not work with Xcode 6 at all, because some of the features are only part of Swift 2.
Extension CordExtension methods are a language feature that allows you to add behavior to a class (“extend” that class’ functionality, if you will).

In .Net, extension methods are merely syntactic sugar. I previously talked about them here and here. I go into more detail in the links, but basically extension methods are implemented as new methods that take the “extended object” as a parameter. You might declare one something like this:

public static class StringExtensions
{
    public static bool StartsWithACapitalLetter(this string input)
    {
        return !string.IsNullOrEmpty(input) && Char.IsUpper(input[0]);
    }
}

Then, when I call “Pete”.StartsWithACapitalLetter() it returns true and “pete”.StartsWithACapitalLetter() returns false.

So, that’s .Net. What about Swift? In Swift, similar functionality can be achieved this way.

extension String {
    var StartsWithACapitalLetter:Bool {
        if (self.isEmpty) { return false }
        let firstCharacter = String(self.characters.first!)
        return firstCharacter == firstCharacter.uppercaseString
    }
}

As it stands, if I call “Pete”.StartsWithACapitalLetter I get true and “pete”.StartsWithACapitalLetter gives me false. Let’s break it down a little more.

The first thing you do is just use the Swift keyword extension in front of the name of the class you are extending. After that, you literally just “add code” to the class. In this case, I added a property (not a method) called StartsWithACapitalLetter that returns a boolean. Notice that within that method, I can use self just as if I had written this code inside of the original class itself.

That’s really all that there is to it.

Swift

Swift – Repeat Keyword

RepeatIn the Swift Programming Language – like all programming languages – we are given a lot of ways to control the flow of the program. Back when Swift was first introduced, I wrote a post to talk about the ways that Swift offered to control program flow.

One of the ways that I covered in that post was the while keyword. Using a while statement will cause the program to evaluate a condition first before it would ever execute the block. Take this code for example:

var counter:Int = 0

while counter < 10 {
    print("counter is at \(counter)")
    counter++
}

This results in the output of:

counter is at 0
counter is at 1
counter is at 2
counter is at 3
counter is at 4
counter is at 5
counter is at 6
counter is at 7
counter is at 8
counter is at 9

However, if you ran the following code:

var counter:Int = 0

while counter > 0 {
    print("counter is at \(counter)")
    counter++
}

There is no output. Since counter is 0 and the while block only executes for positive values, nothing happens.

Let’s see how repeat is different. We’ll try the first example again.

var counter:Int = 0

repeat {
    print("counter is at \(counter)")
    counter++
} while counter < 10

This results in the same output of

counter is at 0
counter is at 1
counter is at 2
counter is at 3
counter is at 4
counter is at 5
counter is at 6
counter is at 7
counter is at 8
counter is at 9

But, the second example of

var counter:Int = 0

repeat {
    print("counter is at \(counter)")
    counter++
} while counter > 0

Results in the code running for ever and ever and ever. It only asked if the variable was greater than 0 after the first pass. Since by the time the code had exited the repeat block the value of counter was 1 (and therefore positive), we just kept going (I stopped it when the last few entries looked like this):

counter is at 10789
counter is at 10790
counter is at 10791
counter is at 10792
counter is at 10793
counter is at 10794
counter is at 10795
counter is at 10796
counter is at 10797
counter is at 10798
counter is at 10799

You might be saying to yourself, but Pete.. this sounds exactly like a do-while loop vs a while loop. Well, you’d be 100% correct. Even according to the Swift documentation, “The repeat-while loop in Swift is analogous to a do-while loop in other languages”. C’est la vie!

Business of Software

Podcast Episode 39 – Warren Buffett’s 25 and 5 Rule w/ bonus Amazon Underground Discussion

Warren Buffett, By USA International Trade Administration (https://www.youtube.com/watch?v=GLKDFhCjaY4) [Public domain], via Wikimedia CommonsToday, I heard about Warren Buffett’s “Two List Strategy”, also known as the “25 and 5 Rule”. I don’t know if the story is apocryphal or real, but I think the lesson is just as valid. When I got to my picks of the week, the first one went the normal way. But then I started talking about Amazon Underground and apparently I hit a hot button with myself. I ended up talking about Amazon Underground for about as long as Warren Buffett’s strategy. We go where the muse goes 😉


Links Mentioned in this Show:
Warren Buffett’s Two List Strategy
David Smith’s Twitter
Do Not Let Your Users See Spinners
Amazon Underground

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.

Podcasts

Podcast Episode 38 – A Stream of Consciousness Rant: The Development Community

A StreamIt has been a little while since I posted a new episode, so when inspiration struck me while waiting in the car, I didn’t pass up the opportunity to record Episode 38. I used my phone as a voice recorder and shared a kind of stream-of-consciousness rant. Some things had really piled up on me recently, not the least of which was my disgust with much of the development community at large. Major targets of my focus include judgement of new developers, judgement of people by their technology of choice, my dislike of “Why I’m Leaving X” posts, and how being yourself doesn’t mean that you need to be a douche when interacting with others.


Links Mentioned in this Show:
21 Management Things I Learned at Imgur
Asciinema.org

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.