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
Contra Duck
Nov 4, 2004

#1 DAD
Something I saw today (typing from memory):

code:
...
try
{
    DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
    // TODO: Check that this is the right format

    date = dateFormat.parse(someString);
}
catch (ParseException pe)
{
    return true;
}
...
No, it was not the right date format.

Adbot
ADBOT LOVES YOU

Contra Duck
Nov 4, 2004

#1 DAD
Hi all! I saw a new code pattern today that I think has the potential to revolutionise the industry and I wanted to share it with you. I call it antipolymorphism. In general it looks like this:

code:

public class ClassB extends ClassA
{
    ...
}

public class ClassA
{
    public void someMethod()
    {
        if (this instanceof ClassB)
        {
            // do something
        }
        else
        {
            // do a different thing
        }
    }
}
Quite powerful I think you'll agree, and the advantages of keeping all your logic in the one place rather than scattered amongst different files cannot be overstated.

Contra Duck
Nov 4, 2004

#1 DAD

Dijkstracula posted:

Indeed, I recall doing Contra Duck's antipolymorphism back in my first semester of CS. I think it's awfully low-hanging fruit unless it's absolutely hysterical

I had my share of laughs back when I used to take first year CS classes at uni, but sadly my last example was from industry. Thank god for code reviews though!

Contra Duck
Nov 4, 2004

#1 DAD
The whole thing is a troll and it's brilliant.

Contra Duck
Nov 4, 2004

#1 DAD

TRex EaterofCars posted:

Yup, that's the web application servlet context and request being passed in. To a job. That runs via Quartz.
Also, processFulfillmentItems is even larger than this and has around 15 exit points.
gently caress.

Well that's just stunning. Congratulations :)

Contra Duck
Nov 4, 2004

#1 DAD

shrughes posted:

Real programmers

Using this phrase is a horror.

Contra Duck
Nov 4, 2004

#1 DAD
Here's one I found today. By no means the worst that this thread has ever seen but definitely something that could be simplified. (names have been changed)
code:
    public Boolean getAaa()
    {
        Boolean bbb = getBbb();

        if (BooleanUtil.isTrue(getCcc())
                && BooleanUtil.isTrue(bbb))
        {
            return Boolean.TRUE;
        }

        if (BooleanUtil.isTrue(getCcc())
                && BooleanUtil.isFalse(bbb))
        {
            return Boolean.FALSE;
        }

        if (BooleanUtil.isFalse(getCcc()))
        {
            return Boolean.FALSE;
        }

        return Boolean.FALSE;

    }

Contra Duck
Nov 4, 2004

#1 DAD

Plorkyeran posted:

Unless it solves k-SAT or something, I think having something named BooleanUtil might be a horror just by itself.

It's just there to avoid NullPointerExceptions in cases where the Boolean is null which actually was a possibility in this case. The fact that it's using a homegrown 'BooleanUtil' class instead of the perfectly good apache-commons BooleanUtils class is probably is a horror though!

Contra Duck
Nov 4, 2004

#1 DAD

Janin posted:

He's implying that Haskell isn't imperative, so yes, he is

Also, some ridiculous percentage (like 75-85%) of OCaml and Haskell programmers work in finance. It's like saying "I'm so glad I'm going to work in the games industry, so I don't have to write in C"

But what percentage of developers in finance work in Haskell or OCaml?

Contra Duck
Nov 4, 2004

#1 DAD
code:
screenField_disabled=not(not(item.isViewOnly))
I have found 21 of these so far :(

Contra Duck
Nov 4, 2004

#1 DAD

Hammerite posted:

http://falconpl.org/index.ftd?page_id=facts

Witness the power of facts! :yum:

Wow, check out that performance, it's three times faster than Perl at executing an empty loop!

Contra Duck
Nov 4, 2004

#1 DAD
I'd call them an ambulance.

Contra Duck
Nov 4, 2004

#1 DAD

TheresaJayne posted:

I cant really post the code that makes me cry...

its a single "small" java class, part of a bean for an article on a website.

15448 lines long,
113 lines of import statements,

and where i worked, only the senior devs were allowed to make changes in case anyone else broke it.

the next largest class was a paltry 5000 lines (and it was extended from this one)

/me sits down and weeps some more at the inhumanity of the class...

oh and this is a key part of a live website needing low latency

15888 lines, 230 imports :smith::hf::smithicide:

Contra Duck
Nov 4, 2004

#1 DAD

TheresaJayne posted:

if its called Article.java,

say hi to the guys there :)

