@pawel_lewtak
Developer @ GOG.com
"There are only two hard things in Computer Science: cache invalidation and naming things."
Phil Karlton
"There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors"
Leon Bambrick
"Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do."
Donald E. Knuth
Source: Literate Programming, 1983
function a($b) {
sort($b);
$c = count($b);
if ($c % 2 === 1) {
return $b[($c - 1) / 2];
} else {
return ($b[$c/2 - 1] + $b[$c/2]) / 2;
}
}
function median($pool) {
sort($pool);
$size = count($pool);
if ($size % 2 === 1) {
return $pool[($size - 1] / 2];
} else {
return ($pool[$size/2 - 1] + $pool[$size/2]) / 2;
}
}
$total = $price * $qty;
$total2 = $total - $discount;
$total2 += $total * $taxrate;
$total3 = $purchase_order_value + $available_credit;
if ($total2 < $total3) {
echo "You can't afford this order.";
}
$order_total = $price * $qty
$payable_total = $order_total - $discount
$payable_total += $payable_total * $taxrate
$available_funds = $purchase_order_value + $availble_credit
if ($payable_total < $available_funds) {
echo "You can't afford this order.";
}
"No-one sets out to write legacy code"
Rachel Willmer
Misapplied Java design patterns
are the root of all AbstractWordFactoryFactory("evil")
HN comment
with extra operations inside
function is_active() {
if (cond) {
return 'false';
}
return 'true';
}
function is_valid() {
if (input_is_valid) {
return true;
}
}
function get_person() {
return ['John Doe', 'Jane Doe'];
}
function get_employers() {
return 'John Doe';
}
function get_lowest_price($user) {}
/**
* Actually it returns the highest price.
*/
function get_lowest_price($user) {}
/**
* Actually it returns the highest price.
*/
function get_lowest_price($user) {
if ($user === null) {
return _get_highest_price();
} else {
return _get_lowest_price($user);
}
}
pos
mod
abs
auth
$client = new GuzzleHttp\Client();
$url = 'https://conference.phpbenelux.eu/';
$response = $client->request('GET', $url);
$response_code = $response->getStatusCode();
if ($response_code === 200) {
echo 'It works!';
} elseif ($response_code === 418) {
echo 'What is that?!';
}
$client = new GuzzleHttp\Client();
$url = 'https://conference.phpbenelux.eu/';
$response = $client->request('GET', $url);
$response_code = $response->getStatusCode();
if ($response_code === StatusCode::OK) {
echo 'It works!';
} elseif ($response_code === StatusCode::IM_A_TEAPOT) {
echo 'Website down. Would like a cup of tea instead?';
}
/**
* Returns the data.
*/
function get_data() {}
/**
* Return maximum ID value from the database.
*/
function get_max_id_from_db() {}
"Code should have comments, but if your file is more than 25% comments, that's a red flag: you may be explaining bad code"
Adam Culp
$Δ = 1;
++$Δ;
echo $Δ;
class 💩💩💩💩 {
function 💩💩💩($😎, $🐯) {
return $😎 + $🐯;
}
}
$🐔 = 3;
$😥 = $🐔 + 2;
$💩 = new 💩💩💩💩;
echo $💩 -> 💩💩💩($🐔, $😥);
hostList, hostSet => hosts, validHosts
valueString => firstName, lowercasedSKU
intNumber => accountNumber
Speeds up review process
Helps write release notes
Helps future maintainers
Short (50 chars or less) summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded by a
single space, with blank lines in between, but conventions vary here
Source: Source: http://git-scm.com/book/ch5-2.html
Short, bite size, single logical change