KSS - Coding Standards

‍General ‍Coding ‍Principles

  • ‍1. ‍Favour ‍reliability ‍and ‍readability ‍over ‍strict ‍formatting ‍guidelines, ‍but ‍if ‍you ‍choose ‍to ‍break ‍one ‍of ‍our ‍guidelines ‍you ‍must ‍be ‍prepared ‍to ‍justify ‍your ‍decision.
  • ‍2. ‍Follow ‍[Programming ‍by ‍Contract] ‍patterns. ‍Primarily ‍use ‍the ‍[precondition] ‍method ‍of ‍the ‍standard ‍library.
  • ‍3. ‍Write ‍unit ‍tests ‍that ‍cover ‍your ‍code. ‍Your ‍code ‍must ‍pass ‍the ‍unit ‍tests ‍before ‍your ‍pull ‍requests ‍will ‍be ‍accepted. ‍For ‍applications ‍and ‍frameworks ‍specific ‍to ‍macOS ‍and ‍iOS, ‍use ‍the ‍[XCTest] ‍framework ‍with ‍the ‍built-in ‍Xcode ‍support ‍for ‍your ‍tests. ‍For ‍frameworks ‍that ‍are ‍intended ‍for ‍both ‍macOS ‍and ‍Linux, ‍use ‍the ‍framework ‍and ‍project ‍structure ‍described ‍at ‍[swift.org].
  • ‍4. ‍Follow ‍the ‍Swift ‍5 ‍standard.
  • ‍5. ‍Don’t ‍work ‍on ‍the ‍master ‍branch, ‍or ‍on ‍the ‍development ‍branches. ‍Create ‍your ‍own ‍suitably ‍named ‍branch ‍from ‍the ‍development ‍branch ‍on ‍which ‍to ‍do ‍your ‍work.
  • ‍6. ‍Eliminate ‍all ‍compiler ‍warnings.

‍Specific ‍Coding ‍Guidelines

‍For ‍the ‍most ‍part, ‍follow ‍the ‍default ‍settings ‍that ‍Xcode ‍provides. ‍Don’t ‍fight ‍the ‍tools!

‍The ‍following ‍documents ‍provide ‍more ‍specific ‍coding ‍guidelines.  If ‍you ‍choose ‍to ‍write ‍code ‍that ‍breaks ‍a ‍recommended ‍guideline, ‍be ‍prepared ‍to ‍justify ‍your ‍decision.

import Foundation


struct PrettyPrintHistory {

    var items = [PrettyPrintItem]()

    var currentIndex = -1


    mutating func addItem(_ item: PrettyPrintItem) {

        items.append(item)

        currentIndex = items.count-1

    }


    func currentItem() -> PrettyPrintItem {

        return (currentIndex < 0 ? PrettyPrintItem("") : items[currentIndex])

    }


    mutating func next() {

        if (currentIndex < (items.count-1)) {

            currentIndex += 1

        }

    }


    mutating func previous() {

        if (currentIndex > 0) {

            currentIndex -= 1

        }

    }

}