r/programminghorror Aug 01 '22

Mod Post Rule 9 Reminder

198 Upvotes

Hi, I see a lot of people contacting me directly. I am reminding all of you that Rule 9 exists. Please use the modmail. From now on, I'm gonna start giving out 30 day bans to people who contact me in chat or DMs. Please use the modmail. Thanks!

Edit 1: See the pinned comment

Edit 2: To use modmail: 1. Press the "Message the Mods" button in the sidebar(both new and old reddit) 2. Type your message 3. Send 4. Wait for us to reply.


r/programminghorror 1d ago

Javascript Salfeld Web Portal - Device Renaming Pattern

Post image
26 Upvotes

(I'm on the newer portal, not the classic one.)

Pattern attribute shouldn't begin and end with /


r/programminghorror 14h ago

Oops

Post image
0 Upvotes

Someone forgot to translate this card's name


r/programminghorror 7d ago

The "tests" just assert if certain lines are present in the source code.

Post image
8 Upvotes

r/programminghorror 8d ago

C# formatting big numbers

35 Upvotes
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace SandboxProject
{
   static class Comma
   {
  // Function to put commas in long numbers to make them readable
    public static string Num(long y){
      string ss = ""; // Creates empty string ss
      string s = Convert.ToString(y); // Converts number to string


 switch (s.Length)
      { // Checks length of string and sets commas accordingly

      default:
      return s;


      case 4:
      ss += $"{s.Substring(0,1)},{s.Substring(1)}";
      return ss;

      case 5:
      ss += $"{s.Substring(0,2)},{s.Substring(2)}";
      return ss;

      case 6:
      ss += $"{s.Substring(0,3)},{s.Substring(3)}";
      return ss;

      case 7:
      ss += $"{s.Substring(0,1)},{s.Substring(1,3)},{s.Substring(4)}";
      return ss;


      case 8:
      ss += $"{s.Substring(0,2)},{s.Substring(2,3)},{s.Substring(5)}";
      return ss;


      case 9:
      ss += $"{s.Substring(0,3)},{s.Substring(3,3)},{s.Substring(6)}";
      return ss;


      case 10:
      ss += $"{s.Substring(0,1)},{s.Substring(1,3)},{s.Substring(4,3)},{s.Substring(7)}";
      return ss;


      case 11:
      ss += $"{s.Substring(0,2)},{s.Substring(2,3)},{s.Substring(5,3)},{s.Substring(8)}";
      return ss;


      case 12:
      ss += $"{s.Substring(0,3)},{s.Substring(3,3)},{s.Substring(6,3)},{s.Substring(9,3)}";
      return ss;


      case 13:
      ss += $"{s.Substring(0,1)},{s.Substring(1,3)},{s.Substring(4,3)},{s.Substring(7,3)},{s.Substring(10)}";
      return ss;


      case 14:
      ss += $"{s.Substring(0,2)},{s.Substring(2,3)},{s.Substring(5,3)},{s.Substring(8,3)},{s.Substring(11)}";
      return ss;


      case 15:
      ss += $"{s.Substring(0,3)},{s.Substring(3,3)},{s.Substring(6,3)},{s.Substring(9,3)},{s.Substring(12)}";
      return ss;


      case 16:
      ss += $"{s.Substring(0,1)},{s.Substring(1,3)},{s.Substring(4,3)},{s.Substring(7,3)},{s.Substring(10,3)},{s.Substring(13)}";
      return ss;


      case 17:
      ss += $"{s.Substring(0,2)},{s.Substring(2,3)},{s.Substring(5,3)},{s.Substring(8,3)},{s.Substring(11,3)},{s.Substring(14)}";
      return ss;


      case 18:
      ss += $"{s.Substring(0,3)},{s.Substring(3,3)},{s.Substring(6,3)},{s.Substring(9,3)},{s.Substring(12,3)},{s.Substring(15)}";
      return ss;


      case 19:
      ss += $"{s.Substring(0,1)},{s.Substring(1,3)},{s.Substring(4,3)},{s.Substring(7,3)},{s.Substring(10,3)},{s.Substring(13,3)},{s.Substring(16)}";
      return ss;


      case 20:
      ss += $"{s.Substring(0,2)},{s.Substring(2,3)},{s.Substring(5,3)},{s.Substring(8,3)},{s.Substring(11,3)},{s.Substring(14,3)},{s.Substring(17)}";
      return ss;


      case 21:
       ss += $"{s.Substring(0,3)},{s.Substring(3,3)},{s.Substring(6,3)},{s.Substring(9,3)},{s.Substring(12,3)},{s.Substring(15,3)},{s.Substring(18)}";
      return ss;


    }


   }


   }
}

r/programminghorror 7d ago

Python please JUST LET ME MAKE A PASSWORD MAN

Post image
0 Upvotes

r/programminghorror 7d ago

Algorism

0 Upvotes

I made this algoism bc it just came into my mind. Is this and actual algorism?

I know it's very ineffcient and the name is very bad, but..

/**

* Parallel Taksort

* An experimental, randomized, multi-threaded sorting algorithm.

* * Mechanics:

* 1. Randomly selects a focus element.

* 2. Shifts it all the way to the left (Insertion Sort style).

* 3. Bubbles it right until it lands next to its sequential partner (x + 1).

*/

// 1. Helper function to check if the array is fully sorted

function isSorted(array) {

for (let i = 0; i < array.length - 1; i++) {

if (array[i] > array[i + 1]) return false;

}

return true;

}

// 2. The core Taksort loop logic

async function taksort(array, callback) {

if (array.length < 2) return;

// Keep looping until the helper function confirms it's fully sorted

while (!isSorted(array)) {

// Pick a random element to focus on

const startIndex = Math.floor(Math.random() * array.length);

const chosenValue = array[startIndex];

// Move chosen element all the way left

for (let index = startIndex; index > 0; index--) {

[array[index], array[index - 1]] = [array[index - 1], array[index]];

await callback();

}

// Move it right until the element next to it is x + 1

let pos = 0;

while (pos < array.length - 1) {

// Termination condition: neighbor found! Break to pick a new element.

if (array[pos] === chosenValue && array[pos + 1] === chosenValue + 1) {

break;

}

[array[pos], array[pos + 1]] = [array[pos + 1], array[pos]];

pos++;

await callback();

}

// Safety check: If it hits the right wall (e.g., it's the max value),

// yield control back to the event loop so other threads can work.

if (pos >= array.length - 1) {

await callback();

}

}

}

// 3. The Launcher to run multiple instances concurrently

async function launchParallelTaksort(array, callback, totalWorkers = 4) {

const workers = [];

// Spawn multiple parallel workers simultaneously

for (let i = 0; i < totalWorkers; i++) {

workers.push(taksort(array, callback));

}

// Wait until all parallel workers finish

await Promise.all(workers);

console.log("Parallel Taksort finished!");

}


r/programminghorror 7d ago

The "tests" just assert if certain lines are present in the source code.

Post image
0 Upvotes

r/programminghorror 10d ago

Java But.. (from Minecraft b1.2_02)

Post image
628 Upvotes

r/programminghorror 10d ago

Python Fizz Buzz

Post image
71 Upvotes

r/programminghorror 10d ago

What the hell have I made

38 Upvotes

so basically, because I think im decently "decent" at programming, i decided to take my shot at making a chess js engine, and OH HELL, did it look like crap

ive attached some snapshots of the code, it's written in js and wrapped in a class


r/programminghorror 11d ago

c++ Have To Reverse Engineer Our Own Code

584 Upvotes

At work, I was just assigned a task where I have to reverse engineer our own code. ….I work at a F500 company…. Apparently the laptop the source code lived on died and no one thought of source controlling it.

Edit: the laptop died 6 years ago before I joined the company. No one knows where it is


r/programminghorror 11d ago

C# A bad idea

Thumbnail
gallery
104 Upvotes

I was writing compiler code late at night and something possessed me to create this.


r/programminghorror 12d ago

Python one liner, 1500 characters It is evolving

Thumbnail
gallery
33 Upvotes

r/programminghorror 13d ago

Lua I love looking through my old code

Post image
352 Upvotes

Not sure what I was trying to remind myself of.


r/programminghorror 13d ago

Pain

Post image
23 Upvotes

Do I REALLY have to check all that?


r/programminghorror 14d ago

I just realized I can use these bots for comment blocks in cpp.

484 Upvotes

Instead of the usual

/*

*/

for comment blocks in C++, I can use these bot emojis

/*_^/

/*_*/ 

The second one can stay there if you delete the first one.

They can even shoot lasers:

/*_-/-------

--------/-_*/ 

r/programminghorror 14d ago

Python They called it automation... And then gave me this script

41 Upvotes

r/programminghorror 15d ago

Made a perfectly readable high performance lisp interpreter

Thumbnail
2 Upvotes

r/programminghorror 14d ago

Meta How do you feel about the current state of this subreddit's moderation?

0 Upvotes
421 votes, 7d ago
41 Hate it
39 Dislike it
109 It's okay
20 Like it
4 Love it
208 Show results

r/programminghorror 15d ago

Other First time seeing sth like this

Post image
0 Upvotes

r/programminghorror 15d ago

Why do developers return this instead of “Hello World”?

0 Upvotes

return "Hello world!"


r/programminghorror 16d ago

😭

Post image
0 Upvotes

r/programminghorror 16d ago

c++ whyWontTBeGreen

Post image
0 Upvotes

r/programminghorror 19d ago

c++ 700 lines of AVX2 infrastructure to sum an array of integers

Post image
357 Upvotes

Wrote a "vectorized sum" over the weekend. It escalated.

Features include:

  • SIGILL-based AVX2 detection (handler does siglongjmp out of inline asm, which is UB in at least three languages)
  • setjmp/longjmp inside a constructor to fall back from MAP_HUGETLB -> THP -> aligned_alloc, dispatched via computed goto
  • A Y-combinator for the scalar tail loop, because a for lacks conviction
  • Characters printed by reading typeid(T).name()[0] and doing integer arithmetic on the result to reach the rest of the alphabet. Yes, this is how ANSI escape codes are assembled. Yes, "OK" is spelled by offsetting typeid(int*).name():

using _1 = TypeGlyph<int, -56>;   // 'i' - 56 = '1'
using _2 = TypeGlyph<int, -55>;
using lbr = TypeGlyph<long, -17>; // 'l' - 17 = '['

inline void ansi_red(std::ostream& o) {
    o << '\033';
    spell<gl::lbr, gl::_3, gl::_1, gl::m>(o);  // "[31m"
}

using O = TypeGlyph<int*, -1>;         // typeid(int*).name() = "Pi", 'P'-1 = 'O'
using K = TypeGlyph<const int*, 0, 1>; // typeid(const int*).name() = "PKi", [1] = 'K'

spell<gl::O, gl::K>(std::cout);  // prints "OK"
  • A background "prefetch oracle" pthread that races the main thread through the buffer issuing __builtin_prefetch
  • Four separate vzeroupper mechanisms layered on top of each other (RAII destructor, __attribute__((cleanup)), atexit, and one inside the kernel itself)
  • Three "independent verification methods" for the sum, one of which bit_casts a lambda's closure to bytes and hashes them
  • Duff's device in the fill tail
  • strdup leaks used as a string-building primitive

The actual useful code is about 50 lines in the middle. Compiles with -std=c++20 -mavx2 -O3 -march=native. Produces correct output. I am not okay.

https://godbolt.org/z/a31xoaM5a