Skip to content

Instantly share code, notes, and snippets.

Avatar

mcsee mcsee

View GitHub Profile
View polymorphic.php
<?
class Array {
public function sort() {
}
}
class List {
public function sort() {
}
View semanticDifferent.php
<?
class Array {
public function arraySort() {
}
}
class List {
public function listSort() {
}
View failFast.php
<?
new Date(31,02,2020)
//Throw an exception
1 + 'Hello'
//Type Mismatch
!3
//Negating is a boolean operation
View smarty.php
<?
new Date(31,02,2020)
1 + 'Hello'
!3
//Valid on most languages
View composition.java
Abstract class Collection {
public abstract int size();
}
final class Stack extendes Collection {
private contents[] ArrayList;
public Stack() {
contents = new long[maxSize];
View subclassification.java
class Stack extends ArrayList {
public void push(Object value) { … }
public Object pop() { … }
}
//Stack does not behave Like an ArrayList
//besides pop, push, top it also implements (or overrides) get, set, add, remove and clear
//stack elements can be arbitrary accessed
//both classes are concrete
View strict.js
array = [];
console.log(array['1'])
//Index Error
noGlobal = "I am not a global"
console.log(noGlobal)
// ReferenceError
var noGlobal = "I am not a global"
View warnings.js
array = [];
console.log(array['1'])
//undefined but keep going on
hiddenGlobal = "I am a global"
console.log(hiddenGlobal)
// I'm a global
View smart.pl
val regex = Regex("^\\+(?:[0-9a-zA-Z][– -]?){6,14}[0-9a-zA-Z]$")
View declarative.pl
val prefix = "\\+"
val digit = "[0-9a-zA-Z]"
val space = "[– -]"
val phoneRegex = Regex("^$prefix(?:$digit$space?){6,14}$digit$")
You can’t perform that action at this time.