Skip to content

Instantly share code, notes, and snippets.

These examples are presented in an attempt to show how each coding styles attempts to or does not attempt to isolate side-effects. There are only 2 semantic elements in a barebone "Hello World" implementation:

  • Invocation of console.log
  • Declaration of HELLO_WORLD

Since every coding style can abstract away data into a parameter or variable, there is no point for us to show that. All implementations assume HELLO_WORLD is a constant that is always inlined. This way it reduces the variations we need to present. (To make an anology, if we were to implement incrementByOne, would we need to inline the number 1 or pass it in as parameter?)

CAVEAT/LIMITATION: All implementations also assume console is static. In case of OOP inheritance, Console is assumed to be extendable. In case of functional programming, console.log is asumed to be a function that can be passed around without further modification.

Declarative

@Usse
Usse / foodit.js
Last active August 29, 2015 14:20
//------- 1 --
var bar = 'hello world';
bar = function() {
return (function bar() {
return bar;
}());
}
//------- 2 --
@Usse
Usse / github-viewer.html
Last active August 29, 2015 14:15
Github viewer V0.1
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="[email protected]" data-semver="1.4.0-beta.4" src="https://code.angularjs.org/1.4.0-beta.4/angular.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.2/cosmo/bootstrap.min.css">
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
@Usse
Usse / data-binding-http-2.js
Last active August 29, 2015 14:15
Basic Angular Data binding
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="[email protected]" data-semver="1.4.0-beta.4" src="https://code.angularjs.org/1.4.0-beta.4/angular.js"></script>
<link href="style.css" rel="stylesheet" />
<script>
(function() {
var app = angular.module('app', []);
@Usse
Usse / revealing.js
Last active August 29, 2015 14:15
Revealing module pattern
(function() {
var createWorker = function() {
var workCount = 0;
var task1 = function() {
workCount += 1;
console.log('Doing task2 :' + workCount);
}
var task2 = function() {
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
* {
font-family: 'Open Sans', sans-serif;
}
@Usse
Usse / reddit-color.js
Created August 6, 2014 16:38
Reddit username color
var objUsers = {};
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
@Usse
Usse / .vimrc
Created July 28, 2014 07:16
.vimrc
" tabulazione a 2
"set ts=2 et
" gesture del mouse
set mouse=a
" numeri di linea
set number
" matching delle parentesi
@Usse
Usse / apache.conf
Created July 28, 2014 07:15
Basic Apache
<Directory "/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<virtualHost *:80>
Legend
C = ⌘ : Command key
Ct = ⌃ : Control key
Cr = ↩ : Return or Enter key
O = Option or Alt key
S = ⇧ : Shift key
D = ⌫ : Delete key
Dn = ↓ : Down arrow key
Up = ↑ : Up arrow key
Esc : Escape key