Lonely Proton

Vim and Xcode

Xvim is a plugin for Xcode that adds Vim key bindings. I've used for a little over a week and its by far the best Vim emulation-plugin-thing I've ever seen for any text editor.

If you like Vim and are developing in Xcode then this is a most have.

How I am learning iOS development

For the past few weeks I've started getting into iOS development. Its something I have long wanted to do and now I finally have an idea for an app and enough time to sit down and figure out how the hell to actually write it.

So I thought it might be useful for someone out there in a similar situation to know how I'm approaching learning all this new cool stuff. So I've made a list.

1. Learn the language

First things first. If you have no experience programming then I would not advise you to start with iOS development. If I was you, and had no programming experience, then I would start with something like web development. Developing for the web is a lot easier to get started with and provides a good platform for learning concepts that'll become important later. I also don't think Objective-C is suitable for being someones first programming language.

If you however do have some programming experience then the first thing I think you should do is learn Objective-C. I think its wise to start learning Objective-C and not Swift because first all Objective-C isn't going away any time soon and there is already a lot of useful stuff written in it, and it would be a real shame if you couldn't understand it.

The Objective-C syntax is also quite different from most other languages that people are familiar with so you might actually enjoy learning a different language.

Lynda.com has a great course for learning Objective-C and it is how I got started.

2. Learn the basics of the platform

If you have experience with programming then learning Objective-C wont take much longer than a weekend. But that doesn't mean that you then know how to write iOS apps.

Creating apps is so much more than just the language. The hard part is learning all of Apple's frameworks.

For getting an introduction to the Cocoa Touch platform Lynda.com has another great course that helped me a lot.

Another course that I also found very helpful was their course on Core Data (A framework used for persisting data). In particular the chapter called "Putting it all together: iOS" was great. Here the author basically walks you through building a complete app from scratch. Good stuff.

3. Build something

Now its time for you get creative, get an idea for an app that you would like to exist and then build it. Try not to come up with something too complicated. I would recommend starting with some kind of list app (thats at least what I'm doing).

4. Research

That last thing you should be doing a lot is sucking up all the knowledge that you can possibly find. I've personally been filling my Instapaper queue with articles to read and videos to watch.

Here are some sites that I'm spending a lot of time on at the moment:

I hope this was helpful and I wish you all the best of luck.

Overcast

I've been waiting for Marco's podcast app to go live in months. Its finally here, and its awesome!

Swift InFlux

A list of things likely to change in Swift. I for one am very excited about this language.

Via Brent Simmons

Apple Pride

Apple supporting the gay community comes as no surprise to anyone.

A danish company would never do this. The amount of discrimination and in part also attention that gay people get are very less - but I guess it does make sense given the current state of the world, especially the US.

1Password for iOS 8

I think this the thing that gets me most excited about iOS 8 - the awesome extensions developers are gonna make.

This is a small preview of what an iOS 8 extension for 1Password might look like. Imagine not having to leave the browser to fill in a password, insanely great.

The Gunfighter

As you can see I have made some changes to the layout of the site and added linked list capabilities.

I first thing I'll link to is a hilarious short film about a gunfighter. You should go check it out.

Why I prefer reading on a Kindle

A few months ago I bought a Kindle. Not a Kindle Paperwhite or a Kindle Fire. Just a regular old Kindle with buttons. I specifically wanted this model for a few reasons.

I read differently

I don't always read, but when I do I'm reading with my finger. My finger is essentially telling my eyes where to look. It might sound strange but it helps me read faster and stay more focused when reading. Because of this I simply couldn't use iBooks on an iPad because you can't touch the screen without triggering all kinds of actions. This means that the button Kindle is really the only e-reader that I can use.

Its cheaper

I already have an iPad but its quite old (its an iPad 2) and it is starting to feel really slow. I know the Kindle isn't exactly faster but I didn't feel like spending the money on a new iPad just for the sake of reading. I also can't read for longer periods of time due on my iPhone due to reasons mentioned above.

Its more comfortable to read on

Having had the Kindle for something like a month and having read two books on it I'm happy I went it. Not only because I get to touch the screen but also because its actually a lot more comfortable to read on. I really like that the screen isn't backlit. Its much more comfortable for the eyes, especially if you're reading for longer periods of time.

So if you're considering a new device for reading I would advice you to get a one of the e-ink Kindles.

If the world was open source, part 2

Here are some more changes I would make if the world was open source.

Structuring JavaScript

I just finished quite a big project at work that involved more than 1.500 lines of JavaScript. This is not including vendor code. Its just code written for this one project.

I find that once you get over something like 100-200 lines of JavaScript it quickly starts to become very hard to maintain. I often find that the design of the language itself and what people normally use it for quickly makes code very unstructured and hard to wrap your head around.

However during this big project I learned a few things I thought I would share.

Its all about functions

Without a doubt the best feature of JavaScript is its functions. Functions can be used to accomplish so many awesome things in JavaScript and if you wanna learn more check some of Douglas Crockford's material.

One thing that I found functions are really good at (and often not used for) is to do information hiding. As you might know pretty much everything in JavaScript is global. There are no namespaces. If a function is defined inside one file then all files loaded afterwards can also see that function. This is bad because it quickly makes the global namespace very polluted and name collisions will occur more often. Functions solve this by providing closures. Here is a example:

Say we have a function that will take a form node as input and then check that all fields that are required are filled out and return a boolean. This function would then be called on submit:

// Find all the required fields within a form
var findRequiredFieldsWithin = function(form) {
  return form.querySelectorAll("[required]");
};

// Check if an array of fields are all valid
var allInputsValid = function(inputs) {
  var valid = true;

  for (var i=0; i < inputs.length; i++) {
    if (inputs[i].value === "") {
      valid = false;
      break;
    }
  };

  return valid;
};

// Find all the required fields and check if they are valid
var isValid = function(form) {
  var requiredFields = findRequiredFieldsWithin(form);
  return allInputsValid(requiredFields);
};

// Listen on the submit event and prevent it if the form is invalid
document.querySelectorAll("form")[0].addEventListener("submit", function(event) {
  if (!isValid(this)) {
    event.preventDefault();
  }
});

This code is, although quite simple, nice and well factored. However there is one problem. We have polluted the global name space with three functions. This could be cleaned up a bit by putting the functions inside a closure.

// We put everything inside a self executing anonymous function which will then keep the three functions from becoming global.
(function() {
  // Find all the required fields within a form
  var findRequiredFieldsWithin = function(form) {
    return form.querySelectorAll("[required]");
  };

  // Check if an array of fields are all valid
  var allInputsValid = function(inputs) {
    var valid = true;

    for (var i=0; i < inputs.length; i++) {
      if (inputs[i].value === "") {
        valid = false;
        break;
      }
    };

    return valid;
  };

  // Find all the required fields and check if they are valid
  var isValid = function(form) {
    var requiredFields = findRequiredFieldsWithin(form);
    return allInputsValid(requiredFields);
  };

  // Listen on the submit event and prevent it if the form is invalid
  document.querySelectorAll("form")[0].addEventListener("submit", function(event) {
    if (!isValid(this)) {
      event.preventDefault();
    }
  });
})();

A variant of this approach can be used when you still have some functions that you want to able to use in different places but you want those functions to have access to a set of private helper functions. This can be done using a pattern like this:

// Define an object to act as a name space for our own functions
var app = {};

// Make a self executing anonymous function and pass the `app` object into it
// Passing `app` as an argument is strictly not necessary but can provide
// a small optimization when minifying
(function(app) {
  // Private functions are defined in the closure of our self executing anonymous function
  var aPrivateFunction = function() {
    // Do some important thing
  };

  // Public functions are defined as properties on the `app` object
  app.somePublicFunction = function() {
    // Call the private function
    var value = aPrivateFunction();

    // Do something else...
  };

  // More code here
})(app);

// Call our public function on page load
$(document).ready(function() {

  app.somePublicFunction();

});

This technique of putting stuff you wanna keep private in a closure is quite simple but I have found that it scales very well. This was exactly how I structured all the code in that 1.500 lines project and it worked well.

← Archive