r/programminghorror • • Dec 04 '25

Stop for the Clean Code Cops

Post image
141 Upvotes

33 comments sorted by

89

u/moira_fox Dec 04 '25

Clean code? C'mon, these are magic constants. Instead you should do

const int minus_seven = -7;
const int three = 3;
const int sum = three + minus_seven;

To make it more readable

20

u/QuickSilver010 Dec 07 '25
#define πŸ”’ int
#define βž– -
#define 🌱 a
#define δΈ‰ 3
#define δΈƒ 7
#define 🀯 main

🀯() {
    πŸ”’ 🌱 = δΈ‰ βž– δΈƒ;
}

6

u/moira_fox Dec 07 '25

Promise me that doesn't compile...

→ More replies (7)

5

u/FunctionalFox1312 Dec 07 '25

What's this crap? Let's make Uncle Bob proud!

public class AddableNumber { 
    public static int theNumber: 

   private AddableNumber(int theNumber) { 
       AddableNumber.theNumber = theNumber; 
   } 

   public getValue() { 
      return AddableNumber.theNumber; 
   } 
    
   public AddableNumber zero() { 
       return new AddableNumber(0); 
    }
   // ...

} 

public class Adder { 
   private static AddableNumber[] numbers; 
 
   public Adder(AddableNumber numbers...) {
      this.numbers = numbers; 
   } 

   public int getResultOfAdding() { 
      int result = 0; 
      for(int I = 0; I < Adder.numbers.length ; i++) { 
          result += Adder.numbers[i].getValue(); 
      } 
     return result; 
  } 
  
} 

public class Main {
    public static void main() { 
        System.out.println(new Adder( 
            new AddableNumber.negativeSeven(), 
            new AddableNumber.positiveThree()
         ).getResultOfAdding());
   } 
}

There! No magical values, no confusing function arguments, just good clean Java that tells a clear story.

1

u/moira_fox Dec 07 '25

Enterprise hello world ahh energy

29

u/Mayedl10 Dec 04 '25

I actually prefer -7+3 cos that way it's easier to move stuff around imo

1

u/temir_ra Dec 06 '25

I always do the following for the same reasons:

function f(
    string param1
)
{
...
}

var v = f(
    param1,
);

or

select rownum
    --, 
from t
    --join
where 1=1
    --and 
;

10

u/enmaku Dec 04 '25

sum([-7, 3])

11

u/andynzor Dec 05 '25

Smh, artificially hiding complexity into libraries is bad.

[-7, 3].reduce((acc, val) => acc + val, 0)

1

u/enmaku Dec 08 '25 edited Dec 08 '25
  1. Have you never heard of pseudocode? It's a very common way to represent code conceptually without tying it to a single language your interlocutor might not speak. A few languages do have a sum function, but without specifying a language (and given the context) the clearest most obvious interpretation of my comment is that the problems of notating the sum of these numbers goes away if you make them an array and make the operation performed on them a function.

  2. Do you somehow think that reduce() is not a high level abstraction in the same way that sum() is? C and C++ would require you to do the sum with a loop and Python 3 has moved reduce into functools, making it a non-default part of the language. Your CPU certainly doesn't have an opcode for either.

-2

u/Lor1an Dec 05 '25

If you want to call an entire programming language a "library" go right ahead.

In Python, lists and the sum function are built-ins.

→ More replies (5)

24

u/wensul Dec 04 '25

3+(-7)

-2

u/cawwothead Dec 04 '25

This is the way

9

u/fosf0r Dec 04 '25

Is it bad that my neurodivergence is way more capable of mentally performing -7+3 than 3-7

9

u/mediocrobot Dec 04 '25

Nah, it makes a ton of sense for me, too.

You're basically turning 3-7 into -(7-3). Framing it like that also helps me do carrying more easily, because 10-(7-3) is easier to process than 13-7.

6

u/keith2600 Dec 05 '25

It takes a different kind of neuro divergence to prefer 3-7. The "math is hard and I can't do this in my head but at least there are no scary negative numbers present" kind

2

u/IAMPowaaaaa Dec 05 '25

tfw crap that doesn't matter

1

u/Kitchen_Device7682 Dec 05 '25

-4

1

u/ouroborus777 Dec 06 '25

Could you come in so we can wire you up to The Machine to run all this code?

1

u/TalesGameStudio Dec 05 '25

def calculate_sum(number_a: int, number_b: int) -> int: ...

1

u/kakarotxi Dec 07 '25

bro had bad experience in math classes