Skip to content

streemau/styleguides

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Streem coding style guides

Philosophy

Code is not about telling the computer what to do, it's about explaining to other humans what you want the computer to do.

Clear is better than clever

Every line of code is a liability

No code is faster to understand/run than no code

Make it work. Make it right. Make it fast. (in that order)

General guidelines

In order to limit cognitive overhead prefer:

  • Short classes and methods with single responsibility
  • Long descriptive variable & method names
  • Comments to explain "why" something is done, not "how", when necessary (i.e. uncommon business rule, specific magic value...)
  • Several smaller PRs instead of one big PR: short_vs_long_code_reviews

When reviewing your own code or someone else's, ask yourself:

  • Does this do what we want?
  • Is the code easy to understand and follow with meaningful names?
  • Is it the simplest solution to achieve the outcome?
  • Are there end-to-end tests for the happy paths and unit tests for all variations?
  • Are the tests testing the right things and only stubbing what is absolutely needed?
  • Is there any potential edge case or expected failure?
  • Is there any internal/external performance risk?
  • Is it working with or affecting all production environments (AU/UK)?

Common backend app structure

MVC + actions + jobs + services + workers

  • Actions receive & validate user input that create/update records, with any related business logic.
  • Job have a single purpose with a clear start and end, usually asynchronous and ideally idempotent.
  • Services encapsulate complex logic or external calls that can be used in multiple places, usually jobs and actions.
  • Workers are long running processes listening for events, usually triggering relevant job in response.

Front end structure, rules and guidelines

To keep the code clean, consistent and well understood across all projects, we should follow the conventions, rules and guidelines below, in addition to the rules and conventions specified by the linting rules and generally those adopted by the language or framework/s.

General conventions As we use Vue for the frontend in our applications, it is a good idea to adhere and follow the official Vue Style Guide.

Component Naming Conventions:

Page Naming Conventions:

  • page components should be prefixed with the resource they refer to
    • OrganisationsTable, BriefGroupForm
  • for pages that list content for a resource, suffix pages with List
    • OrganisationsList, BriefGroupsList
  • we should use the same page component when building create/edit pages, and the resource should be singular and suffixed with Edit
    • OrganisationEdit, BriefGroupEdit
  • for pages that list a singular resource, suffix pages with View
    • OrganisationView, BriefGroupView
  • for routes that are nested, like the organisation tabs components, we should follow the tightly coupled naming rule for components based on the page component it is nested under
    • OrganisationBriefsList, OrganisationBrandingProfilesList
  • avoid nested levels of folders
    • the components will be grouped well, easily discoverable and forces developers to give descriptive names when following the naming conventions

Routing Conventions

  • routes should be prefixed with the resource they refer to
    • /radio-stations/1/edit
  • index pages should simply route to the base page of the resource
    • /radio-stations
  • displaying the details of a singular resource should simply route to the base of the resource suffixed with an id
    • /radio-stations/1
  • creation pages should be suffixed with /new
    • /radio-stations/new
  • edit pages should be suffixed with edit
    • /radio-stations/1/edit
  • the name given to each route should be prefixed with the resource, using dashes instead of underscores, and should contain the action of what they do
    • radio-stations-list, radio-stations-show, radio-stations-new, radio-stations-edit
  • nested routes should follow the naming conventions above
  • avoid route name nesting unless it is a requirement of the page to function, or it is also nested in the backend
  • for any page that isn't covered by the rules above, it should always be prefixed with the resource(s) they refer to and include the action they refer to
    • articles/bulk-search, articles-bulk-search

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •