Some of the most important advancements in programming came from adding restrictions to the way we program.
Famous article by Edsger Dijkstra Go To Statement Considered Harmful
shows how introducing one statement into programming language breaks many nice properties of that language.
goto
gives us freedom and solves couple of simple problems like breaking from nested loops easily,
but it can make programs very hard to understand.
This happens, because we cannot look at two pieces of code in separation.
The execution can jump to some other place in code or even worse: it can jump from other piece of code to here and We need to keep that in mind.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- mode: emacs-lisp; lexical-binding: t -*- | |
;; This file is loaded by Spacemacs at startup. | |
;; It must be stored in your home directory. | |
(defun dotspacemacs/layers () | |
"Layer configuration: | |
This function should only modify configuration layer settings." | |
(setq-default | |
;; Base distribution to use. This is a layer contained in the directory | |
;; `+distribution'. For now available distributions are `spacemacs-base' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.Implementations do | |
def of(key) do | |
with impls when is_list(impls) <- Application.get_env(:app, :impls), | |
{:ok, module} <- Keyword.fetch(impls, key) do | |
module | |
else | |
:error -> | |
raise KeyError, | |
message: """ | |
:#{key} key is not defined in the implementations for application :app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Project.ActiveUsers do | |
@behaviour Project.UseCase | |
def run(params, deps) do | |
deps[:repo].fetch_users(params) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Event do | |
@type t() :: %__MODULE__{date: Date.t(), title: String.t(), content: String.t()} | |
defstruct :date, :title, :content | |
def group(events) do | |
events | |
|> Enum.group_by(fn event -> envent.date) | |
|> Map.to_list() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const glob = require('glob'); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const paths = { | |
static: path.join(__dirname, "../priv/static"), | |
build: path.join(__dirname, "../priv/static"), | |
node_modules: path.join(__dirname, "./node_modules"), |
- Create file on
.templates
folder at user home:mkdir ~/.templates/elixir && touch ~/.templates/elixir/module
- Contents:
defmodule {{mod}} do
end
Usage: bob -tpl elixir/module -d ./person.ex -v mod=Person
Templates are based on handlebars rendered by aymerick/raymond
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const devMode = process.env.NODE_ENV !== 'production' | |
module.exports = { | |
entry: './src/main/resources/assets/js/index.js', | |
output: { | |
filename: './js/index.js', | |
path: __dirname + '/src/main/resources/static/' | |
}, | |
module: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[33mwarn [0m Unable to automatically connect to build server. | |
[34minfo [0m running 'sbt metalsEnable bloopInstall' | |
[31merror[0m Getting org.scala-sbt sbt 1.2.1 (this may take some time)... | |
[34minfo [0m downloading https://repo1.maven.org/maven2/org/scala-sbt/sbt/1.2.1/sbt-1.2.1.jar ... | |
[34minfo [0m [SUCCESSFUL ] org.scala-sbt#sbt;1.2.1!sbt.jar (1216ms) | |
[34minfo [0m downloading https://repo1.maven.org/maven2/org/scala-sbt/main_2.12/1.2.1/main_2.12-1.2.1.jar ... | |
[34minfo [0m [SUCCESSFUL ] org.scala-sbt#main_2.12;1.2.1!main_2.12.jar (6509ms) | |
[34minfo [0m downloading https://repo1.maven.org/maven2/org/scala-sbt/logic_2.12/1.2.1/logic_2.12-1.2.1.jar ... | |
[34minfo [0m [SUCCESSFUL ] org.scala-sbt#logic_2.12;1.2.1!logic_2.12.jar (883ms) | |
[34minfo [0m downloading https://repo1.maven.org/maven2/org/scala-sbt/actions_2.12/1.2.1/actions_2.12-1.2.1.jar ... |