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
Whompy
Apr 21, 2002

Bozart posted:

I'll have you know that I'm a fictional programmer!

Indeed. That must mean I'm a complex programmer: one with both real and imaginary parts.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

yaoi prophet posted:

Net::CUPS loving sucks. In order to get information about a specific job, you have to call getJob, which internall calls the cupsGetJobs C function to get a list of every print job that the printer knows about, then iterates over it to find the appropriate job by checking the jobid. Now, to be fair, this isn't its fault, since CUPS doesn't provide any 'tell me about job N'. What is its fault is that a: there's no sign at all that getJob has this kind of behavior, and b: there's no 'get all jobs'/'get all queued jobs' function, which would be trivial to write using the CUPS API. Instead, you have to call getJobs, which returns the appropriate list of job IDs, then loop over it. Which will wind up being O(n^2) in the number of jobs in the print queue for something that should be an O(n) operation.

CUPS itself is lovely; there are functions called cupsGetJobs and cupsGetJobs2, the only difference being that the latter forces you to specify which server to get jobs from. There's also cupsGetPPD, cupsGetPPD2, and cupsGetPPD3, which perform related but different operations. Want a way to remember which does what? Too bad.

It's a good thing you can fix it! Not sure if it would make sense to provide a function to slurp all the CUPS jobs into a hash for faster lookup later or whether you'd have cache invalidation issues (unfamiliar with CUPS), but I'm sure you'll work something out!

nbv4
Aug 21, 2002

by Duchess Gummybuns
I'm seeing this poo poo everywhere

code:
"%s" % str(i)

A very bad man
Mar 31, 2010

Bozart posted:

I'll have you know that I'm a fictional programmer!

Is that the same as being a programming nihilist?

I don't know if this has been posted yet, presenting the regex from hell
http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

How to validate email address? posted:

code:
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)
?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\
r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
 \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)
?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t]
)*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[
 \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)
*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:
\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t
]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031
]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?
:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?
:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?
:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?
[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|
\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>
@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"
(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?
:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[
\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-
\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(
?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;
:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([
^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\"
.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\
]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\
[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\
r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]
|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \0
00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\
.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,
;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?
:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[
^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]
]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(
?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[
\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t
])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?
:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|
\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:
[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\
]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)
?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["
()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)
?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>
@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[
 \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,
;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:
\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[
"()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])
*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])
+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\
.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(
?:\r\n)?[ \t])*))*)?;\s*)

POKEMAN SAM
Jul 8, 2004

A very bad man posted:

Is that the same as being a programming nihilist?

I don't know if this has been posted yet, presenting the regex from hell
http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

I think that gets posted every 16th page.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Ugg boots posted:

I think that gets posted every 16th page.

Like do{ }while(0) instead of goto, and Hungarian notation.

And MUMPS.

Lurchington
Jan 2, 2003

Forums Dragoon

nbv4 posted:

I'm seeing this poo poo everywhere

code:
"%s" % str(i)

I can't really cast aspersions, because I pretty much just realized that %r prints the repr and %s casts the string for you.

Moof
May 19, 2003

the horror, the horror
Today this was my friend:

code:
bool whatever;
switch(whatever)
{
    case(true):
        blahblah;
        ...
        break;

    case(false):
        blahblah;
        ...
        break;

    default:
        blahblah;
        ...
        break;
}

tripwire
Nov 19, 2004

        ghost flow
Maybe he was into constructivism

Bozart
Oct 28, 2006

Give me the finger.
I was going to put together an effortpost on Matlab - to actually contribute for a change - but I am far too lazy to do it justice. Some highlights are still in order:

There is no built-in date class. Almost all Matlab functions and toolboxes either have to be told that a number is a date externally or assume that numbers within a certain range of numbers are dates.

There is no built-in string class. You can either use arrays of characters or you can use "cell arrays" of characters, where cell arrays are composed of cells, which can each contain arrays of one class. So a cell array can have any number of types in 2 or more dimensions. Since matlab doesn't have a string class, they threw in a special case of cell arrays called a "cellstr" which is of course, a cell array of character arrays. The kicker? The edge cases are all wrong. An empty cell array is still a cellstr, even though it has no cell arrays in it. A cellstr, unlike all other types (or the pseudotype that this is) does not define equals, but it does define set membership. So a call of
code:
ismember({'asdf'},{'asdf'})
returns true, even though
code:
{'asdf'} == {'asdf'}
returns a syntax error.

Also, speaking of true, false, and all other keywords: you can define variables locally that override them. Yes, that's right. If you want to set true = 0 and false = 1, you can do it. Should you ever do it? Of course not. Have I ran into code with sets false = 1? Yes, in the "Bayesian Network Toolbox". Have I ran into code at my work where someone has overwritten the most primitive functions? Yes.

