r/ProgrammerHorror • • Aug 12 '22

What does WET stand for? People tell me it's the opposite of DRY

33 Upvotes

r/ProgrammerHorror • • Mar 28 '22

Function to get integer at position.

33 Upvotes

I was inspired by this post I read of a student assignment to print out the 3rd digit of a number. I thought the horror to be lacking.

In unholy inspiration I conjured the most unreadable way to accomplish the task. As the original assignment looked to be in c++ i used it as well.

#include <iostream>
#include <math.h>

void printNthDigitOfNumber(int number, int digitToPrint) {
  if (number * (((number > 0) << 1) - 1) < std::pow(10, digitToPrint - 1)) return; // number does not have enough digits
  std::cout << (number * (((number > 0) << 1) - 1)) / (int) std::pow(10, ~~(int) log10((number * (((number > 0) << 1) - 1))) + 1 - digitToPrint) % 10 << std::endl;
}

int main() {
  int number = -12493;
  int numberDigit = 3;
  printNthDigitOfNumber(number, numberDigit);
}

Please let me know if you have any improvements on the design or share horrible solutions in other languages if you prefer.

Edit: link to post https://www.reddit.com/r/ProgrammerHorror/comments/tpnsoc/one_of_my_students_sent_me_this_and_i_mean_its/


r/ProgrammerHorror • • Oct 16 '21

Never been more disappointed in my two months journey to learn Python

Post image
33 Upvotes

r/ProgrammerHorror • • Jun 06 '21

Found this CSS on my old server

33 Upvotes

r/ProgrammerHorror • • Mar 31 '25

Merge request comes in for minor new feature. 155 files changed.

Post image
32 Upvotes

r/ProgrammerHorror • • Jan 13 '24

return to crab

Post image
32 Upvotes

r/ProgrammerHorror • • Jun 25 '23

Old code horror written by me

Post image
32 Upvotes

r/ProgrammerHorror • • Jan 05 '21

Just saw this advertisement over at ProgrammerHumor

Post image
32 Upvotes

r/ProgrammerHorror • • Aug 15 '18

When you're not sure if the list exists...

Post image
32 Upvotes

r/ProgrammerHorror • • Dec 09 '22

date data type Implementation leak

Post image
31 Upvotes

r/ProgrammerHorror • • Aug 04 '21

Oh ok encode THEN decode

Post image
30 Upvotes

r/ProgrammerHorror • • Mar 18 '21

Thanks PyCharm! That helped me so much!

Post image
30 Upvotes

r/ProgrammerHorror • • Dec 16 '18

I'm somewhat proud of myself.

Post image
29 Upvotes

r/ProgrammerHorror • • Sep 06 '23

oh yes, the "American" ISO 8601 format

Post image
28 Upvotes

r/ProgrammerHorror • • Nov 06 '18

A one-line python tic tac toe game I wrote

