Happenn
  • Introduction
  • System Architect
  • For Dev
    • AWS
      • Domain & CNAME
      • Rescale Instance
      • Request AWS Certificate
      • Generate Certificate with Certbot
      • S3
      • SSH & FTP
      • Auto Scaling
      • RDS MySQL
    • Digital Ocean
      • Virtual Host & Certificate
      • SSH & FTP
    • Server
      • Git
      • Setup the Server
    • Code
      • Laravel/Lumen
      • Vue.js
      • Webpack
      • JavaScript Library
        • Lodash
        • axios
        • Moment.js
      • Code Style Guide
      • Useful Tools
    • HAM Admin
      • Install locally
      • Deploy
    • Happenn API
      • Install locally
      • Install DB locally
      • Make DB changes
    • Happenn IO
      • Install locally
    • Happenn Virtual
      • Install locally
      • Folders and file structure
      • Deploy code
        • Happenn AWS
        • Delegia AWS
    • Happenn Event app
      • Deploy
      • Install locally
Powered by GitBook
On this page
  • General
  • Tab
  • Variable Name
  • Method Name
  • PHP
  • Overall
  • Array
  • String
  • Function
  • HTML
  • PUG
  • Blade Template
  • Javascript
  • Vue.js
  • CSS/SCSS
  • MySQL
  1. For Dev
  2. Code

Code Style Guide

The code style guide for all the programming languages that has been used on all of our applications.

PreviousMoment.jsNextUseful Tools

Last updated 4 years ago

General

Tab

1 tab = 2 indents

Variable Name

  • Use Snake case.

  • Start with lower and separate with underscore. Example, user_firstname.

  • The reason, is to make the variable name clear and can just glance at it to know for the variable is use for or belong to then using camel case.

  • There is some exception in Vue.js due to the framework.

Method Name

  • Use Camel case.

  • Always name it in vert, adverb, or start with these two.

  • If the method return a view such as from the Laravel Controller. It should be the view name instead.

PHP

Overall

<?php

use Illuminate\Routing\Controller;

class ExampleController extends Controller {
  private $foo = 'bar';
  
  public function index (Request $request) {
    $array = [];
    $abc = $def ?? 'World';
    
    $text_1 = "Hello $def";
    $text_2 = "Foo {$this->bar}";
    
    return reseponse([
      'text_1' => $text_1,
      'text_2' => $text_2
    ], 200);
  }
}

Array

<?php

$foo = ['abc', 'def'];
$bar = [
  'a' => 'b',
  'c' => 'd',
  'e' => 'f'
];
  • Always use brackets for array. Do not use array().

  • Always space after a comma.

  • If need a new line, comma need to be at the end of the above line, not in front.

  • No space before comma.

  • No left comma on array.

  • If the string is too long, the next value should start in new line.

String

<?php

class Example {
  public $bar = 'World';
  
  function hello () {
    $foo = 'world';
    
    echo "Hello $foo";
    echo "Hello {$this->bar}";
  }
}
  • If it's only a text string, you single quote.

  • If the string contain a variable, use double quote instead so it is possible to place variable inside the string without dot for concat.

  • The curly bracket can be used instead if the variables are put together without space.

Function

<?php

$foo = function printString ($str) {
  echo "Hello $str";
}
  • Always a space between function name and parameter.

  • Always a space between parameter and an open curly bracket.

HTML

PUG

Blade Template

Javascript

Vue.js

CSS/SCSS

MySQL

VS Code preference example