angular-styleguide icon indicating copy to clipboard operation
angular-styleguide copied to clipboard

Ambiguity on usage of named functions

Open remcohaszing opened this issue 8 years ago • 7 comments

In Y024 is stated that named functions should be used for callbacks.

However, in all the examples unnamed functions are passed when chaining promises. I must say using named functions in promise chaining make the control flow hard to follow from my experience.

Is Y024 only intended for defining Angular components? Because that's what the example shows.

remcohaszing avatar Feb 02 '16 12:02 remcohaszing

I agree that calling it callbacks is somewhat confusing.

Use named functions instead of passing an anonymous function in as a callback.

perhaps this line should instead be:

Use named functions instead of passing an anonymous function when registering something to a module.

zachlysobey avatar Feb 02 '16 15:02 zachlysobey

:+1: agree or just like this?

Use named functions instead of passing an anonymous function in as a callback.

sukrosono avatar Feb 02 '16 15:02 sukrosono

but it is a callback

johnpapa avatar Feb 02 '16 16:02 johnpapa

@remcohaszing Yes, named functions are recommended for most scenarios unless it is a 1 liner.

johnpapa avatar Feb 02 '16 16:02 johnpapa

To me, whether or not its a callback (which implies async unless I'm confused) under the hood isn't really something angular users need to know.

Totally acceptable as is IMO however.

zachlysobey avatar Feb 02 '16 16:02 zachlysobey

Named functions are easier to follow, if a name is chosen well. Because they then say what will be done. If you don't need to go deeper, you are not bothered with it, makes it way easier to go through a flow of code imho.

dietergeerts avatar Feb 02 '16 19:02 dietergeerts

The suggestions above are good ... anyone for a PR?

johnpapa avatar Sep 05 '16 18:09 johnpapa