Code Monkey home page Code Monkey logo

Comments (7)

gregheo avatar gregheo commented on May 29, 2024

Those are the same – Type[] is syntactic sugar for Array<Type>.

I think we should go with Type[] in the same way we write Int? rather than Optional<Int>. Arrays and optionals are so common that there are these (IMHO) readable and understandable shortcuts; we should use them!

from swift-style-guide.

icanzilb avatar icanzilb commented on May 29, 2024

Yes - syntax sugar is there for a purpose - we should use it.

from swift-style-guide.

rwenderlich avatar rwenderlich commented on May 29, 2024

Yeah the Apple book says to prefer using the Type[] variant: "Although the two forms are functionally identical, the shorthand form is preferred, and is used throughout this guide when referring to the type of an array.”

from swift-style-guide.

jackwu95 avatar jackwu95 commented on May 29, 2024

Very good points, I think the parallel between this and Int? vs Optional<Int> is enough to end the discussion. Type[] is definitely the way to go!

from swift-style-guide.

gregheo avatar gregheo commented on May 29, 2024

Just added this in 9932802. Thanks!

Of course, I had to say [Type] rather than Type[] now. ;]

from swift-style-guide.

jackwu95 avatar jackwu95 commented on May 29, 2024

Yep :] I think with the addition of the Dictionary sugar it makes even more sense to add a section on it. [Type] looks soooo weird to me though...hope I'll get used to it soon!

from swift-style-guide.

gregheo avatar gregheo commented on May 29, 2024

The C++ style Foo<Bar> is very familiar but I think I can see myself getting used to the new Swift style. I do like how the type declaration "looks like" the literal itself, which helps.

from swift-style-guide.

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.