Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Cerberus911 posted:

Finally something to contribute.

I can one-up that.

An ASP.NET MVC3 web site I'm working on is littered with this

code:
public ActionResult DoSomething(string SaveMode)
{
  bool saveMode = SaveMode != null && SaveMode == "true" ? true : false; 
  
}
Which is horrible on all sorts of levels.

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

JawnV6 posted:

Slammer had to do the same thing. Didn't fix it up after, but it's pretty common to craft a payload to avoid a null byte.

Even better is crafting UTF-8 shellcode: http://www.phrack.org/issues.html?issue=62&id=9

Haven't seen anyone crafting shellcode that has the same statistical characteristics as human language which would be pretty nifty.

Bunny Cuddlin
Dec 12, 2004

Cerberus911 posted:

Finally something to contribute.

The following is from a dev that has been around for over 6 months, and apparently has over 10 years of experience.

code:
 mainTitleContainer.visible = (mainTitleContainer.visible == false) ? true : false; 
I've been going through a refactor of our app and the above just made me stop an go for a walk. All the features he has added are copy-paste of existing code with slight modifications.

This is just a toggle. sure, container.visible = !container.visible probably would've been cleaner but maybe he's just used to ternary operators and thought it was more explicit this way.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bunny Cuddlin posted:

This is just a toggle. sure, container.visible = !container.visible probably would've been cleaner but maybe he's just used to ternary operators and thought it was more explicit this way.

What's more explicit than "thing = !thing"? Using a conditional operator just makes it take an extra 5 seconds to parse.

That Turkey Story
Mar 30, 2003

Ithaqua posted:

What's more explicit than "thing = !thing"? Using a conditional operator just makes it take an extra 5 seconds to parse.

Yeah, I'm with you, but I guess some people are not. I've seen stuff like this a few times, specifically conditionals that are equivalent to a single && operation or || operation. One time after updating such code to just use &&, someone saw the commit (I think the person who originally wrote the code, though I never checked) and told me that the conditional was used in order to be more explicit and so he changed it back. I don't at all see how it makes things more clear and I agree that it makes things less clear since you're swapping out a very fundamental binary operation for a ternary operation with a constant argument. Maybe at the moment you're writing it, your train of thought brought you to the more convoluted ?: operation (I think we've all done something along those lines at some point), but that doesn't mean that further reducing the code is a bad idea.

Bunny Cuddlin
Dec 12, 2004

That Turkey Story posted:

Yeah, I'm with you, but I guess some people are not. I've seen stuff like this a few times, specifically conditionals that are equivalent to a single && operation or || operation. One time after updating such code to just use &&, someone saw the commit (I think the person who originally wrote the code, though I never checked) and told me that the conditional was used in order to be more explicit and so he changed it back. I don't at all see how it makes things more clear and I agree that it makes things less clear since you're swapping out a very fundamental binary operation for a ternary operation with a constant argument. Maybe at the moment you're writing it, your train of thought brought you to the more convoluted ?: operation (I think we've all done something along those lines at some point), but that doesn't mean that further reducing the code is a bad idea.

Yeah, I'm not saying I think it's a great way to express that, I'm just saying I understand where it comes from. I wouldn't call it a horror though.

Marta Velasquez
Mar 9, 2013

Good thing I was feeling suicidal this morning...
Fallen Rib

That Turkey Story posted:

Yeah, I'm with you, but I guess some people are not. I've seen stuff like this a few times, specifically conditionals that are equivalent to a single && operation or || operation. One time after updating such code to just use &&, someone saw the commit (I think the person who originally wrote the code, though I never checked) and told me that the conditional was used in order to be more explicit and so he changed it back. I don't at all see how it makes things more clear and I agree that it makes things less clear since you're swapping out a very fundamental binary operation for a ternary operation with a constant argument. Maybe at the moment you're writing it, your train of thought brought you to the more convoluted ?: operation (I think we've all done something along those lines at some point), but that doesn't mean that further reducing the code is a bad idea.

I worked on a project years ago where one of the guys on the project couldn't remember the difference between the ~ and ! operators in C. Instead, he opted to not use either of them "for clarity."

code:
x = (x == 0);
Later, when the person in charge of the project was promoted, this guy was put in charge because he was the most senior guy on the team. He mandated that ALL inversions be done this way so it is clear when he did code reviews.

He also read that compiler optimizations can cause runtime errors and decided that they should be disabled, which is great when you are working on an embedded micro.

It was not a fun time.

TheresaJayne
Jul 1, 2011

Cerberus911 posted:

Finally something to contribute.

The following is from a dev that has been around for over 6 months, and apparently has over 10 years of experience.

code:
 mainTitleContainer.visible = (mainTitleContainer.visible == false) ? true : false; 
I've been going through a refactor of our app and the above just made me stop an go for a walk. All the features he has added are copy-paste of existing code with slight modifications.

As my Fave author says

quote:

The way you determine Good code from Bad code is WTF's per minute

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
^^^^ Yeah I've seen that before, love it. Who was that, Atwood?

