Treehouse Intermediate Course Part 10 (API Design including Naming Methods) *STOPPED!

One day's break in between is fine. I plan to do just half an hour here - seems reasonable! So we're continuing with API design. From what I remember, this was basically about the rules of making code readable and logical. OK here we go!

Start time - 19:35

Naming Methods

Pasan starts off by recapping a method - this one is index. What he's describing is very dull. I can't lie!

Right some key rules -

1. Omit needless words

2. Avoid ambiguity

So a point here is whether it is clear at the use site - where the function is used.

Really - I've lost so much interest with this. If the next video does not pick up, then I'm leaving this stuff for now and moving on from Treehouse!

Fluent Usage

So grammatically correct English is important. Fair enough.

E.g. 'insert a at 1' is grammatically correct. A lot of it is prepositional - at, in etc.

Well, this has been a waste of time. It is so dry and without interesting examples that I'm going to leave Treehouse there. To be honest, it's come to a natural end with this theoretical stuff - my hope is that I'll pick up more in practice with the Udemy courses I have and come back to Treehouse at some point when this seems like easier content to digest. So a VERY brief entry for Treehouse, I'll finish with perusing Udemy courses I already have. Treehouse account being paused!

Time 20:08 (33 minutes total though not very useful!)

Time 20:34

So I've had a look through and archived a few Udemy courses. Some of these I spent good money, well, £10 on! No point looking at stuff from Swift 1. I also archived a couple that just looked a bit dull in content or the projects. The one that I have picked out is from Chris Ching, just because it has some challenges. I'm going to have a go at those to see what I can put into practice...

OK first one:

// CodeWithChris Learn Swift for Beginners
// http://codewithchris.com/learn-swift
//
// Challenge #1: The Lost Animal Challenge
//
// Instructions: 
// Given the two arrays below, write a function that takes a String as an input parameter and returns a Boolean value. The function should return true if the String input is in either array and it should return false if the String input is in neither array.
//
// Examples:
// Call your function and pass in the String "cat" as the input. Your function should return true
// Call your function and pass in the String "cow" as the input. Your function should return false



// Write your function below:

func stringFinder(_ animal: String) -> Bool {
    
    let array1 = ["dog", "cat", "bird", "pig"]
    let array2 = ["turtle", "snake", "lizard", "shark"]
    
    if array1.contains(animal) {
        return true
    } else if array2.contains(animal) {
        return true
    } else {
        return false
    }
    
}

stringFinder("dog")
stringFinder("shark")
stringFinder("tiger")

Well that was fun! I sued the .contains method - which I'm not sure if I've actually used before. But it was logical. In my examples, the first two are true and the tiger is false - so it works!

Let's just check the solution from Chris....

Interesting!

unc findAnimal(animalToFind:String) -> Bool {
    
    let array3 = array1 + array2
    
    for animal in array3 {
        
        if animal.lowercased() == animalToFind.lowercased() {
            return true
        }
    }
    return false
}

findAnimal(animalToFind: "Snake")

He cheated a bit as he kept array1 and array2 as global not local constants. Also, I don't like the if statement he used. Both are totally acceptable though - mine does work!

Right I've looked at challenges 2 and 3 and they look complex. Not that I don't know the information, but I feel like I need to go over some of this. Again! Pasan made it all very complicated before, so I feel like I just need a refresher to go over a few concepts. Here's my idea:

Using Chris's Udemy course I'm going to recap:

  • Data Types (skim through)
  • If statements (skim)
  • Switch statements (skim)
  • Loops
  • Functions
  • Classes
  • UIKit
  • Initializers
  • Optionals
  • Properties
  • Designated and Convenience Inits
  • Arrays
  • Dictionaries

This looks like a lot but to be honest, it's more of a recap. This is what I am going to look over for the rest of this week and next week. I feel like the need to get a fresh take on this after the some of complexity in Pasan's course.

I'll leave this entry here as it's now a renewed focus on the elements above. It's more consolidation at this point as I still don't feel equipped to confidently use what I know. I will, with more and more practice!

Time - 20:55 but the last bit doesn't really count!

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)