Git Product home page Git Product logo

Comments (11)

JohnSundell avatar JohnSundell commented on May 20, 2024 2

Really interesting idea! πŸ€” But I agree with @vadymmarkov, it does make it a bit hard to find the API that you're looking for. It also reduces API discoverability and makes it harder to know where a method "comes from" when implemented. Finally, it would make our code not inline with Apple's naming conventions (if this is something that's important to us, which at least for Open Source, I personally think it should be) πŸ˜…

The nice thing about always using the class name as a prefix for the delegate method names is that things are crystal clear. There are also ways to make the APIs nicer without removing the prefix naming. In the example given in the first post func spotDidSelectItem(_ spot: Spotable, item: Item), we could make it nicer (and more "swifty"), by changing it to this:

func spot(_ spot: Spotable, itemSelected item: Item)

What do you guys think about that? πŸ˜„

from ios-foundation.

vadymmarkov avatar vadymmarkov commented on May 20, 2024

It will take time to get used to it, but I like the idea.

from ios-foundation.

onmyway133 avatar onmyway133 commented on May 20, 2024

This reads better. But I think you mean

func didSelect(item: Item, in spot: Spotable)

from ios-foundation.

zenangst avatar zenangst commented on May 20, 2024

@onmyway133 correct :) I'll fix it!

from ios-foundation.

vadymmarkov avatar vadymmarkov commented on May 20, 2024

Not sure about barcode scanner for example. Now we have this:

public protocol BarcodeScannerCodeDelegate: class {
  func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String)
}

public protocol BarcodeScannerDismissalDelegate: class {
  func barcodeScannerDidDismiss(_ controller: BarcodeScannerController)
}

Should it be changed to:

public protocol BarcodeScannerCodeDelegate: class {
  func didCapture(code: String, type: String, in controller: BarcodeScannerController)
}

public protocol BarcodeScannerDismissalDelegate: class {
  func didDismiss(controller: BarcodeScannerController)
}

func didDismiss(controller: BarcodeScannerController) could cause conflicts:
screen shot 2016-10-07 at 15 55 40

from ios-foundation.

zenangst avatar zenangst commented on May 20, 2024

Oh I see, can you change the label to call it something else than controller would that help?

public protocol BarcodeScannerDismissalDelegate: class {
  func didDismiss(barcodeScanner: BarcodeScannerController)
}

from ios-foundation.

vadymmarkov avatar vadymmarkov commented on May 20, 2024

@zenangst It will solve the problem, but I still find this naming a bit confusing. For example:

// Old way:

protocol AdminHeaderViewDelegate: class {
  func adminHeaderViewDidExpand(_ adminHeaderView: AdminHeaderView)
}

delegate?.adminHeaderViewDidExpand(self)

// New way, option 1:

protocol AdminHeaderViewDelegate: class {
  func didExpand(adminHeaderView: AdminHeaderView)
}

delegate?.didExpand(adminHeaderView: self)

// New way, option 2
// Those 2 delegate methods make more sense, but are conflicting for compiler:

protocol AdminHeaderViewDelegate: class {
  func didExpand(in adminHeaderView: AdminHeaderView)
}

protocol AdminFooterViewDelegate: class {
  func didExpand(in adminFooterView: AdminFooterView)
}

Also when I type did in the controller I get a lot of methods not really related to delegates or to my AdminHeaderViewDelegate specifically:

screen shot 2016-10-13 at 11 03 23

from ios-foundation.

RamonGilabert avatar RamonGilabert commented on May 20, 2024

I like New way, option 1, I don't need the in label in this case.

from ios-foundation.

vadymmarkov avatar vadymmarkov commented on May 20, 2024

Also in the example above it's AdminHeaderView who makes an action, not the delegate which is more like observer. So as for me it makes more sense to have adminHeaderView prefix in delegate function names.

from ios-foundation.

zenangst avatar zenangst commented on May 20, 2024

I like this, we should update the public API's for frameworks such as Spots to be more scope with relevant prefixes. I guess that could go into the 6.0.0 release. What do you guys think?

from ios-foundation.

zenangst avatar zenangst commented on May 20, 2024

The methods in question here ended up looking like this:

func spotable(_ spot: Spotable, itemSelected item: Item)
func spotablesDidChange(_ spots: [Spotable])
func spotable(_ spot: Spotable, willDisplay view: SpotView, item: Item)
func spotable(_ spot: Spotable, didEndDisplaying view: SpotView, item: Item)

from ios-foundation.

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.