ThinkHTML Notes and stuff

Data

most data in life is partial data

Program

Styles

Buttons (different levels)
Spinners
Tooltips (different levels)
Tabs (different levels)
Nav

URL

Auto-negotiate headers

Language: en, es, ru
Content-type: xml, html, json
mobile not mobile???
Cookie sharing?
http://searchengineland.com/the-ultimate-guide-to-multilingual-and-multiregional-seo-157838
http://en.wikipedia.org/wiki/Country_code_top-level_domain

http://example.co.uk (with United Kingdom locale)
http://es.example.co.uk (with United Kingdom locale but in spanish, top level domain adds complexity)
http://au.example.com (Australian geotargeting, bad idea since the country can have more than one language)

Sections

Section content

Content-type

Sub-sites

Languages

Locale

Notes: http://example.com redirects to http://www.example.com for control over cookies
http://www.example.com/section/item-id has canonical link to http://www.example.com/section/item-id.html
Dots are forbidden in URL slugs to avoid confusion with extensions

A resource can have many languages, locales, formats. To specify them we use "en", "en-US", ".json"

Normally: - Locale is example.de (has many tecnical limitations, use de.example.com instead) - Language is es.example.de (has some tecnical limitations, use de.example.com/es/ or example.com/es-DE/ instead) - Format is es.example.de/page.xml (has minor tecnical limitations, use normally)

Subdomains handle sub-site and language

. (redirects to www. to not send cookies to all subdomains)
www.
static. (redirects to en.static to not send cookies to all subdomains)
en.static. (gets cookies from static.)
en.www. (Do not use, gets cookies from www.)
en.
en-GB.?
en-US.?

(http://example.com/en-US/ seems like so much simpler...)

Auto negotiate content version (Redirects to a specific version to give control of cookies with subdomains)

Web version

Alternative sites

Query

Hash

CDN??

Summary

Program

Language comparison

nouns = variables verbs = functions adjectives?

fox jumps over dog

radialSwapXAxis($fox, $dog, array('radius'=>'1m')); // anything can jump over anything, even in zero gravity
$fox->jumpOver($dog); // here only a fox can jump over things, does not make sense

Good way to name functions (functions are verbs in languages)

function actionVerb(subject, options){}

This keeps the number of variables to a minimum number, which helps reduce confusion to which variable

// bad (you have no clue what each argument does)
action(true, true, true);

// bad (ignoring legacy software, forces people to rewrite their code to use new function)
action($subject, $opt1, $opt2, $opt3, $opt4); // old function
action($subject, $opt3, $opt4); // new function

// bad (supporting legacy, forces people using new function to add empty params, like in wordpress)
action($subject, $opt1, $opt2, $opt3, $opt4); // old function
action($subject, null, null, $opt3, $opt4); // new function

//good
action($subject, array('compress'=>true, 'lossy'=>true));
action(array('compress'=>true, 'use-enviroment'=>true, 'lossy'=>true)); // old function
action(array('compress'=>true, 'lossy'=>true)); // new function

Objects create context for functions and variables,

// Asynchronous Transfer Mode
IT::atm();
// Automated teller machine
Bank::atm();
// At the moment
Teen::atm();

Even class variables (called properties, similar to adjectives) can have different values / meaning depending on the context

Apple::$red; // red
Fox::$red; // brown-red

Objects can carry context in instances that can be configured at runtime

$it = new Abbreviations('IT');
$it->atm();

$bank = new Abbreviations('Bank');
$bank->atm();

$teen = new Abbreviations('Teen');
$teen->atm();

good for config carriers or other object wrapping.
just like variables "instances" are also things, except they are defined at compile time
Just like real languages, this allows us to have "assumed" defaults for verbs and nouns

class Context {
    function jacked($subject, $things){

    }
}
$context = new Context(array('it'=>"John's hidden stash", 'them'=>'Collection of coins', 'everything'=>array("John's clothing","John's house")));
$context->jacked($someone, array('it', 'them', 'everything'));

Although you can do the same with variables

$it = "John's hidden stash";
getStolen($it);

But it is harder to carry over large amounts of definitions, while with an array it is easier, but arrays don't carry functions (verbs) very well in PHP
In javascript, objects are fine to carry context (variables and functions)

Prefer composition over inheritance (interfaces are still good)

With extending

No class names in code that works after everything was defined (Find out the name for this type of code)

// add middleware (Classes mentioned, direct dependencies)
$req->db = new Connection($options);
$req->html = new HTML5Parser$options);
$req->img = new ImageGD($options);

// use middleware (No classes mentioned)
$req->db->query($sql);
$req->html->parse($html);
$req->img->convert($file);

Constructors must be minimal and not do processing, especially if it can fail (functions are for processing, constructors are for config)

// bad
class ImageObject {
    var $gd;
    function __construct($img_file){
        $this->gd = imagecreatefromstring($img_file);
    }
    function crop(){
        imageresample($this->gd);
    }
}
// good
class ImageConverter {
    var $options = array();
    function __construct($options){
        $this->options = array_merge($this->options, $options);
    }
    function convertGD($img_gd, $options=array()){
        $o = array_merge($this->options, $options);
        $w = imagesx($img_gd);
        $h = imagesy($img_gd);
        $img = imagecreatetruecolor($s['dst_w'],$s['dst_h']);
        $img = imagecopyresampled($img, $img_gd, 0, 0, 0, 0, $o['width'], $o['height'], $w, $h);
        return new ImageGD($img);
    }
    function convertString($img_str, $options=array()){
        return $this->convertGD(imagecreatefromstring($img_str), $options);
    }
    function convertFile($img_file, $options){
        return $this->convertString(file_get_contents($img_file), $options);
    }
}
class ImageGD {
    var $gd;
    function __construct($gd){
        $this->gd = $gd;
    }
    function save($file, $options){
        return imagejpeg($this->gd, $file);
    }
}
// also good
function jQuery(selection){
    var self = this;
    selection.each(function(i, el){
        self[i] = el;
    });
}
var els = new jQuery(selection);

Wrappers

Wrapper classes (Decorators) add functions and data to other objects just make sure that they work with minimal data, preferably just the object or resource

Websites

Make services

Data service?

must work with minumum data given
the load functions job is the combine tables into views or to use views directly
it loads MANY views and leverages the combined abilities of the database and the server
externally you just request "tagged" content and filter it with filters

// $data[view_name][row_num][col_name] = value;
$data = $data_service->load($filter);

now that we have the data in an array format, we can format it into any shape that we want
format will convert it into a tree structure

$formatted_data = $data->format($xls);

this tree structure is sent to a template that wraps it with html