/r/programminghorror
Share strange or straight-up awful code.
RULES:
All posts MUST show terrible code. There are no exceptions.
No Editor Themes - If it's just your editor that looks bad, it doesn't belong here.
No Advertisement Code. This is generally written by people in marketing who only know what "code" looks like from other ads. It's not real code, so it doesn't belong.
No Student Code. Yes, they're learning, but bad code is part of the process.
No Generated Code. If it's minified JS, generated XML, or what have you, we don't want it here. Yes, the YouTube homepage has an extra right-angle bracket. We know.
No Asking for Help. Go to r/learnprogramming. What are you doing here?
No Spamming/Advertising. We don't care about your shitty Youtube video or new crypto that will "change the world".
Be Nice. No hate speech of any kind is allowed, as well as generally being a jerk. Talk about the code, not eachother.
No Direct Contact of the Mods. Please use the modmail, we don't want to be contacted directly.
Please direct stories without code to /r/talesfromtechsupport, and programming questions to /r/learnprogramming
Programming Horror is where developers come together to revel in the idiocy of our peers.
This subreddit is meant for sharing funny programming related stories and strange or straight-up awful code.
For the sake of not being mauled by rabid lawyer bears, please make sure to anonymize your stories - changing the names of people and companies.
For code examples, indent all your lines with 4 spaces to make it more readable:
foo = 'bar'
Sister subreddits
/r/programminghorror
Updating some stuff , suddenly seeing error massages with : what about this code 🤣🤣🤣🤔😐
/**
* Convert an array of bytes to a string
* @param In byte array values to convert
* @param Count number of bytes to convert
* @return Valid string representing bytes.
*/
[[nodiscard]] inline FString BytesToString(const uint8* In, int32 Count)
{
FString Result;
Result.Empty(Count);
while (Count)
{
// Put the byte into an int16 and add 1 to it, this keeps anything from being put into the string as a null terminator
int16 Value = *In;
Value += 1;
Result += FString::ElementType(Value);
++In;
Count--;
}
return Result;
}
I ran across this while processing data from a network source. I assumed there was a built-in function to convert bytes to FString, and sure enough, there is! It's just not actually useful, since you have to go through and decrement each character afterwards while also cleaning it up.
I've been scratching my head trying to find a reason you might actually want to do this.
Hi to everyone, myb I'm in the wrong category but i will try , I'm looking for someone who can help me with a macro (i can pay for it !!)
"No one is quite sure what this is for"
As per current trends in the market there has been less and less requirements for developers and more for AI is it good enough to switch roles as of now ? A little background have an experience of about 4.3 years as a full stack Java developer my current tech stack includes frameworks like hibernate, spring, MVC, JPA, React js and for db it’s been MySQL current qualifications are BE in computer engineering and currently perusing MTech in computer engineering… recently have even experimenting with some cloud tech too like Linux and RHEL in deployment without CI/CD. I have previously worked upon python so it would not be much of a trouble to pick up from that end for AI/ML I mean … seems like there’s much to do on that front or either ways companies think too much of that tech stack any advice would be appreciated my MTech is about to end so I need to figure my tech stack before applying for another job.
How to enable Cosign image signing and validation in Kubernetes, continuous validation using policies, and the analysis of artifacts in your repository.
Implementing Cosign Image Validation in K8s
How to enable Cosign image signing and validation in K8s, continuous validation using policies, and the analysis of artifacts in your repository.
https://medium.com/@rasvihostings/implementing-cosign-image-validation-in-gke-ba803f6f623c
A Python decorator that allows switching function calls behavior. When you pass a string argument to a function, it's interpreted as the target function name, while the original function name becomes the argument.
pip install git+https://github.com/krakotay/function-switcher.git
from function_switcher import switch_call
@switch_call
def main():
hello('print') # Prints: hello
length = mystring('len') # Gets length of 'mystring'
print(f"Length of 'mystring' is: {length}") # Length of 'mystring' is: 8
main()
The Problem: Print numbers from 1 to 100. Replace multiples of 3 with "Fizz," multiples of 5 with "Buzz," and multiples of both with "FizzBuzz."
fizzbuzz(n) => {
context = n; // Context explicitly defines the current number
result = case {
context % 15 == 0: "FizzBuzz", // Divisible by both 3 and 5
context % 3 == 0: "Fizz", // Divisible by 3
context % 5 == 0: "Buzz", // Divisible by 5
_: context // Otherwise, the number itself
};
result; // Output the result
};
sequence(1, 100) |> map(fizzbuzz); // Apply fizzbuzz to each number in the sequence
Why This Works:
sequence
generates numbers, and map
applies fizzbuzz
to each.The Problem: Find all prime numbers up to n
.
sieve(numbers) => {
context = numbers; // Current list of numbers
prime = head(context); // First number is the current prime
filtered = tail(context) |> filter(x => x % prime != 0); // Filter multiples of the prime
[prime] + sieve(filtered); // Recursively add the prime and process the rest
};
prime_sieve(n) => sieve(sequence(2, n)); // Generate primes from 2 to n
Why This Works:
The Problem: Combine two hashmaps, resolving key collisions by overwriting with the second map's value.
merge(hashmap1, hashmap2) => {
context = (hashmap1, hashmap2); // Pair of hashmaps
merged = context.0 |> fold((key, value), acc => {
acc[key] = value; // Insert key-value pairs from the first map
acc;
});
context.1 |> fold((key, value), merged => {
merged[key] = value; // Overwrite with values from the second map
merged;
});
};
Why This Works:
The Problem: Sort an array using the divide-and-conquer paradigm.
quicksort(array) => {
case {
length(array) <= 1: array, // Base case: array of length 0 or 1 is already sorted
_: {
pivot = head(array); // Choose the first element as the pivot
left = tail(array) |> filter(x => x <= pivot); // Elements less than or equal to the pivot
right = tail(array) |> filter(x => x > pivot); // Elements greater than the pivot
quicksort(left) + [pivot] + quicksort(right); // Concatenate the sorted parts
}
}
};
Why This Works:
The Problem: Compute the n
-th Fibonacci number.
fibonacci(n) => {
fib = memoize((a, b, count) => case {
count == 0: a, // Base case: return the first number
_: fib(b, a + b, count - 1); // Compute the next Fibonacci number
});
fib(0, 1, n); // Start with 0 and 1
};
Why This Works:
(a, b, count)
carries all required state.The Problem: Compute n!
(n factorial).
factorial(n) => case {
n == 0: 1, // Base case: 0! = 1
_: n * factorial(n - 1) // Recursive case
};
Why This Works:
n
is explicitly passed down.The Problem: Generate the sequence for the Collatz Conjecture starting from n
.
collatz(n) => {
context = n;
sequence = memoize((current, steps) => case {
current == 1: steps + [1], // Base case: terminate at 1
current % 2 == 0: sequence(current / 2, steps + [current]), // Even case
_: sequence(3 * current + 1, steps + [current]) // Odd case
});
sequence(context, []); // Start with an empty sequence
};
Why This Works:
current
tracks the sequence value, and steps
accumulates results.The Problem: Compute the greatest common divisor of two integers a
and b
.
gcd(a, b) => case {
b == 0: a, // Base case: when b is 0, return a
_: gcd(b, a % b); // Recursive case: apply Euclid’s algorithm
};
Why This Works:
(a, b)
explicitly carries the state.These classic problems illustrate the essence of B+: computation as algebra. By stripping away unnecessary abstractions, B+ allows problems to be solved elegantly, highlighting the simplicity and universality of its design.
Here’s why B+ parameterization differs fundamentally:
In B+, structures (like ex-sets, sums, and products) are reused and extended contextually rather than instantiated from a generic template. This means:
Option = Sum(None: {}, Some: Product(Value: {}))
Here, Some
can hold a value of any type. Rather than "parameterizing" Option
with a type (Option<T>
in other languages), B+ allows the context to define what kind of Value
is valid.
Rather than parameterizing objects, B+ encourages defining reusable structural patterns. These patterns act like templates but are implicitly resolved through composition.
KeyValue = Product(Key: {}, Value: {})
KeyValue<K, V>
(generic parameterization), you adapt this structure by defining Key
and Value
in the specific context where it’s used.
StringToNumber = KeyValue(Key: {String}, Value: {Number})
There’s no abstract type-level substitution happening. Instead, you specialize the structure by reinterpreting its fields in the immediate context.
Constraints in B+ enable implicit customization of structures. Rather than parameterizing a type with restrictions (e.g., List<T: Number>
), B+ introduces constraints directly into the structure definition, making the type context-aware.
List = Sum(Empty: {}, Node: Product(Value: {}, Next: List))
Add a constraint in context:
NumberList = List where Value: {Number}
List
with a type T
, you constrain its Value
field to a specific set ({Number}
).In B+, parameterization is replaced by contextual growth, where:
Tree = Sum(Empty: {}, Node: Product(Value: {}, Left: Tree, Right: Tree))
Adapt in context:
BinarySearchTree = Tree where Value: Ordered
Instead of explicitly parameterizing Tree
with an Ordered
type, the context imposes constraints that propagate as the structure grows.
The B+ paradigm avoids explicit parameterization for several reasons:
Product
and Sum
) and adapt them directly in use contexts, rather than creating parameterized blueprints.B+ moves away from traditional parameterization by embracing:
This approach is consistent with B+’s design philosophy, prioritizing clarity, minimalism, and adaptability over formal parameterization mechanics.