-- Nobody
Apply tricks learned from
https://github.com/GoogleChrome/udacity-60fps-samples
This famous quote by Sir Tony Hoare (popularized by Donald Knuth)
-- Martin Fowler
const arr = [1, 2, 3];
let len = arr.length;
const output = [];
while(len--) {
output[len] = `string ${arr[len]}`;
}
// vs
const output = arr.map(e => `string ${e}`);
Would I JSPerf this, and use while from now on?
(Everything is invented here)
if (isHappy) {
dance();
} else {
cry();
}
over9000 powerLevel =
let
shout =
if powerLevel > 9000 then
"It's over 9000!!!"
else "meh"
in
shout
1 + 2 + "";
// vs
1 + "" + 2;
module Main exposing (..)
import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
-- These type annotations are totally optional
-- because Elm automatically infers the types,
-- but they are really useful, just to make sure
-- that your function matches the expected signature.
main : App.Program Never
main =
App.beginnerProgram { model = model, view = view, update = update }
-- MODEL
-- Type alias is somewhat similar to an interface in TS,
-- but in addition to that defining a type alias will create
-- a constructor.
type alias Model = Int
model : Model
model =
0
-- UPDATE
type Msg = Increment | Decrement -- Union types
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]