Categories
Geekpulp

Zombie code

Part of developing (and certainly learning to develop) is creating code, commenting it out, and creating a better version. As you get into a flow state with coding it’s really easy to get into he habit of doing this and not going back and clearing out the undead code comments.

Here’s an example of what I’m talking about.

function thriller() {
  return “Something evil\'s lurking from the dark”;
}

//function funkyTown() {
//  chargeKeytar();
//  dressInPastels();
//  return “Gotta make a move to a town that\'s right for me”;
//}
//funkyTown();

thriller();

The trouble with code like this is it’s not clear why the commented out code is there. Is the intention to reworking and use it? Can we remove this because the code was old? Was it commented out accidentally?

Zombie code is ambiguous code, and that’s not helpful for anyone. It’s fine in your own dev environment in the short term, but don’t leave it in too long and never let the zombie out in public. It will only eat everyone’s brains.

Categories
Geekpulp

Keep your friends close and your variables closer

Back in the day, I used to have this habit of declaring all of my variables at the top of the file. My thinking at the time was it would keep everything organised so if I needed to jump to one I’d know where to go looking.

While that might sound like a sensible approach I’ve recently learnt there are quite a few shortcomings of doing this. The main one being the larger the project gets the more difficult it is to debug problems. Jumping about the file all the time just adds to the dreaded mental load, and that reduces your problem-solving skills.

Instead, try putting your variables close to where they’re used. It will reduce your variable hunting and in the rare situations you can’t find something, remember you can just use search.

Categories
Geekpulp

How to function correctly

Coding is a fairly amazing thing to be able to do. There are effectively no limits to what can be done when you’re more or less writing the universe from scratch. Having said that if Spider-Man movies have taught us anything (and I think we can all agree they have) it’s that with great power comes great responsibility. So yes you can do anything, but the truth is your functions at least shouldn’t do everything. When you’re writing a new function make sure it’s only doing what its name implies. Take the following example:

