
Harnessing Code Generation to Increase Reliability and Productivity on iOS at Uber - chmaynard
https://eng.uber.com/code-generation/
======
mpweiher
It's good that they at least recognize that code-generation is a crock.

"If you are using code generation to solve a problem that might be better
solved by making your code more generic, code generation will probably have a
degradative effect on the health and maintainability of your codebase."

Basically, if you have to resort to code generation:

1) Abandon all hope, ye who enter here[1]

2) The abstraction mechanisms available to you are deficient.

[1]
[http://www.cs.cmu.edu/afs/cs.cmu.edu/project/able/www/paper_...](http://www.cs.cmu.edu/afs/cs.cmu.edu/project/able/www/paper_abstracts/archmismatch-
icse17.html)

~~~
crdoconnor
They're recognizing for the first case that if you have to resort to it you're
trying to cover for some sort of deficiency in the language. Which is good.

I think the kind of thing they're doing would be possible without code
generation in a good dynamically typed language or a language with a feature
like F#'s type providers, but maybe swift doesn't allow it.

The second use case (generating test mocks) is a pretty bad reason to use code
generation IMHO. Instead they should be generating non-turing complete code
representing the mock (JSON or something).

~~~
Robin_Message
The mock is called by Swift code in test cases (that's the point of a mock) so
how would generating some JSON help?

~~~
crdoconnor
Actually I'm now starting to think that the idea I had in mind (generate the
mocks on the fly using JSON data) might not be possible.

------
dep_b
> iOS does not have an equivalent to Android’s R class

I use R.Swift in every project for a while already. My template Podfile has it
as well as a linter.

The mock generation tools look neat. Swift is a complicated language to write
tests in as it stands now and using Objective-C limits the things you can do
in swift.

------
rimliu
If you are not Uber and do not suffer from NIHS there are
[https://github.com/mac-cain13/R.swift](https://github.com/mac-cain13/R.swift)
and
[https://github.com/SwiftGen/SwiftGen](https://github.com/SwiftGen/SwiftGen)

~~~
jchw
They mention at the end of the article that SwiftGen did not exist at the time
they made their own tooling.

