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
Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

thel posted:

code:
SharedUtils.getFirstWord = function(str) {
  if (str.indexOf(' ') < 0) {
    return str;
  }
  for(var i = 0; i <str.length; i++){
    if(str.charAt(i) == ' '){
      return str.substring(0,i);
    }
  }
}
variables is basically just another word for loop counter

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.

tef posted:

is it wrong to want a version of awk that handles xpath :catdrugs:
There's a few random libraries for doing obscene awk-like things with streams of "anything", including this one: https://github.com/benbernard/RecordStream

Zombywuf
Mar 29, 2008

tef posted:

is it wrong to want a version of awk that handles xpath :catdrugs:

I keep telling you man, XQuery. Of course there's no good command line version. :-(

lazer_chicken
May 14, 2009

PEW PEW ZAP ZAP

tef posted:

is it wrong to want a version of awk that handles xpath :catdrugs:

Not xml, but check this out http://code.google.com/p/spawk/

I can only imagine that fantastic scripts you could make with this.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Wow, if only that worked with Postgres, it probably would've been perfect for something that I just did for work (with the one true awk).

TheresaJayne
Jul 1, 2011
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

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?
Putting an article on a web site has always been one of the hardest problems to solve in computer science.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

A A 2 3 5 8 K posted:

Putting an article on a web site has always been one of the hardest problems to solve in computer science.
this is my entire job

Lysandus
Jun 21, 2010
I found this today.

code:
if( !true )
{
}
Nothing identifying around it. Just that.

benitocereno
Apr 14, 2005


Doctor Rope

Lysandus posted:

Nothing identifying around it. Just that.

I'm convinced there's a whole subset of programmers that do this kind of thing just to gently caress with you. Gotta say though, after reading this thread, I'm convinced something like this would be more par for the course:

code:
public bool isTrue(bool _true)
{   
   if(_true != false)
   {
      _true = false;
   }

   return _true;
}
PS. Gonna use that in something now :toot:

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

benitocereno posted:

I'm convinced there's a whole subset of programmers that do this kind of thing just to gently caress with you.

Maybe it's a canary. When you see one you're supposed to figure out who wrote it, ask them what the hell they were doing, and they say "ahh, you've actually read the code! Excellent!"

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:

Thel
Apr 28, 2010

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}

You're not thinking badlyenterprisey enough.

