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
PrBacterio
Jul 19, 2000

Ithaqua posted:

Not according to what he said -- they're duplicating functionality. The common functionality needs to be implemented in the base class in a non-virtual method, which possibly calls some virtual/abstract methods that contain differing, implementation-specific code.

Of course, I'm not sure what you're calling an "interface" there, since there are no interfaces anywhere in the example, and an interface isn't appropriate for what he was talking about anyway.
I was talking about this part:

quote:

The horror is that the base has all of it's member functions implemented as no-ops
which sounds to me like the base class is just supposed to represent an abstract interface. I hadn't read the part about all of the derived classes being copy&pastes of one another which *does* sound like all that code ought to have gone in the base class instead (or all be derived from a common base class which itself derives from the existing interface class).

Adbot
ADBOT LOVES YOU

w00tz0r
Aug 10, 2006

I'm just so god damn happy.

PrBacterio posted:

I hadn't read the part about all of the derived classes being copy&pastes of one another which *does* sound like all that code ought to have gone in the base class instead.

It's this. I'm fully aware of what an interface is, and I do think that these two classes should implement themselves in terms of A. The problem I have is that out of all of the member functions in A, only two of them have any business being overridden in a derived class. Instead, the entire class got copied, and the implementation was stripped completely out of A.

NinjaDebugger
Apr 22, 2008


w00tz0r posted:

It's this. I'm fully aware of what an interface is, and I do think that these two classes should implement themselves in terms of A. The problem I have is that out of all of the member functions in A, only two of them have any business being overridden in a derived class. Instead, the entire class got copied, and the implementation was stripped completely out of A.

If this is C++, I've seen people do that repeatedly, in order to mimic Java structure by creating a "pure" interface. Their normal course from there, though, is to create an abstract implementation of that interface for any common functionality.

Beef
Jul 26, 2004
The person who wrote that horror needs to be hit over the head with a manual explaining the differences between Java's and C++'s OO models.

The copy/pasting or calling an object-external 'doSomething' is common in Java because you can't do multiple inheritance. Think KeyboardHandler and MouseHandler being partial implementation of the same Handlers abstract class; need a KeyboardAndMouseHandler, better start copy pasting buddy.

The least they could do is to make the virtual function pure in the abstract class, goddamn.

baquerd
Jul 2, 2007

by FactsAreUseless
code:
throw new java//commenting practices into your code today
/*and comment statements as they are being formed*/.
//While this may create longer statements
/*in the*/lang//uage the natural and seamless
/*integration is well worth it*/.//just be careful
//to pay attention next time so you don't get
/*yet another*/ UnsupportedOperationException
//you dumb rear end coder
();

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

baquerd posted:

code:
throw new java//commenting practices into your code today
/*and comment statements as they are being formed*/.
//While this may create longer statements
/*in the*/lang//uage the natural and seamless
/*integration is well worth it*/.//just be careful
//to pay attention next time so you don't get
/*yet another*/ UnsupportedOperationException
//you dumb rear end coder
();

:swoon: It is... beautiful

w00tz0r
Aug 10, 2006

I'm just so god damn happy.

baquerd posted:

code:
throw new java//commenting practices into your code today
/*and comment statements as they are being formed*/.
//While this may create longer statements
/*in the*/lang//uage the natural and seamless
/*integration is well worth it*/.//just be careful
//to pay attention next time so you don't get
/*yet another*/ UnsupportedOperationException
//you dumb rear end coder
();

Bravo :golfclap:

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

baquerd posted:

code:
throw new java//commenting practices into your code today
/*and comment statements as they are being formed*/.
//While this may create longer statements
/*in the*/lang//uage the natural and seamless
/*integration is well worth it*/.//just be careful
//to pay attention next time so you don't get
/*yet another*/ UnsupportedOperationException
//you dumb rear end coder
();

I feel like this should be in an art gallery somewhere.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I recently had to look into some code that a contractor wrote last year that inexplicably takes much longer when processing multiple warehouses than a single warehouse.
code:
if(!multiplewarehouse)
{
    foreach(ShippingMethod shipMethod in ShippingMethods)
    {
        foreach(Package pkg in Packages)
        {
            ...
        }
    }
}
else
{
    foreach(ShippingMethod shipMethod in ShippingMethods)
    {
        foreach(Package pkg in Packages)
        {
            foreach(ShippingMethod otherShipMethod in ShippingMethods)
            {
                if(shipMethod != otherShipMethod)
                    continue;
                ...
            }
        }
    }
}
I wish he hadn't been fired so I could ask him what the hell he was thinking.

TiltedAtWindmills
Sep 4, 2009
That reads like one of those dumb Xzibit memes:

"Yo dawg I heard you liked ShippingMethods...", etc.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