JawnV6 posted:

Slammer had to do the same thing. Didn't fix it up after, but it's pretty common to craft a payload to avoid a null byte.

Oh, I know, I know. I just really love the idea of Insomniac writing a professional payload for their own software.

I guess maybe this happens more than I thought? :stare:

Look Around You
Jan 19, 2009

Zaphod42 posted:

^^^^ Yeah I've seen that before, love it. Who was that, Atwood?


Oh, I know, I know. I just really love the idea of Insomniac writing a professional payload for their own software.

I guess maybe this happens more than I thought? :stare:

I just love that the thought process was probably like "poo poo we need to patch this and we have no patch code --- wait some loving idiot used strcpy to fill the EULA string that we pull from online... It's a static buffer too!! poo poo maybe we can use it to use a buffer overflow attack on our own code!!! *hacking away* OH poo poo IT WORKED!!! Now let's blog about how loving stupid we were on multiple levels because it's a loving hilarious story!"

e: seriously literally every part of that story is loving gold.

Look Around You fucked around with this message at 08:29 on Jun 27, 2013

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
To be fair, that was a game on PS2, where the network consisted of a separate adapter that like 1% of customers bought, with basically no OS support.

it is
Aug 19, 2011

by Smythe

it is posted:

code:
def can_do_x_to_y:
     @returns: a list of y's that can't have x done to them
Super job, guys.

Haha I remember this company. They're a division of a very large hardware company where I was nominally a QA intern. They had the entire team of 7 people and me, as well as using a software engineer with another team for the UI design, spending the entire time I was there writing the world's simplest CRUD app. It's just a scheduler; it scans the network for hardware and lets you reserve it for a certain amount of time or indefinitely. That's really about it. The company poured probably hundreds of thousands of dollars into developing it instead of using some much much much cheaper solution for some reason.

Highlights:
The fact that they had a bunch of QA folks writing software instead of doing actual QA, for one.
The QA department had practically no automated testing around their own code. I, the intern, was responsible for writing all the unit tests. I don't think they had any integration testing at all. You'd think the QA department would know better.
The entire webapp was on a single page (which is cool I guess, some webapps really are just one page), and all the javascript was one file. A 1000-line, uncommented file. I had to modify this file without actually knowing any javascript; I suspect the author didn't know any either.
I was reporting bugs no one could reproduce. Turns out the code was fine (in a sense); the problem was the computer they gave me to work with was so slow that I was reporting bugs that depended on being able to click on things before the AJAX had finished.

I wish I worked the other internship I had an offer from, where the guy I was dating (who was, 100% coincidentally, friends with the person who interviewed me which no one knew until after I had the offer letter in hand) told me my interviewer thought I was cute and was Facebook stalking me afterwards.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

it is posted:

You'd think the QA department would know better.

It is the weirdest loving thing. When I'm writing code as "test", I'm all over exhaustive testing, finding every possible way to break something, thorough automation, getting mad about unit tests, etc.

The minute I put on my "dev" hat? Hell, it works on my machine, ship it.

Dren
Jan 5, 2001

Pillbug

it is posted:

Highlights:
The fact that they had a bunch of QA folks writing software instead of doing actual QA, for one.
The QA department had practically no automated testing around their own code. I, the intern, was responsible for writing all the unit tests. I don't think they had any integration testing at all. You'd think the QA department would know better.

QA is a cost-center.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Dessert Rose posted:

It is the weirdest loving thing. When I'm writing code as "test", I'm all over exhaustive testing, finding every possible way to break something, thorough automation, getting mad about unit tests, etc.

The minute I put on my "dev" hat? Hell, it works on my machine, ship it.

Unit tests should be the developers' responsibility as well as QA. Perhaps even more than QA. I treat unit tests as production code. If they're failing, it's an issue that needs to be fixed before anything is checked in. And fixing the issue isn't just "comment that poo poo out", either.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Ithaqua posted:

Unit tests should be the developers' responsibility as well as QA. Perhaps even more than QA. I treat unit tests as production code. If they're failing, it's an issue that needs to be fixed before anything is checked in. And fixing the issue isn't just "comment that poo poo out", either.

Yeah, that's what I meant by getting mad about them - it's an uphill battle to get devs to write them a lot of the time.

Thom Yorke raps
Nov 2, 2004


Java code, everything is a boolean
code:
boolean isFoo = !(isBar ^ isJustFucked);
Had a 10 minute discussion with the senior developer who wrote this when I wanted to change it to
code:
boolean isFoo = isBar == isJustFucked; 
I ended up having to draw the truth tables, and he still told me I had to retest all the code before making that one change. This at a place where running the tests took over an hour, which is a WTF all by itself.

coaxmetal
Oct 21, 2010

I flamed me own dad
the code around that must be fascinating if it made more sense to negate an xor than to check equality.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Funnily enough, in the original version the parentheses weren't necessary - !isBar ^ isJustFucked is equivalent.

Zombywuf
Mar 29, 2008