code:
public boolean isTrue(boolean ValueToBeTested) {
    boolean trueBoolean = BooleanFactory.getInstance(BooleanValues.BooleanTRUE);
    boolean falseBoolean = BooleanFactory.getInstance(BooleanValues.BooleanFALSE);
    if(ValueToBeTested != falseBoolean) {
        if(ValueToBeTested == trueBoolean {
            return trueBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }    
    if(ValueToBeTested != trueBoolean) {
        if(ValueToBeTested == falseBoolean {
            return falseBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }
    throw new ValueMatchingException(ValueToBeTested + " is neither true nor false.");
    return false;
}

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
You forgot to account for the case where the boolean is both true and false. This is affecting production.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}
Oh come on, that has to be a joke.

benitocereno
Apr 14, 2005


Doctor Rope
It took me ages to understand why !Boolean.toString(bool).length()==5; was relevant. :psyduck: I think that's a good thing?

As for Thel's code... :suicide:.

Going to be honest here, whenever I write a really bad piece of code I at least try to make the comments entertaining. Why throw such a boring error when you can insult the person responsible for breaking it?

Thel
Apr 28, 2010

Ensign Expendable posted:

You forgot to account for the case where the boolean is both true and false. This is affecting production.

Ah but I did, it would throw an InvalidArgumentException ... I think. :haw:

(If anyone actually has a system with true-and-false booleans, then I'm a bit scared.)

tef
May 30, 2004

-> some l-system crap ->
perl six

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
code:
//not needed anymore
/*
function someFunction(){

}
function someOtherFunction(){

}
function yetAnotherfunction(){

}
*/

qntm
Jun 17, 2009

Thel posted:

You're not thinking badlyenterprisey enough.

code:
public boolean isTrue(boolean ValueToBeTested) {
    boolean trueBoolean = BooleanFactory.getInstance(BooleanValues.BooleanTRUE);
    boolean falseBoolean = BooleanFactory.getInstance(BooleanValues.BooleanFALSE);
    if(ValueToBeTested != falseBoolean) {
        if(ValueToBeTested == trueBoolean {
            return trueBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }    
    if(ValueToBeTested != trueBoolean) {
        if(ValueToBeTested == falseBoolean {
            return falseBoolean;
        } else {
            throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");
        }
    }
    throw new ValueMatchingException(ValueToBeTested + " is neither true nor false.");
    return false;
}

Is it good that I couldn't come up with nonsense like this even if I tried?

TheresaJayne
Jul 1, 2011

Contra Duck posted:

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

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 :)

Thel
Apr 28, 2010

qntm posted:

Is it good that I couldn't come up with nonsense like this even if I tried?

Yes.

I don't know what it says about me that I was able to improvise that in about five minutes. :ohdear: My thought process was basically "Enterprise, so let's throw in a redundant factory class. Hurf some completely ridiculous logic checks in there, some awful and useless exception throws, and we're good to go."

e: Ironically, there's some accidental horrors in there too. :v:

Lysandus
Jun 21, 2010
This is the best part. People around me were poking their heads out of their cubes to see why I was laughing so hard.

code:
throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

Wheany posted:

code:
//not needed anymore
/*
function someFunction(){

}
function someOtherFunction(){

}
function yetAnotherfunction(){

}
*/

This is just someone who's not used to version control and/or wants the logic of those functions readily available for some reason.

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.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Factor Mystic posted:

This is just someone who's not used to version control
Arguably a horror.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}



"ifTrue" and "ifFalse" are methods defined on the True and False classes. Smalltalk owns.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}

I've seen almost that in real-world code. It was something like

code:
    bool value = SomethingThatReturnsBool();
    if (value.ToString().ToLower() == "false")
    {
        ...
    }
Fortunately we caught that poo poo in a code review.

MononcQc
May 29, 2007

http://coding.smashingmagazine.com/2011/07/07/my-favorite-programming-mistakes/

Almost everything in there, including the advice given.

minato
Jun 7, 2004

cutty cain't hang, say 7-up.
Taco Defender
My god, the advice he gives is awful. He enables debugging to the screen on production and his first piece of advice is "Avoid working late at night" instead of "Don't debug on loving production".

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

MononcQc posted:

http://coding.smashingmagazine.com/2011/07/07/my-favorite-programming-mistakes/

Almost everything in there, including the advice given.

"Don’t reinvent the wheel, even very small wheels that look easy from the outside."

"Don’t reinvent the time wheel either: strtotime is a powerful function."

[implements stupid proprietary spam detection algorithm based on number of consonants in a row that leads to inevitable false positives that he fixes by considering "w" to be a vowel]

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

benitocereno posted:

I'm convinced there's a whole subset of programmers that do this kind of thing just to gently caress with you. Gotta say though, after reading this thread, I'm convinced something like this would be more par for the course:

code:
public bool isTrue(bool _true)
{   
   if(_true != false)
   {
      _true = false;
   }

   return _true;
}
PS. Gonna use that in something now :toot:

Am I missing something or will this always return false?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

MononcQc posted:

http://coding.smashingmagazine.com/2011/07/07/my-favorite-programming-mistakes/

Almost everything in there, including the advice given.

Hmm, learning by making mistakes is only good if you draw the right conclusions from the mistakes.

Sedro
Dec 31, 2008

poemdexter posted:

Am I missing something or will this always return false?

Except in the case where _true == FileNotFound

benitocereno
Apr 14, 2005


Doctor Rope

poemdexter posted:

Am I missing something or will this always return false?

Why wouldn't you expect a function named isTrue passed a bool named _true to always return false? :downs:

(no you're not missing anything)

Sedro posted:

Except in the case where _true == FileNotFound

Sorry, to handle that I think you need an enterprise solution.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
I was going to do a FizzBuzz using Rx, but Rx is a little funky. So I thought I'd see how much I could abuse the language instead. The below code works. You wouldn't expect it to, but the first call to GetAction is with a value of 1, and not 0 as you would initially intuit.

code:
   class FizzBuzzThatWorksButIAmBuggeredIfIKnowWhy
    {

        public void Execute()
        {
            var allActions = BuildAction(() => { }, 0);
            allActions();
        }

        public Action BuildAction(Action action, int i)
        {
            if (i == 100) { return action; }
            Action wrapperAction = () => { action(); GetAction(i)(); };
            return BuildAction(wrapperAction, ++i);
        }

        public Action GetAction(int i)
        {
            switch (i % 15)
            {
                case 0:
                    return () => Console.WriteLine(i + ": FizzBuzz");
                default:
                    {
                        switch (i % 5)
                        {
                            case 0:
                                return () => Console.WriteLine(i + ": Buzz");
                            default:
                                {
                                    switch (i % 3)
                                    {
                                        case 0:
                                            return () => Console.WriteLine(i + ": Fizz");
                                        default:
                                            return () => Console.WriteLine(i);
                                    }
                                };
                                break;
                        }
                    };
                    break;
            }
        }

        static void Main(string[] args)
        {
            var p = new FizzBuzzThatWorksButIAmBuggeredIfIKnowWhy();
            p.Execute();
        }
    }

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


minato posted:

My god, the advice he gives is awful. He enables debugging to the screen on production and his first piece of advice is "Avoid working late at night" instead of "Don't debug on loving production".

Actually, not working late is good advice that a lot of agile shops get great results codifying. And he probably assumed that people could tell that, when he's telling the Horrific Tale of Debug Enabled In Production, enabling debug in production is a bad thing.

The article as a whole is pretty sad, though

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

MononcQc posted:

http://coding.smashingmagazine.com/2011/07/07/my-favorite-programming-mistakes/

Almost everything in there, including the advice given.

quote:

Paul Tero is an experienced PHP programmer

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Milotic posted:

but the first call to GetAction is with a value of 1, and not 0 as you would initially intuit.

It's the whole lambda scoping thing. Lambdas close over variables, not values.

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