loinburger posted:

I wish he hadn't been fired so I could ask him what the hell he was thinking.

Well, either he was saving it for "optimization overtime" later, or he wanted to make really sure that the shipping method was valid. By comparing it to itself.

:v:

SlightlyMadman
Jan 14, 2005

I like to give code like that the benefit of the doubt, and assume there was more code there at one point that made that at least somewhat logical, then that code was removed and it didn't occur to him to refactor. Then again, in some ways that's even worse.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

SlightlyMadman posted:

I like to give code like that the benefit of the doubt, and assume there was more code there at one point that made that at least somewhat logical, then that code was removed and it didn't occur to him to refactor. Then again, in some ways that's even worse.

This is the true reason for source control. Not for rollbacks, but for laughs after the fact.

SlightlyMadman
Jan 14, 2005

OriginalPseudonym posted:

This is the true reason for source control. Not for rollbacks, but for laughs after the fact.

"svn blame" is possibly the best thing to ever have happened in computer history.

Optimus Prime Ribs
Jul 25, 2007

I'm not really sure what this was supposed to be used for. Written by some dude a year ago, who left where I work before I got there.
This is all that was in the file. :iiam:

php:
<?
$gConfig = array();
require "../../../config/config.php";

$db_connection_str = "host=" . $gConfig['db']['event']['host'] . " dbname=" . $gConfig['db']['event']['name'] . " user=" . $gConfig['db']['event']['user'] . " password=" . $gConfig['db']['event']['password'];
$db_connection = pg_pconnect($db_connection_str);

$stmt = "select * from _event where event_id = " . $_POST['event_id'];

$result = pg_query($db_connection, $stmt);
if( pg_num_rows($result) > 0 ){
    $handle = fopen("../site/config/config.txt", "w");
    fwrite($handle, $_POST['event_id']);
    fclose($handle);
    $url = "index.php";
}
else{
    $url = "index.php?error=event_id_error&&event_id=" . $_POST['event_id'];
}

header( "Location: $url" );
?>

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Optimus Prime Ribs posted:

:words:

I kind of want to see what's in the event table. Either he has a really poorly named log file, or he's dynamically generating a config file for another script based on database output...? :iiam:

npe
Oct 15, 2004
Well hello there thread, how ya been.

code:
	public static boolean checkPageSequenceOrder(String path, String checkString) {
		String pageNum = path.substring(path.lastIndexOf("_T") + 2, path.lastIndexOf(Globals.FileTypes.IMAGE_TIFF.getExtension()));
		
		if(pageNum != null) {
			
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			
			if(pageNum.equals("")) {
				pageNum = "0";
			}
			
			if(!pageNum.equalsIgnoreCase(checkString)) {
				return false;
			}
		}
		
		return true;
	}

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

loinburger posted:

I recently had to look into some code that a contractor wrote last year that inexplicably takes much longer when processing multiple warehouses than a single warehouse.

(stuff)

I wish he hadn't been fired so I could ask him what the hell he was thinking.

What industry are you in? I had to write almost identical code for my last job in ecommerce/drop shipping. (minus the horror of course)

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

npe posted:

Well hello there thread, how ya been.

code:
	public static boolean checkPageSequenceOrder(String path, String checkString) {
		String pageNum = path.substring(path.lastIndexOf("_T") + 2, path.lastIndexOf(Globals.FileTypes.IMAGE_TIFF.getExtension()));
		
		if(pageNum != null) {
			
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			if(pageNum.startsWith("0") && pageNum.length() > 1) pageNum = pageNum.substring(1);
			
			if(pageNum.equals("")) {
				pageNum = "0";
			}
			
			if(!pageNum.equalsIgnoreCase(checkString)) {
				return false;
			}
		}
		
		return true;
	}

Load-bearing variable assignment, because having just one didn't work. Although this probably isn't one, this has always been the best way to fix a race condition, along with debug print statements.

:v:

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
code:
    do{
                c = fgetc(file);
                if(31 < c && c < 127){
                        c = fgetc(file);
                        if(31 < c && c < 127){
                                c = fgetc(file);
                                if(31 < c && c < 127){
                                        c = fgetc(file);
                                        if(31 < c && c < 127){
                                                fseek(file, -4, SEEK_CUR);
                                                c = fgetc(file);
                                                i = 0;
                                                while(31 < c && c < 127){
                                                        string[i] = (char)c;
                                                        c = fgetc(file);
                                                        i++;
                                                }
                                                string[i] = NULL;
                                                printf("%s\n", string);
                                        }
                                }
                        }
                }
        }while((char)c != EOF);
:eng99: I don't like grading (I don't teach this class, I promise).

nielsm
Jun 1, 2009



OriginalPseudonym posted:

Load-bearing variable assignment, because having just one didn't work. Although this probably isn't one, this has always been the best way to fix a race condition, along with debug print statements.

:v:

Nah, it isn't trying to do the same thing multiple time to get over race conditions or so. It actually removes up to three leading zeroes in pageNum.

NotShadowStar
Sep 20, 2000

clockwork automaton posted:

code:
    do{
                c = fgetc(file);
                if(31 < c && c < 127){
                        c = fgetc(file);
                        if(31 < c && c < 127){
                                c = fgetc(file);
                                if(31 < c && c < 127){
                                        c = fgetc(file);
                                        if(31 < c && c < 127){
                                                fseek(file, -4, SEEK_CUR);
                                                c = fgetc(file);
                                                i = 0;
                                                while(31 < c && c < 127){
                                                        string[i] = (char)c;
                                                        c = fgetc(file);
                                                        i++;
                                                }
                                                string[i] = NULL;
                                                printf("%s\n", string);
                                        }
                                }
                        }
                }
        }while((char)c != EOF);
:eng99: I don't like grading (I don't teach this class, I promise).

what in sweet gently caress

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

clockwork automaton posted:

:eng99: I don't like grading (I don't teach this class, I promise).
Grading is awesome because you get to punish people for writing terrible code rather than having to just sigh and put up with it.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
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)

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.

Beef
Jul 26, 2004
For nearly all programming assignments our students have to come defend their code in person. This gives us ample opportunity to tell them how and why they absolutely suck at coding.

Zombywuf
Mar 29, 2008

clockwork automaton posted:

code:
    do{
                c = fgetc(file);
                if(31 < c && c < 127){
                        c = fgetc(file);
                        if(31 < c && c < 127){
                                c = fgetc(file);
                                if(31 < c && c < 127){
                                        c = fgetc(file);
                                        if(31 < c && c < 127){
                                                fseek(file, -4, SEEK_CUR);
                                                c = fgetc(file);
                                                i = 0;
                                                while(31 < c && c < 127){
                                                        string[i] = (char)c;
                                                        c = fgetc(file);
                                                        i++;
                                                }
                                                string[i] = NULL;
                                                printf("%s\n", string);
                                        }
                                }
                        }
                }
        }while((char)c != EOF);
:eng99: I don't like grading (I don't teach this class, I promise).

TBH that looks like an excellent teaching opportunity.

loinburger
Jul 10, 2004
Sweet Sauce Jones

Scaramouche posted:

What industry are you in? I had to write almost identical code for my last job in ecommerce/drop shipping. (minus the horror of course)

Same industry. Another piece of code I had to rewrite from the same contractor was the box-packing algorithm - the way the contractor's code put items in boxes was "If the items' dimensions fit in the empty box, and there is sufficient unused volume in the box, then the item fits!" In other words, given a 12x12x12 box (volume 1728) and three 8x8x8 items (combined volume 1536), the algorithm would put all three items in the box, even though this is sort of impossible.

When I rewrote the algorithm to prevent overlapping boxes, the QA guy on the project complained that the new algorithm used more box volume than the old algorithm.

loin: That's because the old algorithm allowed boxes to overlap.
QA Guy: Well, we never worried about overlapping boxes before.
loin: I suggest we start worrying about it.

shodanjr_gr
Nov 20, 2007

clockwork automaton posted:

code:
    do{
                c = fgetc(file);
                if(31 < c && c < 127){
                        c = fgetc(file);
                        if(31 < c && c < 127){
                                c = fgetc(file);
                                if(31 < c && c < 127){
                                        c = fgetc(file);
                                        if(31 < c && c < 127){
                                                fseek(file, -4, SEEK_CUR);
                                                c = fgetc(file);
                                                i = 0;
                                                while(31 < c && c < 127){
                                                        string[i] = (char)c;
                                                        c = fgetc(file);
                                                        i++;
                                                }
                                                string[i] = NULL;
                                                printf("%s\n", string);
                                        }
                                }
                        }
                }
        }while((char)c != EOF);
:eng99: I don't like grading (I don't teach this class, I promise).

OK, i decided to decipher what this does as a brain teaser...was the title of the assignment "Print all continuous string of non-control ASCII characters with a length of 4 or more from a file" or something?

SlightlyMadman
Jan 14, 2005

Optimus Prime Ribs posted:

I'm not really sure what this was supposed to be used for. Written by some dude a year ago, who left where I work before I got there.
This is all that was in the file. :iiam:

php:
<?
$gConfig = array();
require "../../../config/config.php";

$db_connection_str = "host=" . $gConfig['db']['event']['host'] . " dbname=" . $gConfig['db']['event']['name'] . " user=" . $gConfig['db']['event']['user'] . " password=" . $gConfig['db']['event']['password'];
$db_connection = pg_pconnect($db_connection_str);

$stmt = "select * from _event where event_id = " . $_POST['event_id'];

$result = pg_query($db_connection, $stmt);
if( pg_num_rows($result) > 0 ){
    $handle = fopen("../site/config/config.txt", "w");
    fwrite($handle, $_POST['event_id']);
    fclose($handle);
    $url = "index.php";
}
else{
    $url = "index.php?error=event_id_error&&event_id=" . $_POST['event_id'];
}

header( "Location: $url" );
?>

How quickly you forget! Clearly it's there to write out this config file:

Optimus Prime Ribs posted:

Found this in the backend for our CMS:
php:
<?
$current_event_id = "";
if(file_exists("../site/config/config.txt")){
    $config_file_lines = file("config/config.txt");
    foreach( $config_file_lines as $config_file_line ){
        if( trim($config_file_line) != "" ){
            $current_event_id = trim($config_file_line);
        }
    }
}?>

molinari
May 13, 2005

code:
#define  B  0x80  /* Busy = 1 */
code:
#ifndef DEBUG
#define printf(...) ((void)0)
#endif
I'm going home now.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
http://forums.silverlight.net/t/240580.aspx/1?126+000+lines+of+code+System+OutOfMemoryException

quote:

Hi,

I do have a question. In my MainPage.xaml.cs file, I am on the 126,000:th line now coding. Sometimes when I compile I get this below exception that tell about OutOfMemoryException.

I wonder if this depends on the big amount of code. I have 3.5 GB of RAM and there is 1.5 GB Free RAM when I compile. My XAML contain of approx: 15,000 lines of code.

Source file 'D:\Documents and Settings\A\My Documents\Visual Studio 2010\Projects\thisProj\thisProj\MainPage.xaml.cs' could not be opened ('Exception of type 'System.OutOfMemoryException' was thrown.')

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

I don't always edit code, but when I do, I have to use cat and tail.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

How do you write 100,000 lines of code in a single file before you think to yourself "surely there's a better way to organize this"?

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe

shodanjr_gr posted:

OK, i decided to decipher what this does as a brain teaser...was the title of the assignment "Print all continuous string of non-control ASCII characters with a length of 4 or more from a file" or something?

Yes. Also I don't work directly with any of the students for this class (I am a TA for a different class and just a grader for this one), but I did leave comments for how this could be written to be more sane. I would actually like some class here to at least mention refactoring or at least teach them what makes good code good. This particular class teaches them that "goto" is bad, but doesn't really step any further than that.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Ah yes, I can see it now..

baquerd posted:

code:
throw new java//commenting practices into your code today
/*and comment statements as they are being formed*/.
//While this may create longer statements
/*in the*/lang//uage the natural and seamless
/*integration is well worth it*/.//just be careful
//to pay attention next time so you don't get
/*yet another*/ UnsupportedOperationException
//you dumb rear end coder
();

Inverse Icarus posted:

code:
// checking below me
// no children to right or left
// i am a leaf node

"Beauty and Rage", Museum of Modern Programming, 2011.

shodanjr_gr
Nov 20, 2007

clockwork automaton posted:

Yes. Also I don't work directly with any of the students for this class (I am a TA for a different class and just a grader for this one), but I did leave comments for how this could be written to be more sane. I would actually like some class here to at least mention refactoring or at least teach them what makes good code good. This particular class teaches them that "goto" is bad, but doesn't really step any further than that.

Well, at least that guy got it right :P.

When I was a grader for a CSE 2xx course (Foundations of Computer Science) and the students had to turn in some basic code in (I believe) OCAML (and ONLY that), I had the joy of receiving assignments in anything from C, C++, BASIC to freaking pseudo code.

The joys of grading...

Optimus Prime Ribs
Jul 25, 2007

SlightlyMadman posted:

How quickly you forget! Clearly it's there to write out this config file:

Well I know what it's doing. I just don't know what purpose it serves.
Maybe the dude really badly wanted to assign an event id to the text file using POST data, and do literally nothing else.

Makes me wonder why he didn't just use a GET variable in the URL for the id.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Optimus Prime Ribs posted:

Well I know what it's doing. I just don't know what purpose it serves.
Maybe the dude really badly wanted to assign an event id to the text file using POST data, and do literally nothing else.

Makes me wonder why he didn't just use a GET variable in the URL for the id.

In a week you'll have found the PHP script that's being run by cron that posts back to that config file.

Adbot
ADBOT LOVES YOU

SlightlyMadman
Jan 14, 2005

OriginalPseudonym posted:

In a week you'll have found the PHP script that's being run by cron that posts back to that config file.

No, it loads that script that pulls the event id from config.txt, then writes it to the database.

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