Home » Derpifying Images

Derpifying Images

Solutons:


This script is a total of 99 lines. Of that, 49 lines are insulting, annoying, and ironic self-congratulating comments.

In general, comments are good. They help any future maintainer (including yourself when it’s been 6 months since the last time you looked at the script) to understand what the code does because programmer time is extraordinarily valuable. Programmer time should be spent fixing the code–not trying to understand it, and helpful comments go a long way toward cutting down on the “trying to understand it” part of the program.

These comments are not funny, at least not in a “laughing with you” sort of way. And they are not constructive. And perhaps worst of all, they’re not even consistent.


/**
 * In this function we make sure the end user isn't
 * a total moran by checking weather we have access
 * to certain hacker libraries.
 *
 **/

Here, we accuse the user of being a “moran” by checking the “weather” or something (though the function doesn’t at all appear to be accessing any sort of weather web service). This comment might be better written as:

// Determine whether necessary libraries exist

This removes the misspellings and still accurately describes in plain-English what the goal of the function is.


// Here we throw an error if we encounter a stupid user.
// >2012
// >Not having GD installed.
//
// ISHYGDDT.

As a note from someone who has plenty of experience dealing with users, your best bet is to program for the lowest common denominator. A “stupid” user is still a user, and if you’re not capable of writing programs that “stupid” users can use, then perhaps it is you who has no hope as a programmer.

This comment might be better written as:

// Alert the user that a necessary library is missing

I’d also argue that including some instructions on how to install the missing library would probably be helpful in your echo statements.


/**
 * Stand back kiddies, this is how a real
 * programmer does things.
 *
 **/

This comment is completely unhelpful and can be completely removed.


  // Enterprise usage of the count() function
  // is demonstrated here, take note of the
  // combined < and = symbol here, only a master
  // programmer could have achieved such an
  // operater without R(ing)TFM.

As a programmer, you have 3 options.

The first option is to develop your own programming language and write the manual for it, and then you don’t have to read the manual. This is PHP; you didn’t create it, so you’re going to fall into one of the other two categories.

The second option is to read the manual. This is what the master programmers do. Manuals are boring and hard to read, but if you want to make the most out of a given programming language, you have to be familiar with the documentation for that language or… fall into the third category…

The third option is learning from other programmers who already read the manual, and while you could still be a “master” programmer and be in this category, you’re no more “master” than those from whom you learn.


  # Only the technologically independent and savvy programmer
  # will be able to truly understand the genius of the below
  # statement; one that even William Shakespear could not have
  # written better.

Once again, another misspelling in the midst of self-congratulating the genius of a programmer who can’t even spell-check.

The irony of this comment is astounding.

Let’s first of all ignore the fact that you misspelled Shakespeare and ignore the fact that he was a playwright, not a programmer, so if you can’t write code better than him, again, you’re probably the one who has no hope at a programmer.

Instead, let’s look at the comment which introduces a somewhat confusing ternary statement. The whole point of comments, again, is to make code more readable. Although, a true master programmer writes the executable code in a highly readable way as a starting point, and only needs comments to explain the bits of code that can’t easily be written in a highly readable manner.

There’s nothing that impressive about the ternary statement–it’s certainly not worthy of self-congratulation. However, it’d be my guess that there’s a better way of doing this in PHP (though I’m no PHP master, so maybe not). But if we feel the ternary statement is not so obvious to the average reader of our source code that a comment is necessary, then the appropriate sort of comment would be to clarify what the code is actually doing. Something more along the lines of this:

// Grabs the file extension

Also, by the way…

// oh so bright. What a marvelous function

It’s not a function. It’s an operator. It’s called the ternary operator. The fact that it’s called a ternary operator is something you could learn by reading the documentation.

sed 's/(//|#).*$//g' YOUR_FILENAME | sed '/^$/N;/^s*$/D'

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments – some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in if/else statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see?
     ? substr($file, -4) // Can you see my genius.
     : substr($file, -3) // It's shining...
     ; // oh so bright. What a marvelous function, I
       // couldn't have done it better myself. Oh, wait.

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION);

In fact, the variables $file and $type are only used once (and hence shouldn’t even be variables).

Related Solutions

Winsock programming connecting to a public ip

The issue is with your server. You are binding it to 127.0.0.1. This means your server will only bind to the loopback interface, so only clients running on the same machine as the server will be able to connect to the server using this same interface. If you...

Pin-board effect with CSS [closed]

You can use JavaScript to accomplish this but it can't be done with CSS floats alone. A library like jQuery masonry will do it well. The reason? The specs on floats. In particular #5 which says, "The outer top of a floating box may not be higher than the outer...

Calculate the sum with minimum usage of numbers

Here's a hint: 23 : 11 + 11+ 1 ( 3 magic numbers) 120: 110+ 10 (2 magic numbers) The highest digit in the target number is the answer, since you need exactly k magic numbers (all having 1 in the relevant position) in order for the sum to contain the digit k. So...

Why not drop the “auto” keyword? [duplicate]

Your proposal would be rejected on the basis of backward compatibility alone. But let's say for the sake of argument that the standards committee like your idea. You don't take into account the numerous ways you can initialize a variable widget w; // (a) widget...

Recursive to iterative using a systematic method [closed]

So, to restate the question. We have a function f, in our case fac. def fac(n): if n==0: return 1 else: return n*fac(n-1) It is implemented recursively. We want to implement a function facOpt that does the same thing but iteratively. fac is written almost in...

How can I match values in one file to ranges from another?

if the data file sizes are not huge, there is a simpler way $ join input1 input2 | awk '$5<$4 && $3<$5 {print $2, $5-$3+1}' B100002 32 B100043 15 B123465 3 This Perl code seems to solve your problem It is a common idiom: to load the entire...

Javascript difference between “=” and “===” [duplicate]

You need to use == or === for equality checking. = is the assignment operator. You can read about assignment operators here on MDN. As a quick reference as you are learning JS: = assignment operator == equal to === equal value and equal type != not equal !==...

Compiler complains about misplaced else [closed]

Your compiler complains about an misplaced else because, well, there is an else without a preceding if: // ... for (j=1; j<n-i; j++) { if(a[j]<=a[j+1]) { // ... } // END OF IF } // END OF FOR else { continue; } // ... The else in your code does not follow...

Bootstrap – custom alerts with progress bar

/* !important are just used to overide the bootstrap css in the snippet */ .alertContainer { border-radius: 0 !important; border-width: 0 !important; padding: 0 !important; height: auto !important; position: absolute !important; bottom: 15px !important; left:...

How to Garbage Collect an external Javascript load?

Yes, s.onload = null is useful and will garbage collect! As of 2019, it is not possible to explicitly or programmatically trigger garbage collection in JavaScript. That means it collects when it wants. Although there is cases where setting to null may do a GC...

Math programming with python

At first, what you are looking for is the modulo operator and the function math.floor() Modulo from wikipedia: In computing, the modulo operation finds the remainder after division of one number by another (sometimes called modulus). for example: 12%12=0...

Android slide over letters to create a word [closed]

Here some advice you can use: First for each cell you can create an object that represents the state of that cell: class Cell { char mChar; int row,column; boolean isSelected; } then you can create a 2D array of your cells Cell[][] mTable = ... For views you...

Sum two integers in Java

You reused the x and y variable names (hence the variable x is already defined in method main error), and forgot to assign the ints read from the Scanner to the x and y variables. Besides, there's no need to create two Scanner objects. public static void...