Comments (19)
We should check for slowly compiled methods before doing something about them.
http://khanlou.com/2016/12/guarding-against-long-compiles
from ios-handbook.
Basically, you mean:
let percentage: Double = 10
Instead of:
let percentage = Double(10)
from ios-handbook.
π
also not:
let percetange = 10 as Double
from ios-handbook.
We don't do that one, though.
from ios-handbook.
Not for this specific case. π€
Thinking about stuff like let json = json as? [String: Any]
and there I think we should keep the as
stuff for sure. No better way.
from ios-handbook.
So yeah, nevermind the as Double
.
from ios-handbook.
What about:
let collectionView = UICollectionView()
Should it be:
let collectionView: UICollectionView = UICollectionView()
Or are you thinking in doing this for some specific cases?
from ios-handbook.
Only where type can't be correctly inferred. Code should be as verbose as needed but not verboser*
* not a real word
from ios-handbook.
Only where type can't be correctly inferred.
let percentage = Double(10)
What's incorrect about this?
from ios-handbook.
Nothing, it's just become inconsistent with the rest as we adopt type annotation instead. π
from ios-handbook.
So we have two options:
Option A:
Use type annotation when it's needed.
let percentage = Double(10)
let collectionView = UICollectionView()
lazy var view: UIView = {
}()
// Type annotation required here, it's obvious, if you don't add it won't work.
let generic: Generic = Generic(value: 1) * Generic(value: 2)
Option B:
Always use type annotation unless the type is obvious such as when assigning a new instance to a variable.
let percentage: Double = 10
// Type annotation is not needed here, since it's obvious looking at the result of UICollectionView()
let collectionView = UICollectionView() // Otherwise it would be let collectionView: UICollectionView = UICollectionView()
lazy var view: UIView = {
}()
let generic: Generic = Generic(value: 1) * Generic(value: 2)
They both are pretty much the same, so I guess it all comes down to.
let percentage = Double(10)
let collectionView = UICollectionView()
vs
let percentage: Double = 10
let collectionView = UICollectionView()
from ios-handbook.
I think having the first one. "Use type annotation when it's needed." Makes more sense since it's easier to be more consistent, basically the only place where the rule will be violated will be when using generics, which is not that often.
Meanwhile. going for "Always use type annotation unless the type is obvious such as when assigning a new instance to a variable." means that you're violating the rule every time you do:
let collectionView = UICollectionView()
Which is several times in any app.
from ios-handbook.
I don't think I understood your point. The rule change would mean that instead of
let percentage = Double(10)
You'd do
let percentage: Double = 10
So it's consistent with generics, etc. π€What am I missing? I don't think anything else changes.
from ios-handbook.
The rule change it's only consistent with generics, which we don't use that often, not with:
let collectionView = UICollectionView()
Which is all over the place.
from ios-handbook.
But this doesn't change. It's still the same. π€
from ios-handbook.
@elland I think this has improved sufficiently in Swift 4 that we don't need this as an official standard. Do you mind if I close this out?
from ios-handbook.
@designatednerd do we have numbers on that? π
from ios-handbook.
Not officially, but we've got the toshi project set up to warn us if anything takes more than 200ms to compile. Even on my cranky old computer the number of things we've needed to add annotations to in order to help the compiler get its shit together was far outpaced by the number of things which just needed to be simplified.
from ios-handbook.
worth a try π
from ios-handbook.
Related Issues (20)
- Things to re-evaluate HOT 2
- Add guidelines for view method names HOT 1
- New project checklist
- Add steps to make a multi-platform Carthage framework HOT 2
- Order of code in classes HOT 4
- Error handling best practices HOT 1
- Switching to Realm HOT 20
- Document defaulting new project to Carthage HOT 5
- Guideline for static tables HOT 16
- Formalize method to add subviews and constraints HOT 1
- Swifty delegates HOT 1
- Document why external testers vs internal testers on TestFlight HOT 4
- Use UIKit's separators vs drawing our own separators HOT 1
- How do we agree on things? HOT 2
- Discourage usage of #imageLiteral and #colorLiteral HOT 3
- How do we do things HOT 1
- Guidelines for branch names HOT 1
- Checking dependency folder into git HOT 1
- Master Detail class name convention HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-handbook.