and i see they added more stuff, did the GWT stuff go in then :)

When I first saw your post I thought "Oh dear, that sounds awfully familiar", but no, mine is an entirely separate 15,000 line horror. There is a part of me that desperately wants to refactor this beast but the part of me that doesn't want to be responsible for it is overriding it.

Contra Duck
Nov 4, 2004

#1 DAD

LOOK I AM A TURTLE posted:


Bravo :golfclap:

Contra Duck
Nov 4, 2004

#1 DAD

Wheany posted:

Does any university offer a course like "Learn not to be a poo poo coder by looking at other people's poo poo code"

Because I bet you could get infinite material from old programming assignments (anonymized, of course)

Eh, looking at terrible student code isn't going to accomplish anything. If you want to learn you need to seek out terrible code written by professionals.

Contra Duck
Nov 4, 2004

#1 DAD
Screw that, I want to know if you ever bought that 36kbps modem.

Contra Duck
Nov 4, 2004

#1 DAD

Zhentar posted:

They've probably been trained not to trust performance testing thanks to horribly inaccurate results from tests run by the same kind of people who think that stuff counts as encryption.

My performance testing story: A client was once very upset that our new release was performing 20% slower in their performance tests. After about two weeks it came out that they had tried to run the test at the same time and on the same machines as another system's performance test.

Contra Duck
Nov 4, 2004

#1 DAD

hobbesmaster posted:

I'm not sure whether this makes me laugh or cry...

Lets see here:


I'm assuming they're not eating their own dogfood here?

You'd think they would learn after the Zune leap year bug in 2008.

Contra Duck
Nov 4, 2004

#1 DAD

Contero posted:

:stare:

Yep, seen this one before :smith::hf::(

Contra Duck
Nov 4, 2004

#1 DAD

McGlockenshire posted:

The formats understood by strtotime are very well-defined. As long as you're not throwing pathologically poorly formed input at it, it works pretty darn well.

Letting users type "+8 weekdays" in a date field and have it just work is pretty nifty.

Here's the problem: http://en.wikipedia.org/wiki/Date_format_by_country

Contra Duck
Nov 4, 2004

#1 DAD
code:
boolean aTrueValue = true;
boolean aFalseValue = false;
It's been in the codebase for 7 years and the values of true and false haven't changed yet, but if it ever does we are prepared for it.

Contra Duck
Nov 4, 2004

#1 DAD
VRML's comeback begins now!

Contra Duck
Nov 4, 2004

#1 DAD

Manslaughter posted:

A new low has been reached.

After so many time-related horrors it's refreshing to see the other dimensions getting a run.

Contra Duck
Nov 4, 2004

#1 DAD

HORATIO HORNBLOWER posted:

Five or six years, easily.

Yeah, one of my clients is in the middle of a major project to upgrade to IE8 right now.

(kill me)

Contra Duck
Nov 4, 2004

#1 DAD

revmoo posted:

I really don't get people that don't like using SCM. It makes your life so much easier in so many ways.

I don't like having to learn new things when the current method has worked so well* up to now.

* Except for all those horrible horrible catastrophes.

Contra Duck
Nov 4, 2004

#1 DAD
Coding horror - dealing with the memory limitations of a Java 5 application running on 32 bit Windows XP in the year 2014.

Contra Duck
Nov 4, 2004

#1 DAD
Coding horror: Finding out that a project which you previously estimated at over 3000 days work has been promised to the client to be delivered by the end of October.

Contra Duck
Nov 4, 2004

#1 DAD

b0lt posted:

Coding horror: Estimating that a project will take over 3000 days of work

Horrible monolithic enterprisey bank projects take a lot of time!

Volmarias posted:

I hope that you've already written CYA emails about how there's no way in hell that you're meeting this deadline.

Way ahead of you there. It's very frustrating, 5 years ago this company used to make stupid promises like that all the time but I've done a ton of work to get us to a point where we actually have reasonable project plans that are delivered on time and on budget without resorting to the usual "crunch time" bullshit and now with a single comment it's all been undone.

Contra Duck
Nov 4, 2004

#1 DAD

pliable posted:

This is my favorite if-else block in the entire world. I'm a pretty lovely programmer but man, I've at least never done poo poo like that.

I mean, how does one not even see that the whole block will literally do the same exact thing?

At least they managed to chain together their if/else in a normal way, unlike the example I ran into today at work...

code:
        if (a.getSomething() == null)
        {
            a.setSomeValue(false);
        }
        else
        {
            if (a.getSomething() == null)
            {
                a.setSomeValue(false);
            }
            else
            {
                /* do some other stuff */
            }
        }
The first condition was originally different but was changed in some shoddy refactoring. It then didn't get picked up in review, and of course screwing with the conditions here produced a really subtle but nasty bug.

Contra Duck
Nov 4, 2004

#1 DAD

QuarkJets posted:

Hypothetically, a.getSomething() could modify some data that results in the next a.getSomething() returning something different. For instance, if it was iterating over some data, then you'd definitely expect the second call of a.getSomething() to return something new

That code is still poo poo anyway, and it's probably not what's happening

I checked that myself when I saw it but no it was just a standard Java accessor :(

Contra Duck
Nov 4, 2004

#1 DAD

JawnV6 posted:

Imagine you've got a nontechnical superior asking you for the biggest semi-defensible LOC count you could come up with. Calling into a library? Include the library's wc -l count. Don't go gettin' fancy with some grep -c ';' nonsense, we want a big number.

Yeah I has a manager once who wanted to know how many lines of code were written for a project. I gave him a big number that included all the changes in config files and other non-code things and he was happy.

Contra Duck fucked around with this message at 01:23 on Sep 30, 2014

Contra Duck
Nov 4, 2004

#1 DAD
This is a timely discussion because our work is migrating to git right now and I'm trying to convince them to not split up into dozens of small repos like we do right now with cvs. Good to have some ammo and some options to present to them on Monday. Thanks everyone!

Contra Duck
Nov 4, 2004

#1 DAD
"Division is a very costly operation so I optimised it"

Contra Duck
Nov 4, 2004

#1 DAD
Is the thing you inherited is a first year CS assignment?

Contra Duck
Nov 4, 2004

#1 DAD
They read a thing about varargs that mentioned object arrays, so...

Contra Duck
Nov 4, 2004

#1 DAD
Naming things is easy, just call things exactly what they are and everything becomes really easy to read.

code:
public class MortgageInsuranceCalculationDataCalculateMortgageInsuranceRequestTransformerImpl extends AbstractTransformer implements MortgageInsuranceCalculationDataCalculateMortgageInsuranceRequestTransformer

Contra Duck
Nov 4, 2004

#1 DAD
I used to be confused why a webservice was giving me dates like "09-07-10007" until I realised they were storing records with no end date as "99999999" and the webservice was just adding 99 months and 99 days to Jan 1 9999.

Contra Duck
Nov 4, 2004

#1 DAD

LeftistMuslimObama posted:

Was this epic? Cuz that sounds like something I could explain if it was :).

Nah on the other end was some monolithic banking mainframe where 'null' wasn't an option so they used a bunch of bizarre workarounds instead.

Adbot
ADBOT LOVES YOU

Contra Duck
Nov 4, 2004

#1 DAD

bobthecheese posted:

php:
<?
function is_equal($val1, $val2) {
    if ($val1 == $val2) {
        return true;
    } else {
        return false;
    }
}
?>

After reading this thread for a years, I can't tell if this is bad because it's just dumb code or if it's actually needed because php equality testing is that broken :(

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