So we do website archiving, we crawl a website and take a copy of everything we find. We just found a totally unsecured webadmin.php page with delete functionality. Fortunately for us the crawler is not quite clever enough to submit the forms to delete pages without human intervention* but drat that could have gone very very wrong.


* It can submit forms in general but taking a particular sequence of actions like "select delete from the drop down, mark the checkbox then submit" require deliberate scripting.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
A web spider that submits POST requests is the real horror.

KaneTW
Dec 2, 2011

It's pretty common for more sophisticated crawlers.

tef
May 30, 2004

-> some l-system crap ->

Jabor posted:

A web spider that submits POST requests is the real horror.

No, it's websites that you browse with POST that are the horror.

qntm
Jun 17, 2009

KaneTW posted:

It's pretty common for more sophisticated crawlers.

Then it's a pretty common horror?

Zombywuf
Mar 29, 2008

The web is the real horror.

fritz
Jul 26, 2003

Jabor posted:

Funnily enough, in the original version the parentheses weren't necessary - !isBar ^ isJustFucked is equivalent.

I don't care how much of a horror it is, if there's more than one Boolean operator in an expression the parentheses are going in.

Sang-
Nov 2, 2007

fritz posted:

I don't care how much of a horror it is, if there's more than one Boolean operator in an expression the parentheses are going in.

100% THIS. I can remember & binds more tightly than |, but once you introduce xor and everything like that I have no clue.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Ranma posted:

Java code, everything is a boolean
code:
boolean isFoo = !(isBar ^ isJustFucked);
Had a 10 minute discussion with the senior developer who wrote this when I wanted to change it to
code:
boolean isFoo = isBar == isJustFucked; 
I ended up having to draw the truth tables, and he still told me I had to retest all the code before making that one change. This at a place where running the tests took over an hour, which is a WTF all by itself.

Write a test that loads up a jpeg of the truth table that you drew for him.

Dietrich
Sep 11, 2001

Strong Sauce posted:

Write a test that loads up a jpeg of the truth table that you drew for him.

Seriously, a unit test for this would have taken all of 2 minutes to write and give you pretty indisputable evidence.

That's generally the approach I take when telling someone their practice is needlessly complicated.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Zombywuf posted:

The web is the real horror.

Truer words were never spoken. :catstare:

raminasi
Jan 25, 2005

a last drink with no ice

Dietrich posted:

Seriously, a unit test for this would have taken all of 2 minutes to write and give you pretty indisputable evidence.

Tests can't prove the absence of bugs :pseudo:

1337JiveTurkey
Feb 17, 2005

fritz posted:

I don't care how much of a horror it is, if there's more than one Boolean operator in an expression the parentheses are going in.

Removing the parentheses actually changes the operation, it's just that (!isBar) ^ isJustFucked == isBar ^ (!isJustFucked) == !(isBar ^ isJustFucked)

Bunny Cuddlin
Dec 12, 2004
So this MySQL bug has been open for seven years as of today and someone... well...

https://www.youtube.com/watch?v=oAiVsbXVP6k

im pretty sure that's max headroom

Dirk Pitt
Sep 14, 2007

haha yes, this feels good

Toilet Rascal

GrumpyDoctor posted:

Tests can't prove the absence of bugs :pseudo:

I work with people who take this line of thinking to the extreme and say tests are a waste of time. According to some, the only way to test an app is manually. No mention of why we have had to issue a fix for 1500+ bugs in the first year this app has been in production.

Opinion Haver
Apr 9, 2007

Ranma posted:

Java code, everything is a boolean
code:
boolean isFoo = !(isBar ^ isJustFucked);
Had a 10 minute discussion with the senior developer who wrote this when I wanted to change it to
code:
boolean isFoo = isBar == isJustFucked; 
I ended up having to draw the truth tables, and he still told me I had to retest all the code before making that one change. This at a place where running the tests took over an hour, which is a WTF all by itself.

Just look at it as elements of GF(2); obviously 1+(a+b) = ab+(1+a)(1+b) :colbert:

QuarkJets
Sep 8, 2008

Python code:
def read_data(data, desired_key):
    if(isinstance(data, dict)):
        indexes = []
        i=0
        desired_val = "none"
        for key in data.iterkeys():
            indexes.append(i)
            indexes.append(key)
            indexes.append(data[key])
            i += 1
        for i in range(len(indexes)):
            if(indexes[i] == desired_key):
                return (indexes[i], indexes[i+1], indexes[i-1])

Tesseraction
Apr 5, 2009

I guess they really can't stand enumerate().

Or readability.

Don Mega
Nov 26, 2005
One of the Python's strengths is readability. So if you gently caress that up you are doing something wrong.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Tesseraction posted:

I guess they really can't stand enumerate().

Or readability.

Or data[desired_key]

Adbot
ADBOT LOVES YOU

Tesseraction
Apr 5, 2009

I think they want to get the specific index of the key, which is pretty terrible as dict doesn't maintain order when built, so good job to that guy for not checking data structure implementations.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply