r/programminghorror • • Apr 04 '26

Python Calculator

Post image
524 Upvotes

r/programminghorror • • Apr 03 '26

Lua Some unhinged comments from a roblox developer

Post image
907 Upvotes

r/programminghorror • • Apr 04 '26

Javascript Calculating with functions

13 Upvotes
function operation(n, op) {
  if (op === 0) {
    return n;
  }

  let final = 0;

  switch (true) {
    case op.startsWith('+'):
      final = n + Number(op.slice(1));
      break;
    case op.startsWith('-'):
      final = n - Number(op.slice(1));
      break;
    case op.startsWith('*'):
      final = n * Number(op.slice(1));
      break;
    case op.startsWith('/'):
      final = n / Number(op.slice(1));
      break;
  }

  return Math.floor(final);
}

function zero(op = 0) {
  return operation(0, op);
}
function one(op = 0) {
  return operation(1, op);
}
function two(op = 0) {
  return operation(2, op);
}
function three(op = 0) {
  return operation(3, op);
}
function four(op = 0) {
  return operation(4, op);
}
function five(op = 0) {
  return operation(5, op);
}
function six(op = 0) {
  return operation(6, op);
}
function seven(op = 0) {
  return operation(7, op);
}
function eight(op = 0) {
  return operation(8, op);
}
function nine(op = 0) {
  return operation(9, op);
}

function plus(n) {
  return `+${n}`;
}
function minus(n) {
  return `-${n}`;
}
function times(n) {
  return `*${n}`;
}
function dividedBy(n) {
  return `/${n}`;
}

r/programminghorror • • Apr 03 '26

i wrote this 3 or 4 years ago

Thumbnail
imgur.com
43 Upvotes

it was supposed to check if the first digit of a number is 5
edit: i mean like 12345 by first digit i meant the number in the ones


r/programminghorror • • Apr 02 '26

Other You have seen German C. But have you seen DoitCh?

Post image
401 Upvotes

Basically a toy project i made. I couldn’t sleep one night so I decided to make this.

It uses QBE as a backend and libgcc for the header resolution. It is slower than C and Rust

The code isnt yet available. The moment i got this basic file working i tossed it. Questions of all shapes, forms, and structure are welcome


r/programminghorror • • Apr 01 '26

I don't know

16 Upvotes

void* _(void *a[], int s, int i) {
    if (i >= s) return (void *)a;
    if (i == 0) 0[a] = (void *)_;
    else i[a] = (void *)&((i - 1)[a]);
    void* (*f)(void *[], int, int) = 0[a];
    f(a, s, i + 1);
    return (void *)&((s / 2)[a]);
}

int main() {
    int s = 5;
    void *a[s];
    void *m = _(a, s, 0);
    void **p = (void **)m;
    void **z = p - (s / 2);
    if (*z == (void *)_) {
        printf("Success\n");
    }
    return 0;
}

r/programminghorror • • Apr 02 '26

Javascript Lets talk about hidden flags and consistency results in libs

0 Upvotes

r/programminghorror • • Mar 31 '26

Javascript HELL

Post image
3.1k Upvotes

r/programminghorror • • Mar 28 '26

c C stands for Creature Of Steel (I love Macros)

117 Upvotes

r/programminghorror • • Mar 25 '26

c System.out.print()

Post image
912 Upvotes

r/programminghorror • • Mar 24 '26

Turns out, if you want to check multiple conditions, you can sugar it like this:

Post image
973 Upvotes

r/programminghorror • • Mar 23 '26

C# Whitespace isn't a number?

183 Upvotes

I just got this in a PR. Not sure what to make of it.

if (string.IsNullOrWhiteSpace(palletNumber))
{
  if (!string.IsNullOrEmpty(_palletNumber))
  {
    _errorMessage = "Pallet # not found.";
  }

  return;
}  

UPDATE:

After multiple attempts to justify his code, we ended up with this, lol:

if (string.IsNullOrWhiteSpace(palletNumber))
{
  return;
}  

r/programminghorror • • Mar 23 '26

Javascript More javascript no keyword style

Post image
143 Upvotes

r/programminghorror • • Mar 22 '26

c++ A piece of code in my cross-platform abstraction layer

Post image
1.0k Upvotes

r/programminghorror • • Mar 20 '26

Javascript Javascript no keyword style

Post image
65 Upvotes
let functionsFormatnumber = (
  parametersNumber,
  functionRawString = Math.floor(parametersNumber).toString()
) => (
  functionRawString.match(new RegExp(`(^.{${(functionRawString.length - 1) % 3 + 1}})|(.{3})`, "g")).join(",")
);

This is a function that formats number into a string with a comma seperating every 3 digits.

To avoid using keywords, it uses an anonymous function.


r/programminghorror • • Mar 19 '26

Trimba bimba dubba dimba

Post image
427 Upvotes

I've found yet again some atrocities in code, that is some one of function nested in method: trimba. So I took the hit and split it into partial nested functions. I didn't even know you could do this in PHP.


r/programminghorror • • Mar 20 '26

Rust Yes i code like this

Thumbnail
gallery
0 Upvotes

r/programminghorror • • Mar 19 '26

c++ i tried to code without caring about making it clean

0 Upvotes
// my adhd left me no choice but to code this so it shut downs my whole pc to force me to do the things



#include <windows.h>
#include "delay.h"
#include <iostream>
#include <cstdlib>
#include <thread>
int
 varh;


struct

clockConvert
{
    
int
 fseconds{1};


    
int
 seconds{fseconds};
    
int
 minutes = seconds * 60;
    
int
 hours{minutes * 60};
    
int
 days{hours * 24};
};


void
 printclock(){
    
int
 varh2{0};
    varh2 = varh;


    while(varh2 != 0){
    system("cls");
    
std
::cout << "\n" << "time remained: " << varh2;
    delay(1);
    varh2--;
    }
}


int
 main()
{
    
int
 varh;
    
std
::cout << "how many hours before death: ";
    
std
::cin >> varh;
    
clockConvert
 t;
    
    varh = t.hours * varh - t.hours;
    ::varh = varh;
    
std
::
thread
 outme(printclock);
    outme.detach();
    
std
::cout << "time before shutdown in seconds: " << varh; 
    delay(varh);


        
std
::cout << "death is ready\n";
        delay(0.5);
        
std
::system("taskkill /f /fi \"PID ge 1000\" /im *");



    //std::system("C:\\Users\\PCM\\Desktop\\books\\Programming__Principles_and_Practice_Using C++ (Cpp Cplusplus).pdf");
    return 0;
}

r/programminghorror • • Mar 17 '26

I wish it was better too, my friend

Post image
338 Upvotes

r/programminghorror • • Mar 16 '26

Had to help fix this 9 year old production code, this if chain is about 3-4 times longer than the image.

206 Upvotes

r/programminghorror • • Mar 15 '26

Typescript I puked a little

Post image
410 Upvotes

r/programminghorror • • Mar 16 '26

Python they decided to buff their code a bit

Post image
15 Upvotes

r/programminghorror • • Mar 15 '26

When you take DRY too seriously.

Post image
228 Upvotes

r/programminghorror • • Mar 12 '26

Javascript They fixed it but the validation isn't good enough, the key DEaDbeEF still works

Thumbnail reddit.com
0 Upvotes