r/badcode • • Jul 08 '19

c# While reviewing code today...

Post image
696 Upvotes

57 comments sorted by

116

u/campbellm Jul 08 '19

I'm almost tempted to ask what the unit test looks like

19

u/andesz Jul 08 '19

i'll give an update when that hits the VCS :D

138

u/Kidiri90 Jul 08 '19

unit test

What's that?

55

u/SanityNotFound Jul 08 '19

Well, it.. you know, tests.. units.

43

u/SheepLinux Jul 08 '19

instructions unclear; dick stuck in toaster...

22

u/overkill Jul 08 '19

Spoken like a true QA.

1

u/GideonMax Jan 02 '20

A unit test is code whose purpose is to test code you made.

For example, if you made a function that multiplies a number by two, the unit test will feed the function some numbers and check the outputs

22

u/iamthemisionman Jul 08 '19

Diver.Url == Driver.Url;

17

u/jarfil Jul 08 '19 edited Dec 02 '23

CENSORED

9

u/christian-mann Jul 09 '19

you mean GotToUrl(url);

5

u/mfb- Jul 09 '19

It checks if Driver.Url == Driver.Url.

38

u/[deleted] Jul 08 '19

What in the goddamn fuck...

8

u/andesz Jul 08 '19

my reaction exactly :D

10

u/RandomAnalyticsGuy Jul 08 '19

Was this code offshored?

20

u/andesz Jul 08 '19

no, it was our tech lead...

-5

u/RandomAnalyticsGuy Jul 08 '19

Sounds like there isn’t enough money in the budget to pay a proper tech lead, or you need a new tech lead.

0

u/[deleted] Jul 08 '19

[deleted]

11

u/andesz Jul 08 '19

Sure, but I found it a good fit for this sub

2

u/RandomAnalyticsGuy Jul 08 '19

Part of me is being facetious but come on.

4

u/[deleted] Jul 08 '19

This is what happens when someone is constantly interrupted while trying to do something easy.

4

u/fletch3555 Jul 08 '19

Insert complaints about open office concept...

0

u/[deleted] Jul 08 '19

[deleted]

1

u/fletch3555 Jul 08 '19

Is it a single-use office where you keep the door open?

0

u/nakatapt Jul 08 '19

Looks like he needs to see the real TechLead on YouTube

25

u/ign1fy Jul 08 '19

A real IDE would have put squiggles all over that.

4

u/Rafael20002000 Jul 08 '19

May used notepad or vim

30

u/myevillaugh C# Jul 08 '19

Looks more like a bug/type-o than bad code.

8

u/bluepoopants Jul 08 '19

Yeah that's what i thought. Surely its supposed to be Driver.url = url.

8

u/xman40100 Jul 08 '19

Who took this picture of me coding at 1 am

6

u/neotecha Jul 08 '19

The first rule of Tautology Club...

7

u/hiljusti Jul 08 '19

...is the first rule of Tautology Club.

9

u/angusmiguel Jul 08 '19

got to url ???? whaaat

6

u/nakatapt Jul 08 '19

Game of Thrones to URL, that's why

8

u/MCWizardYT Jul 08 '19

It's a typo right?

Driver.Url = url;

Should be how this function works

4

u/[deleted] Jul 08 '19

Ahhhhhh the good ole Selenium wrapper. Almost there, but not quite. :D

2

u/NahroT Jul 08 '19

Just looks like two typos honestly, I bet the author's intention was: GoToUrl(url) driver.url = url

3

u/unforgiven1909 Jul 08 '19

the name is the best part...

1

u/Bourdain179 Jul 08 '19

Why make inline 1 line code when you can refactor it into a function that doesn't do anything (does it refresh the page?)

1

u/wigitorax Jul 08 '19

Very clever. He or She deserves a salary raise :D

1

u/xhable Jul 08 '19

I've done this a good few times

1

u/konshensx Jul 08 '19

Jesus Christ that's Jason bourne

1

u/[deleted] Jul 08 '19

Hence proved πŸ˜‚πŸ˜‚

1

u/MyMessageIsNull Jul 08 '19

Just looks like a dumb typo/brainfart to me. I try to catch my such errors before they go to a code review, but I can't say I'm always successful.

1

u/[deleted] Jul 08 '19

Man I love the "url" part. Idk why XD

1

u/[deleted] Jul 09 '19

I suspect somebody typed Url with the capitalized 'U', got an undeclared variable error, had 5pm brain and didn't look, and took either a weird IDE autocorrect suggestion are "fixed" it by prepending the Class name (5pm brain let's you get away with this crap). Or most likely he/she reversed the assignment and forgot to change the RH side.

0

u/[deleted] Jul 08 '19

[deleted]

8

u/andesz Jul 08 '19

sadly, this does nothing, but i can't edit the post :/

59

u/botle Jul 08 '19

As someone that doesn't do C#, I find that completely terrifying.

36

u/pipe01 Jul 08 '19

You can do horrifying stuff in any language, C# just makes this a bit easier

6

u/[deleted] Jul 09 '19

You can have setters with side effects in like any language.

11

u/jarfil Jul 08 '19 edited Dec 02 '23

CENSORED

7

u/Tyfyter2002 Jul 08 '19

Properties in C# are basically a midpoint between fields and methods (with a few added benefits from what I've heard) so you can just use them for the intended purpose, or use them to replace any method with one of the following (as long as you don't intend to use it as a delegate): a void return type (set, probably with an array of objects), no arguments (get, also probably the intended purpose), or multiple arguments and a non-void return type (set, although it functions more similarly to using reference arguments).

3

u/christian-mann Jul 09 '19

You could do that in Python, C++, and probably Javascript as well.

21

u/shrekthethird2 Jul 08 '19

True, but if that is so, the function's "url" argument is pointless and confusing as hell. It could be that this signature was forced upon the implementer, but then I'd expect a clarifying (and apologetic) comment. All in all, it's either stupid or evil, or both.

2

u/[deleted] Jul 08 '19

[removed] β€” view removed comment

8

u/TinyBreadBigMouth Jul 08 '19

They mean that Driver.Url could be a property.

1

u/[deleted] Jul 08 '19

[removed] β€” view removed comment

1

u/AutoModerator Jul 08 '19

Hello jdlyga,

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not not have universal support for this syntax and your comment will render as broken gibberish on old reddit and some mobile apps.

Please edit the comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.