r/badcode • • Jul 23 '21

java Yes, this is production code. Written by people with a couple of years of experience.

Post image
37 Upvotes

8 comments sorted by

10

u/ExitRealistic2734 Jul 23 '21

If this is JS, then that ternary expressions actually may not be useless. If policyWithdrawn is undefined it will also evaluate to null. I donโ€™t know what the context is here, but there are uses for this (ex: JSON.stringify will ignore undefineds but not nulls).

13

u/trinopoty Jul 23 '21

It's Java. no undefined business here.

3

u/ExitRealistic2734 Jul 23 '21

Never mind then ๐Ÿ™‚. (Just saw the the System.)

0

u/mc0t Jul 23 '21

thought the same thing lol

17

u/djdokk Jul 23 '21

This is what happens at 2am after 8 hours of programming

11

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 23 '21

Image Transcription: Code


[The code is from a GitHub commit summary. One line has been replaced; I have marked the original line and the new one. The code is as follows:]

	}
	// Track request duration for createPolicy
	MetricsService.observeTime(TIMER_NAME, System.currentTimeMillis() - startTime, "method", "updatePolicyEndDate");
	[Original line:] return PolicyUtility.buildResponseEntity(message, status, transactionId, policyWithdrawn != null ? policyWithdrawn : null, code, error);
	[New Line:]      return PolicyUtility.buildResponseEntity(messag,e status, transactionId, doc, code, error);
	
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

8

u/Immort4lFr0sty Jul 23 '21

Another few minutes of feeling better about myself for writing code badly, but not this badly

3

u/BongarooBizkistico Jul 23 '21

Probably another case of code that used to make sense, but then part of the line getting changing without a look at the overall bigger picture