Coder Social home page Coder Social logo

Comments (19)

3lvis avatar 3lvis commented on August 19, 2024

We should check for slowly compiled methods before doing something about them.
http://khanlou.com/2016/12/guarding-against-long-compiles

from ios-handbook.

3lvis avatar 3lvis commented on August 19, 2024

Basically, you mean:

let percentage: Double = 10

Instead of:

let percentage = Double(10)

from ios-handbook.

elland avatar elland commented on August 19, 2024

πŸ‘

also not:

let percetange = 10 as Double

from ios-handbook.

3lvis avatar 3lvis commented on August 19, 2024

We don't do that one, though.

from ios-handbook.

elland avatar elland commented on August 19, 2024

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.

elland avatar elland commented on August 19, 2024

So yeah, nevermind the as Double.

from ios-handbook.

3lvis avatar 3lvis commented on August 19, 2024

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.

elland avatar elland commented on August 19, 2024

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.

3lvis avatar 3lvis commented on August 19, 2024

Only where type can't be correctly inferred.

let percentage = Double(10)

What's incorrect about this?

from ios-handbook.

elland avatar elland commented on August 19, 2024

Nothing, it's just become inconsistent with the rest as we adopt type annotation instead. πŸ‘

from ios-handbook.

3lvis avatar 3lvis commented on August 19, 2024

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.

3lvis avatar 3lvis commented on August 19, 2024

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.

elland avatar elland commented on August 19, 2024

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.

3lvis avatar 3lvis commented on August 19, 2024

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.

elland avatar elland commented on August 19, 2024

But this doesn't change. It's still the same. πŸ€”

from ios-handbook.

designatednerd avatar designatednerd commented on August 19, 2024

@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.

elland avatar elland commented on August 19, 2024

@designatednerd do we have numbers on that? πŸ‘

from ios-handbook.

designatednerd avatar designatednerd commented on August 19, 2024

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.

elland avatar elland commented on August 19, 2024

worth a try πŸ‘

from ios-handbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.