complexity

This is a collection of observations about program complexity.

Lots of False

Someone starts with a function that begins like this:

def GetReportData(selector, fields=None):
    if not fields: fields = self.DEFAULT_FIELDS

then they are instructed to add a start/end date, so they end up with this:

def GetReportData(selector, fields=None, start=None, end=None):
    if not fields: fields = self.DEFAULT_FIELDS
    if not start: start = datetime.min
    if not end: end = datetime.utcnow()

Hint: Python datetime documentation

Discovery

function clamp($x,$y,$z)
Quick: What will clamp(100,0,69) return?
if($x>$y)return $y;
if($x<$z)return $z;
return $x;
$a=func_get_args();
sort($a);
return $a[1];
Let's solve this problem with gigabyte text editors...

Performance

We had a good macro for making symbols:
#define S(x) (*(uint64_t*)(#x "\0\0\0\0\0\0\0\0"))
but somebody replaced it with std:: objects because they were "better".

Object Oriented

Task: When presenting an object to a remote debugger, send it a proxy instead. That way, it doesn't matter how big the object is, or if it has cycles in it.
Proxy.prototype.get = function(key) { return this.object[key]; }
I wonder how they intended to send the Proxy object.

Redundancy

I wonder if the programmer thinks about how f.on and f.emit must be implemented.

f.on("message", function(x) {
  command[x[0]].apply(command, x.slice(1));
});
...
f.emit("message", ["a", 69]);

Boilerplate

When you code for machines...
/**
 *
 * @param DefinitionEntry $cDefinition 
 */
public function SetSingleSelectionLimited(DefinitionEntry $cDefinition)