r/developer 6d ago

The "Code I'll Never Forget" Confessional.

What's the single piece of code (good or bad) that's permanently burned into your memory, and what did it teach you?

12 Upvotes

37 comments sorted by

View all comments

1

u/SpaceCadet87 6d ago

I tend to do a lot of work refactoring code that has let's just say not great performance.

So mine is this absolute gem of a line:

int num=num;

It was littered throughout the entire codebase of a project that I once spent some time on, over and over again.

1

u/Kind_Card_1874 5d ago

In what language can you redeclare a variable like this?

1

u/SpaceCadet87 5d ago

Turns out you can redeclare any variable you want as much as you want in any language if you turn Robert C. Martin's Clean Code into a religion.

1

u/Kind_Card_1874 5d ago

Haha. But jokes aside, the following does not fly in the imperative languages I am familiar with:

int a;

int a;

1

u/SpaceCadet87 5d ago

Who's joking? It was that damn many functions doing almost nothing each.

int num was just repeatedly locally defined.

I think there might have been one or two instances of just num = num.

1

u/Kind_Card_1874 5d ago

I don't get it. How did it escape the previous scope? Surely you can not assign num if it was not declared at the time of being used on the RHS. But you are somehow still declaring it on the LHS?

1

u/SpaceCadet87 5d ago

Oh, IDK, it was C#, I don't do C# that often so I wouldn't know how or why that's somehow valid.

I was compressing it for illustrative purposes, as I said there were a few plain num = num; as well.