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
ohgodwhat
Aug 6, 2005

Zakalwe posted:

output(i) returns a reference to the i'th element of an internal array I'd guess. If so I'd personally overload[] and use output[j] = device_read(j) myself; It's a stylistic choice.

Yep, that's what it does. It just looks wrong. This whole project is kind of a pain, I'm trying to write a plugin for an obscure OSS scientific computing program which has no documentation. I got it working after flailing about for a bit, but that was only the beginning!

Adbot
ADBOT LOVES YOU

Spectral Elvis
Jul 23, 2007

I feel like I've spent my life patching other peoples idiocy. I've seen some horrors, but absolutely nothing could prepare me for this

code:
class MyStringClassIterator;

class MyStringClass {
  ...

  typedef MyStringClassIterator iterator;
  typedef const MyStringClassIterator const_iterator;
  ...
}
It's a good thing the coder considered that referential parameters are fundamentally wrong, (to the extent that his disaproval of them was written into the coding standard*), else he might have one day realised what he had created here.


*yeah, that part got dropped the very moment the opportunity arose.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Flobbster posted:

I like that the helper function they wrote to handle the null string case requires about twice as much typing as the expression itself.

code:
str = StringUtilities.AssignNotNullString(str);
str = str == null ? "" : str;
Actually, if you have code completion helping you, it winds up being a matter of typing out Stri<C-space>.rear end<C-space>(str) so it's not so bad and it doesn't mean you have to reach for the = key either. The downside is that it makes your code look more verbose when it's really not. This is what tends to happen in a "verb-heavy" language like Java because its expressive constructs are so primitive.

mr_jim
Oct 30, 2006

OUT OF THE DARK

porkfactor posted:

I feel like I've spent my life patching other peoples idiocy. I've seen some horrors, but absolutely nothing could prepare me for this

code:
class MyStringClassIterator;

class MyStringClass {
  ...

  typedef MyStringClassIterator iterator;
  typedef const MyStringClassIterator const_iterator;
  ...
}
It's a good thing the coder considered that referential parameters are fundamentally wrong, (to the extent that his disaproval of them was written into the coding standard*), else he might have one day realised what he had created here.


*yeah, that part got dropped the very moment the opportunity arose.

I don't have a lot of C++ experience. What's the horror here?

Lexical Unit
Sep 16, 2003

mr_jim posted:

I don't have a lot of C++ experience. What's the horror here?
STL style containers will offer a number of different kinds of iterators such that they can interop with algorithms. However the writer of that code doesn't appear to understand the meaning of "const_iterator." Think about it. If the iterator itself is const... it's not really an iterator, is it? const_iterator is supposed to be an iterator that doesn't allow algorithms to modify the elements being iterated over. Not an iterator that's conceptually const (which I would take to mean an iterator that only ever points to one thing).

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.
A const_iterator conceptually iterates over const elements. That is, they can't be modified through the iterator. An example is const char *. The const_iterator defined in that example is a nonmodifiable iterator that references a non-const element. An example is char * const i. You can do *i = 'c', but you can't do ++i.

mr_jim
Oct 30, 2006

OUT OF THE DARK

OK, I get it now. It's "const pointer" vs "pointer to const" generalized to C++ iterators.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Lexical Unit posted:

STL style containers will offer a number of different kinds of iterators such that they can interop with algorithms. However the writer of that code doesn't appear to understand the meaning of "const_iterator." Think about it. If the iterator itself is const... it's not really an iterator, is it? const_iterator is supposed to be an iterator that doesn't allow algorithms to modify the elements being iterated over. Not an iterator that's conceptually const (which I would take to mean an iterator that only ever points to one thing).

It's totally possible to make a const_iterator by using constness of the iterator itself and creating appropriate const overloads. But then you'd make it impossible to make an iterator that itself cannot be changed, so I propose using volatile for this, e.g.:

code:
class iter
{
public:
    foo & operator*();
    const foo & operator*() volatile;
};

typedef iter iterator;
typedef volatile iter const_iterator;
No one uses "volatile" for anything but primitives, and even that is rare, so it's not like anyone would notice.

TSDK
Nov 24, 2003

I got a wooden uploading this one

Avenging Dentist posted:

code:
class iter
{
public:
    const foo & operator*() volatile;
};
Nice. It never even occurred to me that you could do this. Which, all things considered, is probably a good thing.

Lexical Unit
Sep 16, 2003

Avenging Dentist posted:

No one uses "volatile" for anything but primitives, and even that is rare, so it's not like anyone would notice.
Yeah volatile is great* for all kinds of things, like thread safety! :pwn:


*: not great.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Lexical Unit posted:

Yeah volatile is great* for all kinds of things, like thread safety! :pwn:


*: not great.

That article owns.

Insurrectum
Nov 1, 2005

Avenging Dentist posted:

Seriously, if you work at Epic Systems, just loving quit, it's not worth it.

I almost got flown out to Wisconsin for them before deciding to go to grad school instead, are they well known for being a lovely company or something?

Zombywuf
Mar 29, 2008

Insurrectum posted:

I almost got flown out to Wisconsin for them before deciding to go to grad school instead, are they well known for being a lovely company or something?

http://thedailywtf.com/gsearchresults.aspx?cx=007080070087309103660%3Au1mb5rvqdbu&cof=FORID%3A11&ie=UTF-8&q=mumps&sa=Search#1098

Insurrectum
Nov 1, 2005


Goddamn. Looks like I made the right choice.

wolf_man
Oct 5, 2005

Nunez?
I've been assigned to completely redo this small custom CMS my company did for a client. The old developer was a cheap freelancer and did a crap-tastic job.

Looking through the code I just found this:

php:
<?php if ($totalRows_Recordset1 0) { do { ?>
          ...some html...
<?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); } ?>

a goddamn do while in PHP5!.

I bet I'm gonna find loads of gems in this project.

Vinterstum
Jul 30, 2003

wolf_man posted:

a goddamn do while in PHP5!.

Not having touched PHP in many years (thankfully), I guess I'm missing something here. What's the coding horror, that he should be using foreach() instead or something? What specifically makes do-while loops poo poo in PHP5?

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner

Vinterstum posted:

What's the coding horror, that he should be using foreach() instead or something?

Probably (except I'm not exactly a PHP expert myself)

wolf_man
Oct 5, 2005

Nunez?

Vinterstum posted:

Not having touched PHP in many years (thankfully), I guess I'm missing something here. What's the coding horror, that he should be using foreach() instead or something? What specifically makes do-while loops poo poo in PHP5?

for loops are better optimized and efficient then do whiles.

oldkike
Jan 10, 2003

hey

www.pleasegimmeadollar.com
Saw this today:

code:
SpecialObject *o;
try 
{
  o = dynamic_cast<SpecialObject*>(globalPointer->getObj(SPECIAL_OBJECT); // getObj does not throw
} catch (...)
{
 o = NULL;
}

wolf_man posted:

for loops are better optimized and efficient then do whiles.

.. really?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

wolf_man posted:

for loops are better optimized and efficient then do whiles.
Granted, I don't know the first thing about PHP's internals, but I would be highly surprised if a do-while construct could be "optimized" (I'm thinking of things like loop invarients) any better than a plain for-loop. it's a conditional and jump, what's to optimize :confused:

spiritual bypass
Feb 19, 2008

Grimey Drawer

Dijkstracula posted:

Granted, I don't know the first thing about PHP's internals, but I would be highly surprised if a do-while construct could be "optimized" (I'm thinking of things like loop invarients) any better than a plain for-loop. it's a conditional and jump, what's to optimize :confused:

It doesn't matter if it actually makes sense. PHP has stuff all over the place where there's 3 logically equivalent ways to do something and the first way is 1/10 the cost of the other two.

What's really bad about this is that people start writing code based on some bullshit they picked up in a tutorial (or writing their own tutorial!) because they want their program to be "optimized" before they care about it being useful or maintainable.


Examples:

$array[] = $var vs. $array = array($var)
print("hello") vs. print "hello"

dancavallaro
Sep 10, 2006
My title sucks

royallthefourth posted:

$array[] = $var vs. $array = array($var)

These are different though. For example, if you do

code:
$array = array(1)
$array = array(2)
$array = array(3)
you're going to wind up with $array = [3]. But if you do

code:
$array[] = 1
$array[] = 2
$array[] = 3
you'll wind up with $array = [1,2,3].

royallthefourth posted:

print("hello") vs. print "hello"

This was also the case in Python pre-3.0.

baquerd
Jul 2, 2007

by FactsAreUseless

oldkike posted:

Saw this today:

code:
SpecialObject *o;
try 
{
  o = dynamic_cast<SpecialObject*>(globalPointer->getObj(SPECIAL_OBJECT); // getObj does not throw
} catch (...)
{
 o = NULL;
}

I'm not on the up and up in C. Are you trying to say that the try block is unnecessary? Can't the cast fail and throw an exception?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
dynamic_cast returns NULL if it isn't a valid cast

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Plorkyeran posted:

dynamic_cast returns NULL if it isn't a valid cast

No, dynamic_cast returns NULL if the cast fails and the target type is a pointer (which it is in this case). It throws if it's a reference type.

king_kilr
May 25, 2007

dancavallaro posted:

]
This was also the case in Python pre-3.0.


What do you mean "it was the case in Python", no one in the Python community writes print with parens in Python 2.x, especially not as a performance hack as the OP suggests.

Vinterstum
Jul 30, 2003

oldkike posted:

Saw this today:

code:
SpecialObject *o;
try 
{
  o = dynamic_cast<SpecialObject*>(globalPointer->getObj(SPECIAL_OBJECT); // getObj does not throw
} catch (...)
{
 o = NULL;
}

dynamic_cast is the real horror here.

ctz
Feb 6, 2003

wolf_man posted:

for loops are better optimized and efficient then do whiles.

Coding horrors: posts that make you laugh (or cry)

geetee
Feb 2, 2004

>;[

ctz posted:

Coding horrors: posts that make you laugh (or cry)

We were so close to getting past the PHP side tracking and here you (we) go bringing it back up. See ya in 5 pages and 3 more threads.

king_kilr
May 25, 2007

geetee posted:

We were so close to getting past the PHP side tracking and here you (we) go bringing it back up. See ya in 5 pages and 3 more threads.

It's not our fault PHP is a coding horror.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

king_kilr posted:

It's not our fault PHP is a coding horror.

But it is your fault for using it.

Ogive
Dec 22, 2002

by Lowtax

Avenging Dentist posted:

code:
class iter
{
public:
    foo & operator*();
    const foo & operator*() volatile;
};

typedef iter iterator;
typedef volatile iter const_iterator;

Why?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
In a Qt project:
A colleague had added two text edit widgets to our UI, but they were hidden before the UI was made visible. They were used for getting the row number from a table view.

The table view's activated-signal was connected to a QDataWidgetMapper that set the text edit's value to the row number. Then the text edit's textChanged signal was connected to a custom slot on the UI's parent object. The slot then saved the row number in a private variable.

Then when the user presses a button, the button's event handler uses the private variable to recognize what row in the table view is currently selected.

The other text edit was used in a similar way, except for another table.

Okay, so maybe you don't have a lot of experience with Qt, but I'm pretty sure every framework has a better solution to the problem than "// TODO: ugly hack, needs to be removed"

zombienietzsche
Dec 9, 2003
code:
    public static bool operator ==(Fund f1, Fund f2)
    {
        try
        {
            if (f1.fundId == f2.fundId)
                return true;
            if (f1.Linker == f2.Linker && f1.classId == f2.classId && f1.Date == f2.Date)
                return true;
            if (f1.FundProductRelationId == f2.FundProductRelationId)
                return true;
        }
        catch (NullReferenceException)
        {
            try
            {
                Guid? checkAgain = f1.fundId;
            }
            catch (NullReferenceException)
            {
                try
                {
                    Guid? checkOneLastTime = f2.fundId;
                }
                catch (NullReferenceException)
                {
                    return true;
                }
            }
            return false;
        }
        return false;
    }

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.
He must be following the new "don't use the keyword null" coding standard.

MagneticWombats
Aug 19, 2004
JUMP!
Ugh, everyone knows you have to check at least 4 times

tef
May 30, 2004

-> some l-system crap ->
It might be some 'fix' for some horrible locking bug :v:

Zhentar
Sep 28, 2003

Brilliant Master Genius

Insurrectum posted:

Goddamn. Looks like I made the right choice.

MUMPS is totally awesome and will train you into a programming legend!

code:
torment(poster) ;
	L+ ^CoC(poster)
	i  d  i 1
	. s ^CoC(poster)="I Love MUMPS!"
	. w !,poster," has been tormented."
	. L- ^CoC(poster)
	e  d  
	. w !,poster," was not available for torment."
	q
code:
d torment("Avenging Dentist")
P.S. "A Case of the MUMPS" has a fairly small intersection with reality, so don't take too much of it to heart.

Zombywuf
Mar 29, 2008

meinstein posted:

code:
    public static bool operator ==(Fund f1, Fund f2)
    {
        try
        {
            if (f1.fundId == f2.fundId)
                return true;
            if (f1.Linker == f2.Linker && f1.classId == f2.classId && f1.Date == f2.Date)
                return true;
            if (f1.FundProductRelationId == f2.FundProductRelationId)
                return true;
        }
        catch (NullReferenceException)
        {
            try
            {
                Guid? checkAgain = f1.fundId;
            }
            catch (NullReferenceException)
            {
                try
                {
                    Guid? checkOneLastTime = f2.fundId;
                }
                catch (NullReferenceException)
                {
                    return true;
                }
            }
            return false;
        }
        return false;
    }
Was this written by a DB guy?

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Zhentar posted:

P.S. "A Case of the MUMPS" has a fairly small intersection with reality, so don't take too much of it to heart.

Yeah, the reality is actually worse.

EDIT: Another fun coding horror. This post was originally rendering as blank despite being valid, and only when I edited it did it show up. :waycool:

Avenging Dentist fucked around with this message at 22:09 on Aug 24, 2009

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