There are other more in depth :psyduck: but it would take some 'splaining. Long story short? Even numpy, which is just imitating this monster, is better at doing the exact same things by simple virtue of getting simple poo poo right.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

A very bad man posted:

regex from hell

If you're going to bring it up again, you should at least mention that that mess doesn't actually validate email addresses- it just inlines a recursive loop that should be infinite several times.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I need to nullify an if...then loop across several hundred files on several remote servers, with the contents of the loop changing slightly (so no easy search/replace). That and it's several dozen lines long. Lord help me I'm considering just replacing the triggering If for all of them with:
code:
If 1=0 then
Can't wait for someone to come across that later.

Daald
Mar 25, 2009
When I first started working with my current company some contractor had put in this piece of code. A couple of other contractors saw the code as pretty good and had put it everywhere they needed to convert to integer.

code:
            int wastedSpace;
            int result;

            if (Int32.TryParse(input, out wastedSpace))
            {
                result = Int32.Parse(input);
            }
Seeing that variable named "wastedSpace" really cracks me up every time.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Daald posted:

code:
            int wastedSpace;
            int result;

            if (Int32.TryParse(input, out wastedSpace))
            {
                result = Int32.Parse(input);
            }
I want you to try to parse this integer.

"Okay. I've got it! I've successfully parsed the integer, and the value is--"

NO! WAIT! You said you were able to parse the integer?

"Yes..."

Alright, I want you to parse the same integer again, and let me know what you get.

Opinion Haver
Apr 9, 2007

Internet Janitor posted:

If you're going to bring it up again, you should at least mention that that mess doesn't actually validate email addresses- it just inlines a recursive loop that should be infinite several times.

It's also a horror because there are several parts of the regex that get repeated over and over that could be broken out into variables and then inserted for extra legibility. Hell, if you did that it might even make it readable.



Otto Skorzeny posted:

It's a good thing you can fix it! Not sure if it would make sense to provide a function to slurp all the CUPS jobs into a hash for faster lookup later or whether you'd have cache invalidation issues (unfamiliar with CUPS), but I'm sure you'll work something out!

gently caress no I'm not learning perl's C FFI.

Opinion Haver fucked around with this message at 04:35 on Oct 6, 2010

dark_panda
Oct 25, 2004

yaoi prophet posted:

It's also a horror because there are several parts of the regex that get repeated over and over that could be broken out into variables and then inserted for extra legibility. Hell, if you did that it might even make it readable.

That's actually just the final regex and it's really just the author joking around and showing off in the documentation. The actual source code in the Perl module that builds the regex looks like this:

code:
# Preloaded methods go here.
my $lwsp = "(?:(?:\\r\\n)?[ \\t])";

my $char = '[\\000-\\177]';

sub make_rfc822re {
#   Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
#   comment.  We must allow for lwsp (or comments) after each of these.
#   This regexp will only work on addresses which have had comments stripped 
#   and replaced with lwsp.

    my $specials = '()<>@,;:\\\\".\\[\\]';
    my $controls = '\\000-\\037\\177';

    my $dtext = "[^\\[\\]\\r\\\\]";
    my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$lwsp*";

    my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$lwsp)*\"$lwsp*";

#   Use zero-width assertion to spot the limit of an atom.  A simple 
#   $lwsp* causes the regexp engine to hang occasionally.
    my $atom = "[^$specials $controls]+(?:$lwsp+|\\Z|(?=[\\[\"$specials]))";
    my $word = "(?:$atom|$quoted_string)";
    my $localpart = "$word(?:\\.$lwsp*$word)*";

    my $sub_domain = "(?:$atom|$domain_literal)";
    my $domain = "$sub_domain(?:\\.$lwsp*$sub_domain)*";

    my $addr_spec = "$localpart\@$lwsp*$domain";

    my $phrase = "$word*";
    my $route = "(?:\@$domain(?:,\@$lwsp*$domain)*:$lwsp*)";
    my $route_addr = "\\<$lwsp*$route?$addr_spec\\>$lwsp*";
    my $mailbox = "(?:$addr_spec|$phrase$route_addr)";

    my $group = "$phrase:$lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
    my $address = "(?:$mailbox|$group)";

    return "$lwsp*$address";
}

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

yaoi prophet posted:

gently caress no I'm not learning perl's C FFI.

Good thing you don't have to :v:

Daald
Mar 25, 2009

Orzo posted:

I want you to try to parse this integer.

"Okay. I've got it! I've successfully parsed the integer, and the value is--"

NO! WAIT! You said you were able to parse the integer?

"Yes..."

Alright, I want you to parse the same integer again, and let me know what you get.

I think the funniest thing was him naming that variable "wastedSpace". I can already see his reasoning.

