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

DOC Update coding conventions #397

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Nov 6, 2023

Issue #323

Right now it requires some discussion with @silverstripe/core-team to see everyone's happy with the conventions that I've added in < This has been done

This PR will only focus on PHP. I've spun off a separate card for JS + SCSS

@michalkleiner
Copy link
Contributor

👍 Generally agree with all the proposed additions. It'd be great to have linter/phpcs/PhpStan rules for as many of these as possible.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some stuff here that seems like a duplication of the stuff below your additions - what's the intention there? Will you be removing all the old standards? Will you do a de-dupe separately? Or are the duplications not intended?

I'll hold off reviewing the existing standards until you've answered this.

I also assume that the other language coding standards have yet to be done.

Copy link
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly feel strongly about trying to ratify member visibility, as some may remember from silverstripe/silverstripe-framework#8996.

Copy link
Contributor

@maxime-rainville maxime-rainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of good stuff in there!!!

I would make the following assumptions explicit once and avoid repeating them over and over:

  • Best practices are approaches that will work well in most situations.
  • It's OK to occasionally ignore them. (Maybe we want to have two classes ... the ones that are nice to have but not so important ... and the ones that should only be ignored as a last results)
  • Best practices have not always been systematically applied, so you will encounter instances where they are not followed.

In term of language, I would be inclined to try to normalise it and avoid complicated dissertation. Maybe remove in-depth explanation of why we think something is a good.

I would focus on using the words "avoid" or "prefer" in most places. Maybe avoid using expression like "where possible" or "if practical".

Some extra questions we might want to address:

  • Do we prefer Promises or Async/Await in JS?
  • Prefer using the ORM instead of raw SQL.
  • Prefer DataObjectSchema::tableName() to get the table name for DataObject rather then hardcode the value.
  • Prefer generic/standard SQL syntax that work across all DataBase.

@ScopeyNZ
Copy link
Contributor

ScopeyNZ commented Nov 10, 2023

Do we prefer Promises or Async/Await in JS?

I'm against mentioning a preference here. They have different use-cases. Both are situational, and may even be used together, eg:

const thing = await fetch('url').then(response => response.json());

Prefer DataObjectSchema::tableName() to get the table name for DataObject rather then hardcode the value.

This should be a rule (at least it was when I was last peer-reviewing 😅 )

@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch 2 times, most recently from 205bb53 to 40b1e83 Compare November 13, 2023 03:33
@emteknetnz emteknetnz marked this pull request as ready for review November 13, 2023 03:34
@emteknetnz
Copy link
Member Author

emteknetnz commented Nov 13, 2023

Have made recommended edits. Have also updated the content that was previously on the page and either made it much more concise or removed. Ready for review again

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxime-rainville in #397 (review) you said

Maybe avoid using expression like "where possible" or "if practical".

There's still some of that in here so you may want to look and see if you're okay with the way that language has been used in the new revision.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emteknetnz emteknetnz force-pushed the pulls/5/code-standards branch 2 times, most recently from b7d6716 to d5fb128 Compare November 14, 2023 02:31
@GuySartorelli
Copy link
Member

@maxime-rainville here are the specific things you need to double check:

Copy link
Contributor

@maxime-rainville maxime-rainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe avoid using expression like "where possible" or "if practical".

There's still some of that in here so you may want to look and see if you're okay with the way that language has been used in the new revision.

I had a glance and didn't see anything obviously standing out. By general point was that "where possible" or "if practical" is kind of implied when drafting best practices.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No outstanding requested changes.

@GuySartorelli GuySartorelli merged commit a80f184 into silverstripe:5 Nov 26, 2023
@GuySartorelli GuySartorelli deleted the pulls/5/code-standards branch November 26, 2023 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants