Skip to content

Instantly share code, notes, and snippets.

@soxjke
Created October 22, 2016 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxjke/c2f3052d28320de95e38df0b1ee3ec2d to your computer and use it in GitHub Desktop.
Save soxjke/c2f3052d28320de95e38df0b1ee3ec2d to your computer and use it in GitHub Desktop.
Breaking KISS principle for the win
//: Playground - noun: a place where people can play
import UIKit
typealias ๐Ÿป = String
typealias ๐Ÿ˜ฑ = String
typealias ๐Ÿ•ถ = String
typealias ๐Ÿ‘ = String
enum Decision{
case DontGiveAFuck(๐Ÿป)
case Panic(๐Ÿ˜ฑ)
case KeepItSimple(๐Ÿ•ถ)
case Fuckup(๐Ÿ‘)
}
enum Result {
case Win
case Fuckup
}
enum EngineeringPrinciples {
case SOLID
case YAGNI
case KISS
}
enum TestTarget {
case Device
case Simulator
}
var decision : Decision = .DontGiveAFuck("")
switch (decision) {
case .Fuckup(let ๐Ÿ™„):
// ...
break
default:
break
}
class Developer {
}
class Engineer : Developer {
func workWith(smth: String) -> Result {
if (smth == "UIWebView-based browser") {
return .Fuckup
}
else {
return .Win
}
}
func useMagic() -> Result {
if !self.understandsMagic() {
return .Fuckup
}
else {
return .Win
}
}
func breakTheRules(principle: EngineeringPrinciples) -> Result {
switch principle {
case .SOLID: return rand() % 2 == 0 ? .Win : .Fuckup
case .YAGNI: return rand() % 2 == 0 ? .Win : .Fuckup
case .KISS : return .Fuckup
}
}
func RTFM(m: String) -> Result {
if m.containsString("ARM Instruction set") {
return .Fuckup
}
else {
return .Win
}
}
func useGoogle(use : Bool) -> Result {
return use ? .Win : .Fuckup
}
func testOn(target: TestTarget) -> Result {
return target == .Device ? .Win : .Fuckup
}
func tryWithoutDebugger(without: Bool) -> Result {
return without ? .Win : .Fuckup
}
private func understandsMagic() -> Bool {
return false
}
}
var you : Developer = Engineer()
// case study
(you as! Engineer).workWith("UIWebView-based browser") == .Fuckup
(you as! Engineer).useMagic() == .Fuckup
(you as! Engineer).breakTheRules(.KISS) == .Fuckup
(you as! Engineer).RTFM("ARM Instruction set") == .Fuckup
(you as! Engineer).useGoogle(false) == .Fuckup
(you as! Engineer).testOn(.Simulator) == .Fuckup
(you as! Engineer).tryWithoutDebugger(false) == .Fuckup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment