[Java] The fucking code that I used to see

2 minute read

Overview

Inspired by @rana_kualu’s article, I’ll write about the damn fucking code I’ve ever seen.

(Original article) The most dirty source code I’ve ever seen-Qiita https://qiita.com/rana_kualu/items/2f3c40642836c11f5ddc

Fucking code

① typedef

Reproduction code.c


typedef void coid;
typedef void boid;

Looking at the keyboard, [c] [v] [b] are lined up. In other words, this covers typos by redefining the type name. As expected, I thought that this was not a program **.

② Minus 10,000

Variable names are suitable for the time being.

Reproduction code.php


$date0 = '20201122'; // The character string comes from the screen with YYYYMMDD
$date1 = $date0 -10000;
$year = substr($date1, 0, 4);
$month = substr($date1, 4, 2);
$day = substr($date1, 6, 2);

What’s the process of pulling 10,000? A colleague (at that time) found this code from a mechanism that was being maintained, and bothered together. 10,000 is not sharp in date processing. .. .. Fortunately the person who wrote it was next to me so I asked him directly.

Calculating 1 year ago

:thinking::thinking::thinking::thinking::thinking:

:astonished: I see! :rage: Rewrite! :punch_tone2:

Fortunately, the person I wrote was a friend (classmate) from high school, so I hit him for the time being.

There are functions for manipulating dates, so let’s use it. (I mean, I’m a static field man, so my knees quivered how to use dynamic conversion.)

③ Takoika Panic

Reproduction code.java


boolean checkNumber (str) {
  boolean isNumber = !NumberUtils.isNumber(str);
  if(isNumber) {
    // error message processing
  }
  return !isNumber;
}

Tsukkomi

  • The variable name is obviously lying
  • After all, this function inverts back again
  • So what was the reason why it was reversed in the first place? ? ?

The logical value (boolean value) is messed up.

Logical values are very confusing, so be careful when handling them. I try to make the positive one true and the negative one false. ## ④ (Addition) Power of include! [@fujitanozomu's sample code](https://qiita.com/libraplanet/items/5fbe7d7d3b4f1906b4ad#comment-c189c5cad7740bbd8258) #### **` Reproduction code.c`** ```c int tbl[] = { #include }; ``` This way... .. .. It's hard work because you understand the compilation process! ? I tought. Macro culture has become a basic bad law in programming languages. (Some features remain in later languages) # that's all I want to devote myself every day to avoid writing shit code. # Addition ① 2020/06/21 (Sun) I am surprised that the number of views is larger than I expected. The part where the corners stand is likely to be a private issue, so I deleted part of the description. # Addendum 2 2020/06/21 (Sun) ④ has been added. I just remembered it (bitter smile) # Addendum ③ 2020/06/22 (Sun) Information from @sakuro. There seems to be a file format that is originally supposed to be included. ・XPM-Wikipedia https://ja.wikipedia.org/wiki/XPM XPM itself seems to be a body of C source code.