Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Not Writing PHP Makes You Better At PHP

How Not Writing PHP Makes You Better At PHP

Given at PHP Benelux 2015

Daniel Cousineau

January 24, 2015
Tweet

More Decks by Daniel Cousineau

Other Decks in Programming

Transcript

  1. HOW NOT WRITING PHP CAN MAKE YOU BETTER AT PHP

    View Slide

  2. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    @dcousineau

    View Slide

  3. @croscon

    View Slide

  4. View Slide

  5. HOW NOT WRITING PHP CAN MAKE YOU BETTER AT PHP

    View Slide

  6. HOW TO LIFEHACK YOUR WAY INTO LEARNING
    PROGRAMMING

    View Slide

  7. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Don’t do more work than you have to
    My middle school swim coach

    View Slide

  8. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    PROGRAMMING
    LANGUAGES

    View Slide

  9. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    TURING
    COMPLETE

    View Slide

  10. View Slide

  11. View Slide

  12. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    any real-world computation can be
    translated into an equivalent
    computation involving a Turing machine.
    CHURCH-TURING THESIS

    View Slide

  13. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM

    View Slide

  14. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Turing Complete

    View Slide

  15. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    THE LANGUAGE IS A MEANS TO AN END
    A WAY TO EXPRESS ABSTRACT THOUGHT

    View Slide

  16. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    THE LANGUAGE IS A MEANS TO AN END
    A WAY TO EXPRESS ABSTRACT THOUGHT
    ALGORITHMS

    View Slide

  17. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    EXPLANATION

    View Slide

  18. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    In the beginning, there was Assembly

    View Slide

  19. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    …and it was not good

    View Slide

  20. main:
    li $a0, 1
    li $a1, 2
    li $t0, 3
    jal addthem
    add $t0, $t0, $v0
    syscall
    addthem:
    addi $sp, $sp, -4
    sw $ra, 0($sp)
    add $v0, $a0, $a1
    lw $ra, 0($sp)
    addi $sp, $sp, 4
    jr $ra

    View Slide

  21. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    And then there was C

    View Slide

  22. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    int main() {
    int t0 = 3;
    int v0 = addthem(1, 2);
    return v0 + t0;
    }
    int addthem(int a0, int a1){
    int t0 = a0 + a1;
    return t0;
    }

    View Slide

  23. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    CONSTRUCT FUNCTION
    WHAT’S YOUR … FUNCTION

    View Slide

  24. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    function recurse() {
    recurse();
    }
    recurse();
    RangeError: Maximum call stack size exceeded.

    View Slide

  25. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    REPETITION=LEARNING

    View Slide

  26. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    http://bit.ly/bk-js
    Linguistic Relativity in
    Programming Langauges

    View Slide

  27. +
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    SAPIR-WHORF HYPOTHESIS
    The languages you speak determine the way you think

    View Slide

  28. +
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    SAPIR-WHORF HYPOTHESIS
    The languages you speak influence the way you think

    View Slide

  29. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Culture Language thought

    View Slide

  30. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Culture Language thought

    View Slide

  31. +
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    BLUB PARADOX
    “Some programming languages are more powerful
    than others… I look at [Python, Java, C and Perl].
    How can you get anything done in them, I think,
    without macros?”
    Paul Graham
    http://www.paulgraham.com/avg.html

    View Slide

  32. +
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    BLUB PARADOX
    “They're satisfied with whatever language they
    happen to use, because it dictates the way they
    think about programs.”
    Paul Graham
    http://www.paulgraham.com/avg.html

    View Slide

  33. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    IDIOMS

    View Slide

  34. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Combination of words in common use
    that have a figurative, and sometimes
    literal, meaning

    View Slide

  35. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    In this case, it was routed straight to the Director
    of Central Intelligence and, because it evidently
    discussed the identity of a field spook, to the
    Deputy Director (Operations), since all the field
    spooks worked for her. The former was a busier
    person than the latter, but that didn’t matter, since
    the latter was married to the former
    Tom Clancy, Rainbow Six

    View Slide

  36. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    What beliefs or what wrong could motivate a man
    to do murder on a large scale? In the former case,
    Brightling was not a religious fanatic. In the latter,
    he had no overt dissatisfaction with his country.
    Tom Clancy, Rainbow Six

    View Slide

  37. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    His last through before closing his eyes on this
    sunny morning was that he hoped the contact
    number hadn’t been changed, or compromised. If the
    latter, then he’d have to do some explaining to the
    local police…
    Tom Clancy, Rainbow Six

    View Slide

  38. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Yes, this could and would work. The only question
    was daylight or nighttime. The latter was the usual
    answer, but he’d learned the hard way that
    counter-terror teams loved the night…
    Tom Clancy, Rainbow Six

    View Slide

  39. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    “Language and economics.” The former had proven
    very useful. The latter had been totally valueless,
    since the Marxist idea of economics had not exactly
    proven to be an effective one.
    Tom Clancy, Rainbow Six

    View Slide

  40. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    Means of expressing a recurring
    construct or abstract idea, often
    across multiple languages

    View Slide

  41. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    i = 0
    for line in text.split("\n"):
    print "#{0} {1}".format(i, line)
    i += 1

    View Slide

  42. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    for i, line in enumerate(text.split("\n")):
    print "#{0} {1}".format(i, line)

    View Slide

  43. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    def my_enumerate(iterable):
    i = 0
    for item in iterable:
    yield i, item
    i += 1
    for i, line in my_enumerate(text.split("\n")):
    print "#{0} {1}".format(i, line)

    View Slide

  44. View Slide

  45. View Slide

  46. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    function enumerate($iterable) {
    $i = 0;
    foreach ($iterable as $item) {
    yield [$i, $item];
    $i++;
    }
    }
    foreach (enumerate(explode("\n", $text)) as list($i, $line)) {
    print "#$i $line\n";
    }

    View Slide

  47. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    DECISIONS ARE LIKE WATER

    View Slide

  48. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    (defn manhattan-distance [piece board]
    "Find the manhattan distance between a piece and its goal"
    (let [pos (locate piece board)
    goal-pos (locate piece *goal-state*)]
    (abs (+
    (- (floor (/ pos 3)) (floor (/ goal-pos 3)))
    (- (mod pos 3) (mod goal-pos 3))))))
    (defn manhattan-distance-sum [board]
    "Find the sum of the manhattan distances"
    (reduce + (map #(manhattan-distance % board) board)))

    View Slide

  49. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    var sortedDict = _(someDict).chain()
    .map(function(v, k) { return [k,v]; })
    .sortBy(function(a) { return a[0]; })
    .reduce(function(s, v) { s[v[0]] = v[1]; return s; }, {})
    .value();

    View Slide

  50. DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    PHP MADE
    ME BETTER

    View Slide

  51. +
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM
    THE TAKEAWAY
    Other languages make certain ABSTRACT concepts
    easier to learn
    By making it easier to use said concept than not use it
    in a way that your current language does not

    View Slide

  52. THANKS.
    FOR YOUR ATTENTION
    DANIEL COUSINEAU // FOLLOW ME : @DCOUSINEAU OR HTTP://DCOUSINEAU.COM

    View Slide