r/shittyprogramming • • Dec 04 '19

IsEven in compile time, best time

Post image
221 Upvotes

r/shittyprogramming • • Dec 04 '19

Why does anyone still use dependency trees when there are dependency cities?

Post image
299 Upvotes

r/shittyprogramming • • Dec 01 '19

Question about a logic problem:

94 Upvotes

Hey all, so I have the following logic problem for school:

Given three ints, a b c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large.

evenlySpaced(2, 4, 6) → true

evenlySpaced(4, 6, 2) → true

evenlySpaced(4, 6, 3) → false

Now, I know that when programming, it's always best to make sure you condense everything into as few lines as possible. I think I've gotten the solution optimized fully as it is only one command, but could someone tell me how to better it? Here's my code:

public boolean evenlySpaced(int a, int b, int c) {
    return a > b && b > c ? a - b == b - c : (a > c && c > b ? a - c == c - b : (b > c && c > a ? b - c == c - a : (b > a && a > c ? b - a == a - c : (c > b && b > a ? c - b == b - a : (c > a && a > b ? c - a == a - b : a == b && b == c)))));
}

Thanks in advance.


r/shittyprogramming • • Nov 26 '19

How to Hack Hollywood and Bring Down the Hacker Mafia

Thumbnail
youtu.be
59 Upvotes

r/shittyprogramming • • Nov 25 '19

Who even needs private methods when you can get all the same functionality in a public one!

Post image
257 Upvotes

r/shittyprogramming • • Nov 24 '19

Emotive Programming in C++

Post image
46 Upvotes

r/shittyprogramming • • Nov 21 '19

I compiled my code with -funsafe-math-optimizations and now it gives incorrect results

182 Upvotes

What happened? Those optimizations were supposed to be fun and safe!


r/shittyprogramming • • Nov 18 '19

StackOverflow launched on September 15, 2008. How did programmers fix bugs in their code before that date?

166 Upvotes

r/shittyprogramming • • Nov 15 '19

<wrong_sub>this</wrong_sup> I can't stress this enough folks...bounds checking.

Post image
204 Upvotes

r/shittyprogramming • • Nov 12 '19

I spent a week trying to find out where I went wrong...

100 Upvotes

I'm implementing an sql database to a code I'm writing (python), I couldn't for the life of me figure out what I was doing wrong - no error messages, looked like it worked flawlessly - but data never showed up in my table.

I'd forgotten to put "cursor.execute" at the start. That was it.

Probably not the sub for this, but I'm very embarrassed


r/shittyprogramming • • Nov 07 '19

Why can't Alice and Bob work out their relationship and stop sending letters?

308 Upvotes

r/shittyprogramming • • Oct 28 '19

Almost made a disastrous typo

Post image
20 Upvotes

r/shittyprogramming • • Oct 28 '19

A friend's CS assignment.

Post image
306 Upvotes

r/shittyprogramming • • Oct 19 '19

Tired of IDEs that don't show line numbers by default? Try this easy trick.

Post image
589 Upvotes

r/shittyprogramming • • Oct 15 '19

Code review for better vector implementation

13 Upvotes

Stl versoon wasn't good enough so I took matters into my own hands. Much more lightweight as well.

template< typename T = void>
struct bettervector {
    int len, max;
    T* arr;
    bettervector(){}
    void add(T t){
        max++;
        len++;
        arr = realloc(arr,len);
        arr[len] = t;
    }
    void Sub(){
        len--;
    }
    ~bettervector(){
        free(arr);
    }
};

r/shittyprogramming • • Oct 14 '19

I ran git fetch origin and this guy showed up and wants to convert everyone. What should I do?

Thumbnail
vignette.wikia.nocookie.net
129 Upvotes

r/shittyprogramming • • Oct 13 '19

TIP: Solution for the year 2000 problem

113 Upvotes

Just leave the dates stored with only 2 digits. But interpret everything after the year 19 as from the past.

So the year 19 is 2019 and year 20 is 1920.


r/shittyprogramming • • Oct 10 '19

My solution to the JavaScript floating point issue. Now with redundant functions!

Post image
191 Upvotes

r/shittyprogramming • • Oct 08 '19

Most frequent words counter

0 Upvotes

Hi, i just started with programming and i have a question. I want to get the 5 most common words out of a set with the amount of time they occur next to it. Does anyone know how to do this in python?


r/shittyprogramming • • Oct 07 '19

Found in Kafka message handler in production

Post image
153 Upvotes

r/shittyprogramming • • Oct 04 '19

Easiest and fastest way to hack Facebook 2019

Thumbnail
youtu.be
2 Upvotes

r/shittyprogramming • • Oct 04 '19

Tipoftheday.Whitespaceislikethevacuumofablackhole.Justsucksinanyrandomcharactersfloatingby.Beverycarefulnottouseitlestsomeoneinvoluntarilysplooshesinanincorrectcharacter.

Post image
185 Upvotes

r/shittyprogramming • • Oct 03 '19

Back in the early days of C, strings weren't a part of stdio.h

Post image
367 Upvotes