1. Hey I need to parse this string to integer.
2. Wouldn't it be nice if I found a function that tells me if it is a valid string?
3. Let me see if I find it...ohh there is one...tryparse...looks like it.
4. WTF? It needs me to pass it an integer...WTF for? Ahh well stupid MS api. Here is your stupid variable.
5. Cool, I can parse it. Now let me call the parse function.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Daald posted:

I think the funniest thing was him naming that variable "wastedSpace". I can already see his reasoning.

1. Hey I need to parse this string to integer.
2. Wouldn't it be nice if I found a function that tells me if it is a valid string?
3. Let me see if I find it...ohh there is one...tryparse...looks like it.
4. WTF? It needs me to pass it an integer...WTF for? Ahh well stupid MS api. Here is your stupid variable.
5. Cool, I can parse it. Now let me call the parse function.

To compound it even further the signature of the method is TryParse(string s, out int result).

Hmm... what could result possibly mean... oh well whatever time to call Parse and store the value in my local variable named result.

Reformed Pissboy
Nov 6, 2003

In an otherwise very well-written testing class (edited for brevity):

code:
void Test::getMessage(...)
{
tryAgain:
    readStat = waitForMessage(...);
    if( readStat == TIMEOUT && _nonBlockingEnabled )
    {
        // don't pin the CPU
        sleep(0);
        goto tryAgain;
    }

    do
    {
        if( _states[_currentState] != ... )
        {
            _result = false;
            cerr << "incorrect state";
            break;
        }
        if( readStat != _expectedReadStat )
        {
            _result = false;
            cerr << "incorrect read result";
            break;
        }

        _currentState++;
        if( _states[_currentState] == End )
        {
            _done = true;
        }
    } while(0);
}
I mean it works fine so I'm not too upset, but goto and do{ }while(0) in the same method is :confused: Not to mention the goto bit would make more sense as a while, and the while bit as a goto...

Reformed Pissboy fucked around with this message at 18:14 on Oct 7, 2010

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Space Prostitute posted:

code:
void Test::getMessage(...)
{
tryAgain:
    readStat = waitForMessage(...);
    if( readStat == TIMEOUT && _nonBlockingEnabled )
    {
        // don't pin the CPU
        sleep(0);
        goto again;
    }

Where exactly is the again: label that it's going to?

Blue Footed Booby
Oct 4, 2006

got those happy feet

Space Prostitute posted:

...
I mean it works fine so I'm not too upset, but goto and do{ }while(0) in the same method is :confused: Not to mention the goto bit would make more sense as a while, and the while bit as a goto...

I had something like this today. I saw a function call in some VB code I was working with, and right click->definition'd to see what it was doing (the name was not helpful). I was presented with a 300 line function that did...stuff with an Access database. Using many nested for loops and a total of 13 temp tables. All of which had names like "temp3," "tempM," and "temptemp." The first one used was temp3.

Did I mention the three gotos?

There was a comment at the top explaining what the code did. I made a note of it, and pretended I never scrolled down past that. I mean, it works, but jesus christ. The code I was looking at was sane. It's like Visual Studio goatsed me.

Blue Footed Booby fucked around with this message at 02:18 on Oct 7, 2010

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
code:
public void DoSomething(int parameter1, SomeObject parameter2 = null)
{
  if(parameter2 == null)
    throw new ArgumentNullException("parameter2");

  ...
}
:psyduck:

oneinchhard
Mar 14, 2003
I AM FUCKING AWESOME!
code:

public class SomeClass
{
    public string SomeString1 { get; set; }
    ...
}

...elsewhere in the code:

string someVar = someClassInstance.SomeString1.ToString();

:negative:

This type of poo poo is all over this project that was handed off to me to optimize. Also:

code:

StringBuilder sb = new StringBuilder();
sb.Append("SELECT field");
sb.Append("FROM table");
sb.Append("WHERE field = ");
sb.Append(someVal.ToString());

string sql = sb.ToString();

...there are probably 100 DAL methods that have this crap in there.

:smith:

Going to school to be a nurse. 15 years of this loving poo poo...

gibbed
Apr 10, 2006

dwazegek posted:

code:
public void DoSomething(int parameter1, SomeObject parameter2 = null)
{
  if(parameter2 == null)
    throw new ArgumentNullException("parameter2");

  ...
}
:psyduck:
Why is this a horror?

I'm assuming you mean something besides the argument names.

oneinchhard
Mar 14, 2003
I AM FUCKING AWESOME!

gibbed posted:

Why is this a horror?

I'm assuming you mean something besides the argument names.

Default parameter value is null.

Calling DoSomething(someVal) will throw an exception.

Calling the method as designed will break.

loving HORRIBLE PROGRAMMERS!

king_kilr
May 25, 2007

gibbed posted:

Why is this a horror?

I'm assuming you mean something besides the argument names.

Real horror spotted.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

oneinchhard posted:

code:

public class SomeClass
{
    public string SomeString1 { get; set; }
    ...
}

...elsewhere in the code:

string someVar = someClassInstance.SomeString1.ToString();

:negative:

This type of poo poo is all over this project that was handed off to me to optimize. Also:

code:

StringBuilder sb = new StringBuilder();
sb.Append("SELECT field");
sb.Append("FROM table");
sb.Append("WHERE field = ");
sb.Append(someVal.ToString());

string sql = sb.ToString();

...there are probably 100 DAL methods that have this crap in there.

:smith:

Going to school to be a nurse. 15 years of this loving poo poo...
Why are either of these 'horrors?'

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.
Well, if you don't think SQL injection is a horror…

oneinchhard
Mar 14, 2003
I AM FUCKING AWESOME!

Orzo posted:

Why are either of these 'horrors?'

Lesson 1: L2STRONGLYTYPEDLANGUAGE

You see SomeString1 is ALREADY A loving STRING. There is no need to call ToString().

Might as well do this:

code:

string myString = Convert.ToString((string)((string)SomeString1.ToString()).ToString());

Lesson 2: Try not to be a human being and write lovely code.

code:

string sql = @"select field
               from table
               where field = @parameter";

...

mySqlCommand.Parameters.Add("@parameter", someVal);

Dynamic sql is already bad enough...don't gently caress it up any more than it has to be.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

king_kilr posted:

Real horror spotted.

Shut up I also missed that the default parameter value is null.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

oneinchhard posted:

code:

public class SomeClass
{
    public string SomeString1 { get; set; }
    ...
}

...elsewhere in the code:

string someVar = someClassInstance.SomeString1.ToString();


For some reason I see this in contractor code ALL THE TIME. Apparently contractors are really really enthusiastic about toString'ing strings.

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.
Maybe it's out of habit from calling ToString() on everything else. Who needs any other data type? Strings are simple and easy to understand!

Reformed Pissboy
Nov 6, 2003

Kilson posted:

Where exactly is the again: label that it's going to?

My bad, it should be to tryAgain, five lines up. I should add that's the only goto statement in the entire project :)

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Hah, I wasn't even thinking of SQL injection; I was more focused on the unnecessary use of StringBuilder for that particular set of strings.

But for the first one, oneinchhard, yes, I understand why it's wrong. I just don't think it's a 'horror.' In fact, it's completely harmless and could easily have been introduced through a quick refactoring.

Daald
Mar 25, 2009

Space Prostitute posted:

In an otherwise very well-written testing class (edited for brevity):

code:
void Test::getMessage(...)
{
tryAgain:
    readStat = waitForMessage(...);
    if( readStat == TIMEOUT && _nonBlockingEnabled )
    {
        // don't pin the CPU
        sleep(0);
        goto tryAgain;
    }

    do
    {
        if( _states[_currentState] != ... )
        {
            _result = false;
            cerr << "incorrect state";
            break;
        }
        if( readStat != _expectedReadStat )
        {
            _result = false;
            cerr << "incorrect read result";
            break;
        }

        _currentState++;
        if( _states[_currentState] == End )
        {
            _done = true;
        }
    } while(0);
}
I mean it works fine so I'm not too upset, but goto and do{ }while(0) in the same method is :confused: Not to mention the goto bit would make more sense as a while, and the while bit as a goto...

This is funny as hell!!

1. Using goto where a do while loop would serve the same function and immediately the next statement is a do while loop.
2. The next do while loop only runs once since it is (while(false)) and is only there so the "break" statements work. If he had used the great concept known as else or at least did what he did in part 1 and used a goto it would have at least been consistent.

palatka
Apr 4, 2003

by Ralp
I came across this gem today at work (in Ruby).

code:
x, y = x, x+y

NotShadowStar
Sep 20, 2000
I don't really see that being a horror, just someone was probably quickly doing something. It's harmless.

A very bad man
Mar 31, 2010
I'm currently porting a program from a system to another and I've noticed a large number of sql views selecting from views, that select from views, that select from views. These 'parent' views aren't being used in many places so it doesn't seem like it was a calculated decision to make the hierarchy more simple to update.

This is nasty as hell. is there a good reason for this?

EDIT: I considered posting the code but it's will make you bleed from the eyes.

A very bad man fucked around with this message at 06:40 on Oct 8, 2010

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

A very bad man posted:

I'm currently porting a program from a system to another and I've noticed a large number of sql views selecting from views, that select from views, that select from views. These 'parent' views aren't being used in many places so it doesn't seem like it was a calculated decision to make the hierarchy more simple to update.

This is nasty as hell. is there a good reason for this?

EDIT: I considered posting the code but it's will make you bleed from the eyes.

Are any of the views materialized?

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