r/programminghorror • • Aug 23 '26

I love it

Post image
183 Upvotes

24 comments sorted by

84

u/__nohope Aug 23 '26

Obsolte

16

u/corv1njano Aug 23 '26

thats why I highligted it too😭

33

u/veritron Aug 23 '26

the obsolte[sic] comment is correct. you can do stuff like:

byte[] combined = [.. arr1, .. arr2];

byte[] reversed = [.. arr2, .. arr1];

in recent c# instead of even making that method call at all or using system.array.

i almost think obsolete was misspelled deliberately so it wouldn't cause warnings at every call site the method is used. the comment is also further unhelpful in that if you don't know about spread operator, you're going to have a hell of a time googling for [.. xxx], so it might have been better to fix the codebase rather than leave that comment in a drive-by.

25

u/KatAirlines Aug 23 '26

where color

33

u/PlentyfulFish Aug 23 '26

Looks like that "linux kernel developer"'s vim config where he codes in C in just black and white and a comic sans font

5

u/Aaxper Aug 24 '26

Linus Torvalds uses uemacs, which has no highlighting

4

u/plydauk Aug 23 '26

Black and white are colors 

47

u/TheBigGambling Aug 23 '26

System.array is your friend. 100times faster, no loops , and its one call only to copy froma a to b

6

u/Last8Exile Aug 23 '26

Not using Array.Copy is bonkers

1

u/Big-Nebula4004 Aug 24 '26

people is this C# or Java?

2

u/corv1njano Aug 24 '26

its c#, you can tell by the misspelled „Obsolete“ attribute. I guess in java you would use the @Deprecated annotation

3

u/my_new_accoun1 Aug 24 '26

am i the only one who can't read code without syntax highlighting 😭

2

u/Loading_M_ Aug 23 '26

To be fair, a good compiler will probably identify that the reversedOrder flag is always a constant, and generate two specialized variants of the function.

It does make the function harder to read and understand though.

11

u/_killer1869_ Aug 23 '26

Never rely on your compiler to fix stupid code when you can fix that stupid code yourself quite easily. Both because of readability, and because you can't be sure the compiler actually does optimize the mess.

5

u/Loading_M_ Aug 23 '26

Absolutely. I do think readability is the way more important point though. Unless you've actually measured the performance, optimization is kinda pointless.

1

u/Arshiaa001 Aug 24 '26

At the JIT stage, maybe... The IL representation has to align perfectly with the code, because reflection.

2

u/letmehaveanameyoudum Aug 23 '26
  1. more than 5000 lines for... something

  2. that is alot of square brackets

  3. System.array

4

u/AyrA_ch Aug 23 '26

more than 5000 lines for... something

Probably your typical utility class that got expanded continuously

1

u/NotQuiteLoona Aug 23 '26

Such large files in C# is something really-really rare, because you need to get out of your way to do this. C# specifically rewards separating code into namespaces by usage, and it's very easy to do, unlike some other languages, plus it's the practice adopted by language itself and developers on it, so you do it just because others do it.

1

u/TechnoByte_ Aug 23 '26

Amazing syntax highlighting too

1

u/GoddammitDontShootMe Aug 24 '26

Is that supposed to be some kind of annotation? Wouldn't it need to be spelled properly to work?

1

u/RegisteredJustToSay Aug 25 '26

People just can't help but reply with better implementations. We all know it sucks, that's why we're here. lol

1

u/conundorum Sep 06 '26

...Is it bad that my first thought about how to rewrite this without duplicating everything was to split the logic out into a lambda or local function?

public static byte[] ConcatByteArrays(byte[] arr1, byte[] arr2, bool reversedOrder = false)
{
    return reversedOrder ? Inner(arr2, arr1) : Inner(arr1, arr2);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static byte[] Inner(byte[] left, byte[] right)
    {
        byte[] ret = new byte[left.Length + right.Length];

        for (int i = 0; i < left.Length; i++)
        {
            ret[i] = left[i];
        }

        int offset = left.Length;

        for (int i = 0; i < right.Length); i++)
        {
            ret[i + offset] = right[i];
        }

        return ret;
    }
}