Ruining /r/programmerhumor memes

5 minute read

Published:

https://www.reddit.com/r/ProgrammerHumor/comments/8uqhfu/hell_yeah/

Hi everyone, today I’ll be ruthlessly destroying some /r/programmerhumor memes for those who are new to programming.

Gru Tries Recursion

https://www.reddit.com/r/ProgrammerHumor/comments/85a6n7/gru_tries_recursion/

Recursion is an elementary operation in logic, maths, and computer science where an operation is partially defined in terms of itself. While the most common example is the Fibonnaci function, the best example is perhaps addition of two integers:

Recursion in various languages

Basic Recursion: Addition
>def add(a, b):
>  if b = 0: # The 'exit condition' allows recursion to end, return value is *not* defined in terms of this function.
>    return a
>  else:
>    return add(a+1, b-1) # Here, the add function is called on incremented/decremented arguments. 
  
Fibonacci: Iterative, Recursive, Tail-recursive
# P E R F O R M A N C E
# 2.7.10, GCC 4.2.1, Apple LLVM 8.0 on 2011 OSX
>import numpy
>import timeit
# Regular, non-recursive imperative/procedural implementation.
>def fibIter(n):
>  if n < 2:
>    return n
>  fibPrev = 1
>  fib = 1
>  for num in xrange(2, n):
>    fibPrev, fib = fib, fib + fibPrev
>  return fib
# Recursive, simple, and intuitive. But not very efficient for *machines* for larger n
>def fibRecur(n):
>  if n < 2:
>    return n
>  else:
>    return fibRec(n - 1) + fibRec(n - 2)
# Tail recursive, simple outer wrapper with defaults, efficient for machines.
>def fibTailRecur(n):
>  def fib(a, b, m):
>    if m < 1:
>      return a
>    else:
>      return fib(b, a + b, m - 1)
>  return fib(0, 1, n)
Fibonacci: Iterative, recursive, tail recursive
>require 'memory_profiler'
>def fibIter(n):
>  if n < 2:
>    return n
>  else:
>    a, b = 1, 1
>    (n-2).times {|x| a,b = b, a + b}
>  return n
>end

>def fibRecur(n)
>  if n < 2:
>    return n
>  else:
>    return fibRecur(n-1) + fibRecur(n-2)
>end

>def fibTailRecur(n)
>  def fib(a, b, m)
>    if m < 1
>      return 1
>    else
>      return fib(b, a+b, m-1)
>    end
>  end
>  return fib(0, 1, n)
>end

>

While the concept seems simple as presented here, a special type of recursion should be mentioned (as it's mentioned in nearly every other ignorant hipster treatment of recursion these days): tail recursion. Tail recursion is a special type of recursive treatment that results in a constant memory requirement as the recursion progresses, instead of the linear memory requirements afforded by poorly formed recursive functions. The differences can be seen in the 'Python' and 'Ruby' panels above.

Object-oriented Zucc

https://www.reddit.com/r/ProgrammerHumor/comments/8bh21u/not_oc_zuckerborgdrink/

Next, no discussion is complete in 2018 without mentioning OOP, by and far the dominant programming paradigm in industry. Too simplify, we'll assume basic knowledge of computer programs and describe a few classes of software. In the gif above is the actual source code of Zucc's internal programming. The .gif alludes to event-driven programming, where the 'state' of Mark's thirst is stored in a boolean attribute/instance-variable, accessed from zucc.isQuenched(). Mark responds to thirst with the following instance methods, some of which receive a hand instance: zucc.reach(right), zucc.grip(right), zucc.raise(right), zucc.sip(). The joke is obvious due to the high-level abstractions of the tasks, as well as appropriate method/instance names. Looking for more reading on objects, classes, instances and OOP? Here is an excellent review from Salman Khan.

FrontEnd vs. BackEnd

https://www.reddit.com/r/ProgrammerHumor/comments/7zfgwg/frontend_vs_backend/

I debated whether this meme deserved to make the cut and decided to include it for those who don’t have much experience making different kinds of applications. Not every developer will want to make different kinds of applications but I think this can still help everyone understand the perspective we give towards applications. There’s also a dual nature to discuss here and I’ll start with UI. User interfaces always need to be simplistic and intuitive to reach the most users. In my opinion, it is sad but true that utility doesn’t always win when it comes to the ‘value’ of an application and software developers that neglect their UIs are often punished.

That said, the image above the surface is calm, tranquil, and simple. The user is given a pretty, simplistic picture of the state of the creature, without any distraction or clutter. Of course this is the way things look to the user, but that does not at all mean that the code for the UI is in any way simple. In fact the above-the-surface depiction of simplicity and aesthetic is in stark contrast to the complexity of UI design. It takes a true love for artistic principles and design concepts to understand how the user thinks and what they value.

In contrast, the image shows beneath the ‘surface’ of the communication layer (HTTP/TCP) is an ugly creature, with different appendages, and a gruesome mechanical and technical feel. I’m sure that the abstract content of back-end source code might seem ‘ugly’ to front-end developers or even the user, but the functionality is anything but ugly. The aesthetic is in the structure of the app but also in convenient frameworks used by back server-side developers (e.g. Rails, Flask, Django, Express).

That’s it for this post! I’ll be doing this often I hope, ruining the punchline…

Extras

Does anyone else remember the Hawaii missile warning false alarm?