From onemonth.com: Swift Programming Language Crash Course

by alfiehanssen

Originally posted on the One Month blog:

With the iPhone 6 announcement today, it’s the perfect time to talk about Swift and it’s impact on you as a developer or entrepreneur.

SO WHAT IS SWIFT?

Swift is a brand new programming language from Apple that you can use to build iOS and Mac apps with. It’s a modern language influenced by pretty much every other language out there. You can pinpoint features that come from Python, Ruby, C#, and others. That means Apple has spent a lot of time thinking about what impact these features will have upon developer productivity and happiness.

HOW IS IT DIFFERENT THAN OBJECTIVE-C?

You may not realize it, but Objective-C originally came out in 1983. That’s a very long time ago when it comes to computers.

For those of you who may not be familiar with it, Objective-C is essentially the C language with a slightly different syntax and an object oriented layer on top. It requires you to do a lot of manual work. For example, in most modern languages you can do something simple like this:

// What I wish we could do in Objective-C
NSString *first = “Chris”;
NSString *fullname = first + " Oliver”;

Instead, in Objective-C you’ve got to use a long-winded method to help you:

// Objective-C
NSString *first = @"Chris";
NSString *name = [NSString stringWithFormat:@"%@ Oliver", first];

The first example is far cleaner to read than the second Objective-C example.

With Swift, you’re able to do this:

// Swift
let first =Chrisvar name = first + Oliver// name now equals “Chris Oliver”

That’s a whole lot cleaner than both the previous examples! Swift even knows to interpret the variables as strings without us having to declare it.

IN COMES SWIFT

Many people have ideas for mobile apps these days. The problem is those ideas never get implemented after inception because you either need to hire an iOS developer or teach yourself Objective-C which is quite the commitment.

Apple knows that the barrier to entry of becoming an iOS developer has been fairly high. A modern language would solve a lot of these problems and make it a lot easier to build apps. So that’s exactly what they did with Swift.

At first glance, Swift looks awesome. Just look at the screenshot on the homepage:

https://developers.apple.com/swift

Are there no more semicolons? None! (Unless you want to for some crazy reason.)

Is that a simulator on the right side? Yes!!

Are they showing me a preview of my code in the sidebar? Yep! How cool is that?!

If you’re really interested in where some of these ideas came from, give Bret Victor’s Inventing on Principle a watch.

WILL IT BE AS GOOD AS THE HYPE?

Swift sounds really cool and a lot of people are talking about it but is it really going to be as good as the hype?

The short answer is yes.

Software is becoming an increasingly diverse industry. Phones and tablets are now entering almost every market imaginable. These devices are so helpful that everyone wants to figure out how to use them to make their lives easier.

This influx of interest in programming means that there are millions of people learning for the very first time. On the web, you can pick up Ruby on Rails very quickly but mobile has always been quite a bit harder. Swift aims to change that and provide a friendly language that can do everything Objective-C can with a much nicer syntax and feature set.

IT WILL BE WELL SUPPORTED

Apple isn’t generally a company to release something publicly and then abandon it. Swift has so much backing that it’s bound to grow extremely quickly. It can even work hand-in-hand with Objective-C code so you can start using it right away even.

I haven’t seen this much discussion about a new programming language for a while. Hacker News had a gigantic conversation thread with a lot of interesting insights into the language.

THE FUTURE OF SWIFT LOOKS VERY PROMISING

I’m sure you’ve noticed the trend of iOS-first releases for mobile apps over the past few years. Apple is aiming for Swift to help continue that trend. Everything seems poised for the language to be a huge hit as developers are incredibly excited with it. Someone even built a Flappy Bird clone in Swift after spending just 4 hours learning the language. Now that’s awesome!

In his spare time, Vimeo lead iOS engineer Alfie Hanssen teaches courses for onemonth.com, a Y-Combinator-backed online learning program specializing in one-month coding courses.

  • Sep 5 2014

CasperJS, our friendly testing tool

by accessmaincomputerfile

If there’s one thing we Vimeo devs hate, it’s murder. Another thing we hate: regression bugs. We push code to production dozens, maybe even millions of times a day, but without a dedicated QA team, bugs sometimes slip through the cracks. Even with unit tests, exhaustive manual testing, and a general holding-onto-our-butts, we need a little something that can act as the first line of defense against pesky regression, as well as allow for easy testing during the development process.

Enter the best open-source, javascript-based, automated testing framework named after a portly lovable ghost: CasperJS. (That is, until someone makes GhostDadJS).

Consider this snippet of our signup.js test (and while you do that, I’ll be over here cruising Tinder):


casper.start(config.base_url);
    common.ACTIONS.signup(casper);

    casper.then(function() {
        this.test.assertUrlMatch (config.base_url + '/home', 'on the Welcome page');
    });

    casper.thenClick('.logout a', function () {
        this.test.assertExists('.log_in_container', 'logging out and logged out page is         visible');
    });

casper.run(function() {
    this.test.done();
});
    

The config.js file lets us easily swap out variables, which is helpful in case we want to run tests on different environments. There’s a common.js file that contains widely used functions such as account creation, login, buy, and upload. We also use ChanceJS to generate test data for us (because everyone was tired of seeing my “@mariahcarey.com” email addresses in the db). This may not look like much, but coupled with Jenkins, this, and several other of these “smoke tests” run after every commit to master in our ci environment with the “—fail-fast” argument, which halts the entire build if there’s a failure.

 Some would say, “Hey, that’s overkill man!” or “Damn son, where’d you find that?” but these tests are pretty fast, and don’t add a considerable amount of time to builds. Also, I think it was  Matthew McConaughey who said, “It’s better to be safe than sorry alright alright alright.”

 Another thing we like about CasperJS is that anyone can write tests! Working on a new feature? Write a test! Refactoring a flow? Write a test! Write two! Hungry? Sorry! CasperJS can’t help you there.

 Tests can be as detailed and asynchronous as you’d like. For our payments system, we have tests that cover every flow a user can go through. In this snippet, we’re checking to see that promo codes for our OnDemand feature are working correctly:


casper.then(function() {
    this.withFrame('ondemand_cart_iframe', function () {
    this.test.assertSelectorHasText('div.total', 'Total: $19.99', 'Correct Amount shown     on cart');
    });
});

if (discount_code) {
    common.ACTIONS.applyVodDiscountCode(casper, discount_code);

    if (discount_code in PROMOS) {        
            casper.then(function() {
                this.withFrame('ondemand_cart_iframe', function () {
                    this.test.assertSelectorHasText('div.total', 'Total: $17                                .99', 'Correct Amount with discount shown on cart');
                });
            });
    }

This allows devs who make changes to anything payments related to simply run “casperjs test payments/” and sit back, check Worldstar, and not worry about the finance department losing their brains.

 This isn’t to say that all our releases are #iwokeuplikethis flawless, but having both automation suites that devs can run on a local branch as they develop AND top-level smoke tests that run constantly on check-ins to master means we’re getting closer to our dream of a world where hefty test scripts covering all aspects of the site run constantly on a staging environment, yelling profanities at every failure and crushing bugs before they get to production. Also, world peace and stuff.

 While CasperJS has its flaws (wait timeouts, UGH), it’s been part of our development process for a couple months now and we’re constantly iterating on it to make things faster and easier for developers, while attempting to keep our code quality at the highest standard.