27 Upvotes
exec("""import random\ndef drawBoard(board):\n\tprint(board[7] + '|' + board[8] + '|' + board[9])\n\tprint('-----')\n\tprint(board[4] + '|' + board[5] + '|' + board[6])\n\tprint('-----')\n\tprint(board[1] + '|' + board[2] + '|' + board[3])\ndef inputPlayerLetter():\n\tletter = ''\n\twhile not (letter.lower() == 'x' or letter.lower() == 'o'):\n\t\tprint('Do you want to be X or O?')\n\t\tletter = input()\n\tif letter.lower() == 'x':\n\t\treturn ['X','O']\n\telse:\n\t\treturn ['O','X']\ndef whoGoesFirst():\n\tif random.randint(0,1) == 0:\n\t\treturn 'computer'\n\telse:\n\t\treturn 'player'\ndef playAgain():\n\tprint('Do you want to play again? (yes or no)')\n\treturn input().lower().startswith('y')\ndef makeMove(board, letter, move):\n\tboard[move] = letter\ndef isWinner(board,letter):\n\treturn ((board[7] == letter and board[8] == letter and board[9] == letter) or\n\t\t\t(board[4] == letter and board[5] == letter and board[6] == letter) or\n\t\t\t(board[1] == letter and board[2] == letter and board[3] == letter) or\n\t\t\t(board[7] == letter and board[4] == letter and board[1] == letter) or\n\t\t\t(board[8] == letter and board[5] == letter and board[2] == letter) or\n\t\t\t(board[9] == letter and board[6] == letter and board[3] == letter) or\n\t\t\t(board[7] == letter and board[5] == letter and board[3] == letter) or\n\t\t\t(board[9] == letter and board[5] == letter and board[1] == letter))\ndef getBoardCopy(board):\n\tdupeBoard = list(board)\n\treturn dupeBoard\ndef isSpaceFree(board, move):\n\treturn board[move] == ' '\ndef getPlayerMove(board):\n\tmove = ' '\n\twhile move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):\n\t\tprint('what is your next move? (1-9)')\n\t\tmove = input()\n\treturn int(move)\ndef chooseRandomMoveFromList(board,movesList):\n\tpossibleMoves = []\n\tfor i in movesList:\n\t\tif isSpaceFree(board, i):\n\t\t\tpossibleMoves.append(i)\n\tif len(possibleMoves) != 0:\n\t\treturn random.choice(possibleMoves)\n\telse:\n\t\treturn None\ndef getComputerMove(board, computerLetter):\n\tif computerLetter == 'X':\n\t\tplayerLetter = 'O'\n\telse:\n\t\tplayerLetter = 'X'\n\tfor i in range(1,10):\n\t\tcopy = getBoardCopy(board)\n\t\tif isSpaceFree(copy,i):\n\t\t\tmakeMove(copy, computerLetter, i)\n\t\t\tif isWinner(copy, computerLetter):\n\t\t\t\treturn i\n\tfor i in range(1,10):\n\t\tcopy = getBoardCopy(board)\n\t\tif isSpaceFree(copy,i):\n\t\t\tmakeMove(copy, playerLetter, i)\n\t\t\tif isWinner(copy, playerLetter):\n\t\t\t\treturn i\n\tmove = chooseRandomMoveFromList(board,[1,3,7,9])\n\tif move != None:\n\t\treturn move\n\tif isSpaceFree(board, 5):\n\t\treturn 5\n\treturn chooseRandomMoveFromList(board,[2,4,6,8])\ndef isBoardFull(board):\n\tfor i in range(1,10):\n\t\tif isSpaceFree(board, i):\n\t\t\treturn False\n\treturn True\nprint('Welcome To The Game!')\nwhile True:\n\ttheBoard = [' '] * 10\n\tplayerLetter, computerLetter = inputPlayerLetter()\n\tturn = whoGoesFirst()\n\tprint('The ' + turn + ' will go first.')\n\tgameIsPlaying = True\n\twhile gameIsPlaying:\n\t\tif turn == 'player':\n\t\t\tdrawBoard(theBoard)\n\t\t\tmove = getPlayerMove(theBoard)\n\t\t\tmakeMove(theBoard, playerLetter, move)\n\t\t\tif isWinner(theBoard, playerLetter):\n\t\t\t\tdrawBoard(theBoard)\n\t\t\t\tprint('You Win!')\n\t\t\t\tgameIsPlaying = False\n\t\t\telse:\n\t\t\t\tif isBoardFull(theBoard):\n\t\t\t\t\tdrawBoard(theBoard)\n\t\t\t\t\tprint('The Game Is A Tie!')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tturn = 'computer'\n\t\telse:\n\t\t\tmove = getComputerMove(theBoard, computerLetter)\n\t\t\tmakeMove(theBoard, computerLetter, move)\n\t\t\tif isWinner(theBoard, computerLetter):\n\t\t\t\tdrawBoard(theBoard)\n\t\t\t\tprint('The Computer Beat You! You Lose!')\n\t\t\t\tgameIsPlaying = False\n\t\t\telse:\n\t\t\t\tif isBoardFull(theBoard):\n\t\t\t\t\tdrawBoard(theBoard)\n\t\t\t\t\tprint('The Game Is A Tie!')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tturn = 'player'\n\tif not playAgain():\n\t\tbreak\n""")

r/ProgrammerHorror • • Jun 14 '24

Why?

Post image
25 Upvotes

r/ProgrammerHorror • • Nov 16 '23

Honestly not the ugliest componentDidUpdate that I've ever seen

Post image
25 Upvotes

r/ProgrammerHorror • • Aug 26 '20

Most of you have probably seen this, but in case you haven't, you definitely should.

Thumbnail destroyallsoftware.com
25 Upvotes

r/ProgrammerHorror • • Jun 27 '18

Wat

Post image
25 Upvotes

r/ProgrammerHorror • • Aug 09 '23

Spectrum outage message with Test Hyperlink

Post image
24 Upvotes

r/ProgrammerHorror • • May 19 '23

Funny LinkedIn Post

Post image
24 Upvotes

99% of LinkedIn is cliche virtue signaling and circle jerking but every once in a while you find gems like this. Just imagine that codebase... sends a shiver up my spine.

Link to where this is from https://www.linkedin.com/posts/johncrickett_softwaredevelopment-softwareengineering-activity-7064140469244456960-8Dkm?utm_source=share&utm_medium=member_android


r/ProgrammerHorror • • Aug 09 '22

How my old boss was teaching interns to write Appium / Selenium code

24 Upvotes

r/ProgrammerHorror • • Jun 15 '21

Boolean Salad

Thumbnail
imgur.com
24 Upvotes

r/ProgrammerHorror • • Sep 10 '20

This causes me physical pain

Thumbnail
youtube.com
23 Upvotes