Code Monkey home page Code Monkey logo

Comments (9)

 avatar commented on June 11, 2024

Definitely do away with prefixes. Apple seems to be encouraging this as well.

However, probably let's not name any classes UIButton. ;)

--------- Original Message --------- Subject: [swift-style-guide] Class prefixes (#13)
From: "Matthijs Hollemans" [email protected]
Date: 6/10/14 1:31 pm
To: "raywenderlich/swift-style-guide" [email protected]

Because you get an automatic namespace that is named after your project, I vote that we drop the requirement of having an RWT / SKT / whatever prefix for class names and global constants.
If there is a naming conflict with a built-in symbol, you can always prefix with the name of the framework (or your project) to disambiguate.
Silly example:
class UIButton { ... } // this is now allowed (but not a good idea) let myButton1 = UIButton(...) let myButton2 = UIKit.UIButton(...) // get the one from UIKit let whatever = Swift.Array() -
Reply to this email directly or view it on GitHub.

from swift-style-guide.

cwagdev avatar cwagdev commented on June 11, 2024

👍 👍 Kill the prefix!

I think a prefix would confuse me and make me think I am working with an ObjC class.

from swift-style-guide.

ecerney avatar ecerney commented on June 11, 2024

👍 Plus prefixes are dumb when I want to reuse classes between multiple projects and I have to change the file names :)

from swift-style-guide.

hollance avatar hollance commented on June 11, 2024

Also, when you need Obj-C interoperability, you can do:

@objc (RWTMonster) class Monster { ... }

In Obj-C the class will have the name RWTMonster.

EDIT: To clarify, in your source code it will still be called Monster but during runtime it's called RWTMonster. Freaky! (And even if you don't specify a name, the class will automatically get a mangled runtime name to avoid namespace collisions.)

from swift-style-guide.

jackwu95 avatar jackwu95 commented on June 11, 2024

Since we will be writing both Swift and ObjC we should definitely use the @objc tag for all classes so no one gets lost between Swift & ObjC.

from swift-style-guide.

edekhayser avatar edekhayser commented on June 11, 2024

Prefixes seem to have been abandoned in Swift, and I agree that our classes should not be prefixed. However, not for some of the reasons people are saying.

Namespaces is why we should not have prefixes, I agree. I just do not like the argument, "it seems like Apple wants it this way." If out style guide is exactly how Apple is pushing Swift, then there is no point in having a style guide. We can deviate from Apple's suggested formatting for our own reasons and purposes.

from swift-style-guide.

 avatar commented on June 11, 2024

Our style guide is meant for one thing: making sure we all agree on the way we write code so that the books (primarily) and tutorials (secondarily) look consistent. Whenever in doubt, do what Apple does, because that makes our code consistent with their code, which is the other place most people will encounter Swift.

We can definitely do things other than what Apple does, but we should have a really good reason for doing it.

--------- Original Message --------- Subject: Re: [swift-style-guide] Class prefixes (#13)
From: "Evan Dekhayser" [email protected]
Date: 6/10/14 7:15 pm
To: "raywenderlich/swift-style-guide" [email protected]
Cc: "elephantronic" [email protected]

Prefixes seem to have been abandoned in Swift, and I agree that our classes should not be prefixed. However, not for some of the reasons people are saying.
Namespaces is why we should not have prefixes, I agree. I just do not like the argument, "it seems like Apple wants it this way." If out style guide is exactly how Apple is pushing Swift, then there is no point in having a style guide. We can deviate from Apple's suggested formatting for our own reasons and purposes.

Reply to this email directly or view it on GitHub.

from swift-style-guide.

moayes avatar moayes commented on June 11, 2024

+1 for no class prefix in Swift-only code - i.e. class Monster { ... } but +1 to maintain the convention for those classes that are going to be exposed to ObjC - i.e. @objc (RWTMonster) class Monster { ... }.

from swift-style-guide.

 avatar commented on June 11, 2024

I agree that when exposing our classes to Obj-C, we should use a prefix.

However, will we be exposing any classes to Obj-C? Other than maybe in a chapter or tutorial that is specifically design to show how to use Swift code from Obj-C code, will any projects we deliver mix the two?

--------- Original Message --------- Subject: Re: [swift-style-guide] Class prefixes (#13)
From: "Soheil Moayedi Azarpour" [email protected]
Date: 6/10/14 10:05 pm
To: "raywenderlich/swift-style-guide" [email protected]
Cc: "elephantronic" [email protected]

+1 for no class prefix in Swift-only code - i.e. class Monster { ... } but +1 to maintain the convention for those classes that are going to be exposed to ObjC - i.e. @objc (RWTMonster) class Monster { ... }.

Reply to this email directly or view it on GitHub.

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.