Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular style guide may conflict with regard to capitalization #2

Open
marcusreese opened this issue Sep 5, 2017 · 2 comments
Open

Comments

@marcusreese
Copy link

Here is a snippet from your guide and then a snippet from Angular's guide. Angular seems to "prefer" lowerCamelCase over UPPER_CASE.

ngrx-styleguide:

naming actions (for state)

Note: look at actions for side effects here
DO name actions with a unique name and captial letters - VERB + NOUN.
DO name actions values with - Prefix + VERB + NOUN.
Why?: it's readable.
Why?: actions can be filtered and viewed in redux dev tool easily.
Why?: uniqueness is for making sure only one reducer handles the action.

const UPDATE_FILTER = '[PlayerSearch] UPDATE_FILTER';
const ADD_RESULTS = '[PlayerSearch] ADD_RESULTS';

https://angular.io/guide/styleguide#constants says:

Consider spelling const variables in lower camel case.

Why? Lower camel case variable names (heroRoutes) are easier to read and understand than the traditional UPPER_SNAKE_CASE names (HERO_ROUTES).

Why? The tradition of naming constants in UPPER_SNAKE_CASE reflects an era before the modern IDEs that quickly reveal the const declaration. TypeScript prevents accidental reassignment.

Do tolerate existing const variables that are spelled in UPPER_SNAKE_CASE.

Why? The tradition of UPPER_SNAKE_CASE remains popular and pervasive, especially in third party modules. It is rarely worth the effort to change them at the risk of breaking existing code and documentation.

app/shared/data.service.ts
content_copy
export const mockHeroes = ['Sam', 'Jill']; // prefer
export const heroesUrl = 'api/heroes'; // prefer
export const VILLAINS_URL = 'api/villains'; // tolerate

Also, there is an interesting comment at reduxjs/redux#1097 from the creator of Redux:

Please use any style you consider appropriate. There's nothing particularly "right" about the style we use in docs. We always discuss important parts (such as reducer purity). The rest is up to you.

Would you agree, based on this information, that we should use lowerCamelCase for our exported action variables?

@orizens
Copy link
Owner

orizens commented Sep 25, 2017

hi @marcusreese
By the Angular styleguide, "Do tolerate existing const variables that are spelled in UPPER_SNAKE_CASE..."
I think it's more readable to distinguish when skimming the code.
Also, the ngrx-example app uses the same convention - so i would like to somehow follow this one as well.

@orizens
Copy link
Owner

orizens commented Jun 24, 2020

should switch to the new createAction with recommendations for action types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants