automatic programming identifies a type of computer programming in which some mechanism generates a computer program to allow human programmers to write the code at a higher abstraction level — Wikipedia 3 — Code Generators in Swift, #se2016
types or objects structure in runtime There are languages, where still have Runtime, but still want to generate code WHY DO WE NEED CODE GENERATORS IN SWIFT? > No Runtime > Static Typing > No simple way to get types in runtime* > Hard to get metainformation at runtime* 8 — Code Generators in Swift, #se2016
public let image: String public let name: String public let description: String public let currency: String? public let serviceCharge: AdditionalCharges? public let paymentMethods: [PaymentMethod]? } 53 — Code Generators in Swift, #se2016
up let validShop = Shop.restrictedRandom( shopId: "SE2016", currency: "UAH" ) // Everything will be copied but 'shopID' property let anotherShop = validShop.updated(shopId:"123") // If we want to set up nil value let notSavedYet = validShop.updated(internalId: Optional(nil)) let notSavedYet2 = validShop.updated(internalId: .Some(nil)) 59 — Code Generators in Swift, #se2016
will we be talking about here and today Generatros why do we need them Why genertaors? What other options can we have? What we're tryin to achive? How we can do that? Next steps The ide of the all programmers is to not writing code less code - is better But it doesn't mean that this means than you need to write less code in the final language Right? No matter how many real code will be generated - if you have original code - less - is better Reperetive operations We dont' want to perform repetetive opertins. It's really easy for a brain to perform repetetive tasks. Really. But it's also really boring, and really time consuming So in case if we can automate - we should Small task size | Big task size | Fast to automate | Takes long time to automate If it takes less time to automate... What other problems we have here? Repetetive tasks tend to have copy-paste errors. Yep. Let's say, that Programmer will make a stupid mistake once per 1K lines of code (removed and deleted) Few More Facts Generated code is easier to remove Example with tests book Other examples of transformations Code Generation as Transformation -> One Form -> map -> AnotherForm XML + XSLT - ... Xib + Compielr - UI SwiftCode + CLANGCompiler -> ARM instructions A Bit of History - we have an API - mapped to the JAva groovy + APi spec (Java + RetroFit) - then we need to use that api on both Android and Other systems - we also need to have API tests, since most of our subcontractors weren't doing testing right - so we decided to write "Spec" which will describe everything and we'll use it to generate clients - And original Spec was a THE END 67 — Code Generators in Swift, #se2016