function setHipsterEBikeSpeed( speed ) {
  brewHipsterCoffee( “Double shot decafe soy latte” );
  if ( speed < 20 ) {
    return “Low and slow”;
  { else if ( speed < 40 ) {
    return “Fast and furious”;
  } else {
    return “Might be safer to walk”;
  }
}

The name of the function implies we are going to use it to set the speed of a hipster e-bike, and while that is true it’s also brewing a hipster coffee at the same time, despite not making that clear in the name.

Ideally, the best approach here is to not brew coffee while setting the speed of a hipster ebike (this is true in life and code), as functions are best to be unitaskers the vast majority of the time. If for some reason your function needs to do a combination of two or more things then make sure it’s descriptive enough to communicate what it will do. Other developers will thank you for it.

Categories
Geekpulp

Simplify conditional statements

Consider the following code:

function danceLikeNoOnesWatching( person ) {
  if ( person.danceMoves === “amazing” ) {
    return false;
  } else {
    return true;
  }
}

Looks good right? It’s logical and easy to understand, just your standard if statement. All true, but over the course of an entire project you’ll make a lot of considtional statements like this and using 5 lines of code when 1 will do can create some serious size increases to your code. To reduce the codes size, just return the output of the conditional like this:

function danceLikeNoOnesWatching( person ) {
  return person.danceMoves === “amazing”;
}

Simpler, still easy to understand and now light weight.

Categories
Geekpulp

Avoid abbreviating variables

Do you know what’s super annoying when reading someone else code? Abbreviated variable or function names. Until late 2017 I hadn’t done any coding in years so I was rusty as all hell, and truthfully I still am. One thing I noticed when looking at other peoples code was how it made it far slower to read and learn from when all the variables and function names are abbreviated. Yes, it might be faster for the person writing the code at the time, but anyone else exposed to that code carries a bit more mental load to decipher it. Take this simple code for example:

var prsn = {
  n: "Emma",
  a: 7,
  loc: "Palmerston North",
  frnds: [ "Ella", "Megan", "Tom" ]
};

prsn.prntFrnds = function() {
  this.frnds.forEach( function( frnd ) {
    console.log( frnd );
} );
}

Now compare this to the same function without abbreviated variables and function names:

var person = {
  name: "Emma",
  age: 7,
  location: "Palmerston North",
  friends: [ "Ella", "Megan", "Tom" ]
};

person.printFriends = function() {
  this.friends.forEach( function( friend ) {
    console.log( friend );
} );
}

Both examples are technically the same. However, it’s far easier to understand the second example at a glance, especially for a beginner who’s already looking at something relatively unfamiliar.

So the next time you catch yourself writing a block of code just remember to take a second for the next person reading it. Your code should be as descriptive as possible, so even a junior developer understand what it’s for at a glance… or someone who hasn’t seen the code in a long while… chances are that someone will be you at some point.

Categories
Geekpulp

iPad Pro

I’ve been really loving working on my 10.5-inch iPad Pro since I got it around a year ago. Recently the newer, fancier 11-inch pro came out and as much as I lust after the new design I’ve decided not to upgrade this time around.

The main reason’s the hardware side of iPads seem so vastly ahead of iOS, my current model has a good chance of getting the improvements I’m wanting without shelling out for new hardware every year or two. There’s a bunch of stuff that’s limiting on my current pro that only software can really address. The things that hold me back are relatively minor in isolation, but combined they paint a picture of productivity friction that doesn’t match the pro moniker.

USB drive support in the files app

I don’t think this is something I would use all that often, I certainly don’t on my Mac, but it’s one of those capabilities that when you need it, you need it. Its absence is a particularly egregious limitation given how Apple devices have been shooting 4k video (which are very large files) for some time. Copying large files like this to a drive is often a much faster way of working and collaborating on this sort of thing.

Safari

iOS 12 multi tasking

Mobile Safari is an amazing thing, but sometimes it just doesn’t cut it, particularly when it comes to downloading files. For example, I want to download a file from a stock image site to include in this blog post, no can do (at least not in an obvious way) in Mobile Safari, yikes!

The camera app

Something I really like about the notes app on iOS is the document scanning function built into it. The only issue, I use Bear for note taking. On an iPad I rarely, if ever, use the camera for taking pictures but I frequently use to scan documents or take pictures of whiteboards. It would be great to be able just pop open the camera app and scan away. Scanning should be a system-wide capability and the camera app seems the obvious place to have it.

Image via The Verge

Multitasking improvements

There’s quite a bit in this space, but for me, it’s all about polishing what’s in the system now. I love using split screen to have two apps side by side, normally I use this when I’m doing things like replying to emails and want a browser to look stuff up at the same time. The biggest issue is there’s no way of seeing which application has keyboard focus. Yes, it’s a minor thing, but it’s little bits of friction like this that add up on daily iPad use.

Setting default apps

There’s a vast number of fantastic third-party apps available to meet just about any need. For instance, I use Outlook for my email, calendar and contacts because it works better with the Office 365 infrastructure at work. Unfortunately, you can’t set an app like Outlook to be the default “manager” of these activities. So if I click an email link in Safari, up pops the standard mail application. Not exactly ideal and certainly not pro.

The good news about all of these shortcomings is they are 100% solvable and (touch wood) are fairly likely things to come in a future release of iOS. Cool factor aside, skipping the new iPad Pro this time around feels like the right thing to do. There’s a lot of room for my existing device to grow with software updates, so it just doesn’t make sense for me, no matter how high the cool factor. The joy of Apple products.

Categories
Geekpulp

Running lessons​

Over the past few years, I’ve had an on and off relationship with running. I’m not sure I’d go as far as saying “I’m a runner”, but I have run a few half marathons and had periods of time where I’d run at least 5 km a day. Over this time I’ve learnt a few things I didn’t expect when I started.

There’s a difference between knowing the path and walking the path

Yes this is a quote from The Matrix and yes it’s a cliché, but neither of these things makes it any less true. I’ve always known if I really wanted to run 10km or even a marathon I could. Here’s the thing, knowing I could do these things didn’t change me, it didn’t challenge me, it didn’t add any real value to my life. In fact, all it really did was inadvertently stop me from doing things that make interesting people… well… interesting. Doing is where the value is, so go out and do.

It’s all in your head

Running is physically challenging, you can’t just get up in the morning and run a marathon (not well anyway), you have to train your body to meet the physical demands of a run. The aha moment for me was about my 3rd-4th run. About then I started thinking about not running. I started hearing my mind saying, “screw this”, “why bother”, “might as well stop”. Overcoming my own self-talk was 90% of the battle and it continues to be. The great thing about this is building mental toughness, persistence and grit have a far greater effect on everyday life than simply being fit. Staying mindful of your thoughts is the first step to overcoming them.

Goals matter

Without the right outcomes, there’s no purpose in an activity. This sort of calls back to the mental component of running. If I don’t give myself a ”why” it’s much harder to fight the voices of decent in my mind. Goals give me sort of physiological ammunition, so when I start to think of stopping, instead I can just smile and say to myself, “not today brain, today is for X”.

Marathon runner
Me about 100m away from completing my first big “race”

Balance is important

When I first started running I would go out every day and just try and smash it. I’d push myself hard and as a result, tire myself out. It wasn’t long before physical tiredness gets the better of mental will, and I stop running with the excuse, “I’m just not a runner”. As it turns out to find success I didn’t need to kill myself. What I needed to do was show up. Not every day is going to be your fastest, your longest, your best, but if you don’t show up you make certain it won’t be. This also applies to recovery and rest. Introduce some “nothing” into my day really helped me to learn to take time for nothing, clearing my head, refreshing my body, giving myself a chance to succeed.

Every day is its own challenge

After a few runs were behind me and I got comfortable in a “quick 5km”, running begins to feel mundane. Becoming a little less impressed with each run I needed to challenge myself again. For me, this was another aha moment. Greatness is all about raising the bar. It’s treating myself like a project, being mindful and working to become a better version of me. Yesterday’s challenge was for yesterday’s version of me. Greatness comes from how a behave here and now, not yesterday. Today is where greatness lives.

Categories
Geekpulp XR (AR/VR/MR)

Oh yeah!

Hey, so in case you haven’t heard already the Oculus Quest is a thing. It’s been a long time coming but we finally have proper PC free VR. I’m not going to go into any real detail about it other than to say I’m super excited to get my hands on one of these things when it’s released next year. If you want to know the ins and outs of what’s currently known about the product I’d suggest watching tested.com’s coverage of it at Oculus Connect 5 below.

Video via Tested.com
Categories
Geekpulp

Moving host

Hey team, I’m moving this site to a new host and I’m yet to polish things up. Forgive me if things are a little rough around the edges at the moment.