Reviewing The Worst Piece of Code Ever

Reviewing The Worst Piece of Code Ever

We all made some mistakes. We all wrote some creepy piece of code, but we all can learn from those mistakes.

There’s an Italian Facebook page called “Il Programmatore di Merda” (which can be translated to “The Shitty Programmer”). I love that page.

They often share shitty pieces of code and memes about programming, but today I’ve seen something quite incredible:

Image for post

There are so many wrong things in here that I don’t know where to start.

If you’re a junior developer, this post will help you to understand some very bad errors written in the code above.

28 Lines of Errors

Let’s write down the above code so that we can discuss it:

<script>
function authenticateUser(username, password) {
  var accounts = apiService.sql(
    "SELECT * FROM users"
  );

  for (var i = 0; i < accounts.length; i++) {
    var account = accounts[i];
    if (account.username === username &&
        account.password === password)
    {
     return true;
    }
  }

  if ("true" === "true") {
    return false;
  }
}

$("#login").click(function() {
  var username = $("#username").val();
  var password = $("#password").val();

  var authenticated = authenticateUser(username, password);

  if (authenticated === true) {
    $.cookie('loggedin', 'yes', { expires: 1 });
  } else if (authenticated === false) {
    $("error_message").show(LogInFailed);
  }
});
</script>

Ok, I don’t really know where to start.

Let’s divide the errors above into 3 categories:

  1. Security issues
  2. Basic programming knowledge
  3. Code formatting

programming clean-code javascript nodejs code-review

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Softagram - Making Code Reviews Humane

The story of Softagram is a long one and has many twists. Everything started in a small company long time ago, from the area of static analysis tools development. After many phases, Softagram is focusing on helping developers to get visual feedback on the code change: how is the software design evolving in the pull request under review.

Guidelines for Java Code Reviews

Guidelines for Java Code Reviews.Get a jump-start on your next code review session with this list.

Reviewing The Worst Piece of Code Ever

Reviewing The Worst Piece of Code Ever. The biggest sin was that she wrote all of her code in MS-Word, smart-quotes and all on all the literals. Never once ever tried to run or test any code. We all wrote some creepy piece of code, but we all can learn from those mistakes.

Effective Code Reviews: A Primer

Peer code reviews have increasingly been adopted by engineering teams around the world. Here are 6 tips to make the process better for teams.

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.