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
npe
Oct 15, 2004
I've got two PL/SQL ones that I found recently. First, I found this:

code:

        EXCEPTION WHEN OTHERS THEN
            io_jobid := NULL;
            COMMIT;
        END;

For those of you who don't know PL/SQL but maybe know java, EXCEPTION WHEN OTHERS is the equivalent of "catch (Exception e)", which is bad enough. Putting the commit in there is like adding an additional "gently caress you" to whoever is calling the code... swallowing your exception and then preventing you from a rollback. :gonk:

Also, this gem was found by a coworker and while it doesn't look terrible, it led to a ridiculous bug:

code:
CREATE OR REPLACE PROCEDURE delete_user

<snip>

    UPDATE users
       SET is_deleted = 1
     WHERE userid = delete_user.userid;

    COMMIT;
END;
Inside this code is lurking an insidious bug: at some point the "users" table was altered and the column "userid" went away (replaced by another column). This package should have been changed but was not... Normally in Oracle when a table is altered, any packages that reference that table are invalidated and have to be recompiled (which happened), and if there are references to non-existent columns the compile will fail. But this code compiled just fine, and it even runs!

Of course, since userid can't be found in the table, and it wasn't explicitly referenced as users.userid, Oracle is helpful and assumes you mean the lexically scoped delete_user.userid, turning that condition into WHERE delete_users.userid = delete_users.userid. So we've set is_deleted on every single user!

And then it loving commits!

Jesus gently caress people, do not ever put commit in your procedure.

npe fucked around with this message at 21:52 on Mar 21, 2008

Adbot
ADBOT LOVES YOU

npe
Oct 15, 2004

tef posted:

This do?

Is there a das keyboard version?

npe
Oct 15, 2004

quote:

Then you're no friend of mine. There's a difference between being concise and golfing (which Perl folk love to do) and this isn't golfing. The entire field of computer science has been about a power versus concision payoff. And if you can't see that, then you're hopeless.

You guys are arguing about inelegant code, which can be annoying if there's a lot of it sure, but I have a hard time calling it really a "code horror", unless you're the type of person that gets in a huff about everyone's bike shed.

For me, true code horror is when you realize that the author clearly doesn't have any idea whatsoever that what they are doing is terribly dangerous and evil (see my COMMIT in stored procedures rant from earlier), or just so outright incompetent that it's obvious the author doesn't really "get" programming in any way, like in the following (apologies for recycling this from the last thread, it's just too drat hilarious to me):

code:
  my $perms = stat($path);
  my $permsbin = unpack("B32",pack("N",$perms->mode & 0777));
  $permsbin =~ s/.*(.)..(.)..(.)../$1$2$3/;

  # check if file is not readable
  if ($permsbin != 111) {
    # error!
    # ...snip...
  }

npe
Oct 15, 2004
poo poo, if I can get a few people to sleepily stare at my code for a few seconds during a code review, that's a good day.

npe
Oct 15, 2004
Some of the old perl code I've found here was written by someone who seemed to think entire subroutines had to be on a single line. Lots of

code:

sub foo {my $blah=$_[0];foreach my $item(@_){etc etc etc}return $foo;}

I also found a hash definition that line wraps 14 times in my text editor. :psyduck:

npe
Oct 15, 2004
Sometimes I think that if CoC had it's own YCS/helldump/BYOB style subforum, many people would have a hell of a time telling the difference.

npe
Oct 15, 2004

npe fucked around with this message at 01:52 on Apr 26, 2008

npe
Oct 15, 2004

npe
Oct 15, 2004
Today's horror is that I'm still arguing with people about why you can't delimit a file with literal 0xFE bytes when you want the delimited data to contain utf8 multibyte characters.

A couple of people have now actually said "...but I thought all bytes were valid utf8?" :psyduck:

npe
Oct 15, 2004
I should have clarified, the file has to be a valid "text" file in single encoding. While you could delimit the data like that, it would be mixed encoding and would piss off text editors.

In other words, the 0xFE bytes are tripping complaints from programs reading them about that byte not being valid utf8, and this is where the wtf complaints come from... "I thought anything could be unicode".

npe fucked around with this message at 13:59 on Jun 14, 2008

npe
Oct 15, 2004

geetee posted:

It only got worse after I emailed him my reply. Here's more bullshit:

You know, I'm not going to defend this guy or what he's doing, but I think I've seen this solution before from people who want to simulate Oracle style sequences. Usually though, it's wrapped up in a single procedure to sort of hide the unpleasantness of it.

I guess maybe I'm too used to Oracle, where out of the box we regularly have to query out of a one column, one row table to get certain types of queries to work.

npe
Oct 15, 2004

Iniluki posted:


If you can't be bothered reading it all, and I don't blame you, several tables are aliased multiple times with different aliases.


By itself, that's not a "coding horror". In fact, it's necessary for lots of legitimate queries.

Whether or not this particular query is terrible in other ways, I have no idea.

npe
Oct 15, 2004
code:
while (ii < arrayList.size())
{
	ss = arrayList.get(ii);
	jj = ss.indexOf(',');
	if (jj < 0)
	{
		++ii;
		continue;
	}
	cc = ss.charAt(jj + 1);
	serialNo = ss.substring(0, jj);
	tempSerialNo = ss.substring(0, jj);
	sb.append("\"" + serialNo + "\",");
	if (cc == 'A' && serialNo.equals(tempSerialNo))
	{
		sb.append("\"" + ss.substring(jj + 3) + "\",");
		if (ii < arrayList.size() - 1)
		{
			++ii;
			ss = arrayList.get(ii);
			jj = ss.indexOf(',');
			cc = ss.charAt(jj + 1);
			tempSerialNo = ss.substring(0, jj);
		}
	} else
	{
		sb.append("\"\",");
	}
	if (cc == 'B' && serialNo.equals(tempSerialNo))
	{
		sb.append("\"" + ss.substring(jj + 3) + "\",");
		if (ii < arrayList.size() - 1)
		{
			++ii;
			ss = arrayList.get(ii);
			jj = ss.indexOf(',');
			cc = ss.charAt(jj + 1);
			tempSerialNo = ss.substring(0, jj);
		}
	} else
	{
		sb.append("\"\",");
	}
	if (cc == 'C' && serialNo.equals(tempSerialNo))
	{
		sb.append("\"" + ss.substring(jj + 3) + "\",");
		if (ii < arrayList.size() - 1)
		{
			++ii;
			ss = arrayList.get(ii);
			jj = ss.indexOf(',');
			cc = ss.charAt(jj + 1);
			tempSerialNo = ss.substring(0, jj);
		}
	} else
	{
		sb.append("\"\",");
	}

	if (firstPass)
	{
		sb.append("\"D\"\r\n");
		firstPass = false;
	} else
	{
		sb.append("\"\"\r\n");
	}
	++ii;
}
A small sample of what we've been finding lately from one of our more interesting developers.

npe
Oct 15, 2004
Clearly there needs to be an IRegistrationInputSource which requires methods getName and getRoom. The Register class should be able to take an object that implements this and use it to obtain the information. A ScannerInputSource class can then be implemented that manages the use of the scanner, but future implementations can be developed and the correct one can be chosen at runtime.

:suicide:

npe
Oct 15, 2004
Found this bit of java code to left pad a number with zeros...

code:
String ss = "0000000000000000" + Integer.toString(suffix); 
sb.append(ss.substring(ss.length() - pad_size));

npe
Oct 15, 2004

HFX posted:

It could be a bug, but would be very likely in a pre 1.5 environment. I was unaware of the format on String until you mentioned it. Now, I feel terrible for some places where I used while loops on String buffers to pad them.

No, this guy is just crazy, this is all recent code (within the last year) and we regularly use StringUtils (which has a leftPad() function) all over the place. He also likes to pack multiple variables into a single comma separated string so it can later be picked apart via substring() to get at the relevant parts. This is to "work around" java's lack of multiple return values as he puts it.

npe
Oct 15, 2004

HFX posted:

Couldn't he just use a list to do the same thing, thereby forming a tuple?

His response to all of these types of questions is "this works pretty well."

He's crazy. I just try to keep him away from anything I'll have to work on.

npe
Oct 15, 2004
Structs are nice for their non-nullability as well, which helps with ensuring correctness (or at least pushing the incorrect code around to where it should be).

npe
Oct 15, 2004
Dear Penthouse:

I never thought it would happen to me. For years, I've been reading sordid tales of the "for case" paradigm, but I never thought they actually happened! But today, I found this in svn...

quote:

Changeset 19314 for AutomatedUser

Timestamp:
11/02/10 14:33:14 (2 weeks ago)

-Added 50 more workers to make 100. I put the calls to start each worker in a while loop. This is not ideal. I really wanted to make an array (or other container) of workers and handle them throughout the code using loops. But VB doesn't like it when you try to put "Friend WithEvents?" types of objects into an array. There are ways of working with that and if I need to make > 100 workers I'll check them out. Each worker is its own thread.

code:
 		        Me.BackgroundWorker51 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker52 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker53 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker54 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker55 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker56 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker57 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker58 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker59 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker60 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker61 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker62 = New System.ComponentModel.BackgroundWorker() 
 		        Me.BackgroundWorker63 = New System.ComponentModel.BackgroundWorker() 

...etc
code:
 		    Friend WithEvents BackgroundWorker51 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker52 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker53 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker54 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker55 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker56 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker57 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker58 As System.ComponentModel.BackgroundWorker 
 		    Friend WithEvents BackgroundWorker59 As System.ComponentModel.BackgroundWorker 

...etc
...wait for it...

code:
 		    Private Sub BackgroundWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker100.DoWork, _ 
 		                        BackgroundWorker99.DoWork, BackgroundWorker98.DoWork, BackgroundWorker97.DoWork, BackgroundWorker96.DoWork, BackgroundWorker95.DoWork, _ 
 		                        BackgroundWorker94.DoWork, BackgroundWorker93.DoWork, BackgroundWorker92.DoWork, BackgroundWorker91.DoWork, BackgroundWorker90.DoWork, _ 
 		                        BackgroundWorker89.DoWork, BackgroundWorker88.DoWork, BackgroundWorker87.DoWork, BackgroundWorker86.DoWork, BackgroundWorker85.DoWork, _ 
 		                        BackgroundWorker84.DoWork, BackgroundWorker83.DoWork, BackgroundWorker82.DoWork, BackgroundWorker81.DoWork, BackgroundWorker80.DoWork, _ 
 		                        BackgroundWorker79.DoWork, BackgroundWorker78.DoWork, BackgroundWorker77.DoWork, BackgroundWorker76.DoWork, BackgroundWorker75.DoWork, _ 
 		                        BackgroundWorker74.DoWork, BackgroundWorker73.DoWork, BackgroundWorker72.DoWork, BackgroundWorker71.DoWork, BackgroundWorker70.DoWork, _ 
 		                        BackgroundWorker69.DoWork, BackgroundWorker68.DoWork, BackgroundWorker67.DoWork, BackgroundWorker66.DoWork, BackgroundWorker65.DoWork, _ 
 		                        BackgroundWorker64.DoWork, BackgroundWorker63.DoWork, BackgroundWorker62.DoWork, BackgroundWorker61.DoWork, BackgroundWorker60.DoWork, _ 
 		                        BackgroundWorker59.DoWork, BackgroundWorker58.DoWork, BackgroundWorker57.DoWork, BackgroundWorker56.DoWork, BackgroundWorker55.DoWork, _ 
 		                        BackgroundWorker54.DoWork, BackgroundWorker53.DoWork, BackgroundWorker52.DoWork, BackgroundWorker51.DoWork, BackgroundWorker50.DoWork, _ 
 		                        BackgroundWorker49.DoWork, BackgroundWorker48.DoWork, BackgroundWorker47.DoWork, BackgroundWorker46.DoWork, _ 
 		                        BackgroundWorker45.DoWork, BackgroundWorker44.DoWork, BackgroundWorker43.DoWork, BackgroundWorker42.DoWork, _ 
 		                        BackgroundWorker41.DoWork, BackgroundWorker40.DoWork, BackgroundWorker39.DoWork, BackgroundWorker38.DoWork, _ 
 		                        BackgroundWorker37.DoWork, BackgroundWorker36.DoWork, BackgroundWorker35.DoWork, BackgroundWorker34.DoWork, _ 
 		                        BackgroundWorker33.DoWork, BackgroundWorker32.DoWork, BackgroundWorker31.DoWork, BackgroundWorker30.DoWork, _ 
 		                        BackgroundWorker29.DoWork, BackgroundWorker28.DoWork, BackgroundWorker27.DoWork, BackgroundWorker26.DoWork, _ 
 		                        BackgroundWorker25.DoWork, BackgroundWorker24.DoWork, BackgroundWorker23.DoWork, BackgroundWorker22.DoWork, _ 
 		                        BackgroundWorker21.DoWork, BackgroundWorker20.DoWork, BackgroundWorker19.DoWork, BackgroundWorker18.DoWork, _ 
 		                        BackgroundWorker17.DoWork, BackgroundWorker16.DoWork, BackgroundWorker15.DoWork, BackgroundWorker14.DoWork, _ 
 		                        BackgroundWorker13.DoWork, BackgroundWorker12.DoWork, BackgroundWorker11.DoWork, BackgroundWorker10.DoWork, _ 
 		                        BackgroundWorker9.DoWork, BackgroundWorker8.DoWork, BackgroundWorker7.DoWork, BackgroundWorker6.DoWork, _ 
 		                        BackgroundWorker5.DoWork, BackgroundWorker4.DoWork, BackgroundWorker3.DoWork, BackgroundWorker2.DoWork, _ 
 		                        BackgroundWorker1.DoWork 
...here it is!

code:
 		        While (ctr > 0) 
 		            Select Case (ctr) 
 		                Case 100 : BackgroundWorker100.RunWorkerAsync() 
 		                Case 99 : BackgroundWorker99.RunWorkerAsync() 
 		                Case 98 : BackgroundWorker98.RunWorkerAsync() 
 		                Case 97 : BackgroundWorker97.RunWorkerAsync() 
 		                Case 96 : BackgroundWorker96.RunWorkerAsync() 
 		                Case 95 : BackgroundWorker95.RunWorkerAsync() 
 		                Case 94 : BackgroundWorker94.RunWorkerAsync() 
 		                Case 93 : BackgroundWorker93.RunWorkerAsync() 
 		                Case 92 : BackgroundWorker92.RunWorkerAsync() 
 		                Case 91 : BackgroundWorker91.RunWorkerAsync() 
 		                Case 90 : BackgroundWorker90.RunWorkerAsync() 
 		                Case 89 : BackgroundWorker89.RunWorkerAsync() 
 		                Case 88 : BackgroundWorker88.RunWorkerAsync() 
 		                Case 87 : BackgroundWorker87.RunWorkerAsync() 
 		                Case 86 : BackgroundWorker86.RunWorkerAsync() 
 		                Case 85 : BackgroundWorker85.RunWorkerAsync() 
 		                Case 84 : BackgroundWorker84.RunWorkerAsync() 
 		                Case 83 : BackgroundWorker83.RunWorkerAsync() 
 		                Case 82 : BackgroundWorker82.RunWorkerAsync() 
 		                Case 81 : BackgroundWorker81.RunWorkerAsync() 
 		                Case 80 : BackgroundWorker80.RunWorkerAsync() 
 		                Case 79 : BackgroundWorker79.RunWorkerAsync() 
 		                Case 78 : BackgroundWorker78.RunWorkerAsync() 
 		                Case 77 : BackgroundWorker77.RunWorkerAsync() 
 		                Case 76 : BackgroundWorker76.RunWorkerAsync() 
 		                Case 75 : BackgroundWorker75.RunWorkerAsync() 
 		                Case 74 : BackgroundWorker74.RunWorkerAsync() 
 		                Case 73 : BackgroundWorker73.RunWorkerAsync() 
 		                Case 72 : BackgroundWorker72.RunWorkerAsync() 
 		                Case 71 : BackgroundWorker71.RunWorkerAsync() 
 		                Case 70 : BackgroundWorker70.RunWorkerAsync() 
 		                Case 69 : BackgroundWorker69.RunWorkerAsync() 
 		                Case 68 : BackgroundWorker68.RunWorkerAsync() 
 		                Case 67 : BackgroundWorker67.RunWorkerAsync() 
 		                Case 66 : BackgroundWorker66.RunWorkerAsync() 
 		                Case 65 : BackgroundWorker65.RunWorkerAsync() 
 		                Case 64 : BackgroundWorker64.RunWorkerAsync() 
 		                Case 63 : BackgroundWorker63.RunWorkerAsync() 
 		                Case 62 : BackgroundWorker62.RunWorkerAsync() 
 		                Case 61 : BackgroundWorker61.RunWorkerAsync() 
 		                Case 60 : BackgroundWorker60.RunWorkerAsync() 
 		                Case 59 : BackgroundWorker59.RunWorkerAsync() 
 		                Case 58 : BackgroundWorker58.RunWorkerAsync() 
 		                Case 57 : BackgroundWorker57.RunWorkerAsync() 
 		                Case 56 : BackgroundWorker56.RunWorkerAsync() 
 		                Case 55 : BackgroundWorker55.RunWorkerAsync() 
 		                Case 54 : BackgroundWorker54.RunWorkerAsync() 
 		                Case 53 : BackgroundWorker53.RunWorkerAsync() 
 		                Case 52 : BackgroundWorker52.RunWorkerAsync() 
 		                Case 51 : BackgroundWorker51.RunWorkerAsync() 
 		                Case 50 : BackgroundWorker50.RunWorkerAsync() 
 		                Case 49 : BackgroundWorker49.RunWorkerAsync() 
 		                Case 48 : BackgroundWorker48.RunWorkerAsync() 
 		                Case 47 : BackgroundWorker47.RunWorkerAsync() 
 		                Case 46 : BackgroundWorker46.RunWorkerAsync() 
 		                Case 45 : BackgroundWorker45.RunWorkerAsync() 
 		                Case 44 : BackgroundWorker44.RunWorkerAsync() 
 		                Case 43 : BackgroundWorker43.RunWorkerAsync() 
 		                Case 42 : BackgroundWorker42.RunWorkerAsync() 
 		                Case 41 : BackgroundWorker41.RunWorkerAsync() 
 		                Case 40 : BackgroundWorker40.RunWorkerAsync() 
 		                Case 39 : BackgroundWorker39.RunWorkerAsync() 
 		                Case 38 : BackgroundWorker38.RunWorkerAsync() 
 		                Case 37 : BackgroundWorker37.RunWorkerAsync() 
 		                Case 36 : BackgroundWorker36.RunWorkerAsync() 
 		                Case 35 : BackgroundWorker35.RunWorkerAsync() 
 		                Case 34 : BackgroundWorker34.RunWorkerAsync() 
 		                Case 33 : BackgroundWorker33.RunWorkerAsync() 
 		                Case 32 : BackgroundWorker32.RunWorkerAsync() 
 		                Case 31 : BackgroundWorker31.RunWorkerAsync() 
 		                Case 30 : BackgroundWorker30.RunWorkerAsync() 
 		                Case 29 : BackgroundWorker29.RunWorkerAsync() 
 		                Case 28 : BackgroundWorker28.RunWorkerAsync() 
 		                Case 27 : BackgroundWorker27.RunWorkerAsync() 
 		                Case 26 : BackgroundWorker26.RunWorkerAsync() 
 		                Case 25 : BackgroundWorker25.RunWorkerAsync() 
 		                Case 24 : BackgroundWorker24.RunWorkerAsync() 
 		                Case 23 : BackgroundWorker23.RunWorkerAsync() 
 		                Case 22 : BackgroundWorker22.RunWorkerAsync() 
 		                Case 21 : BackgroundWorker21.RunWorkerAsync() 
 		                Case 20 : BackgroundWorker20.RunWorkerAsync() 
 		                Case 19 : BackgroundWorker19.RunWorkerAsync() 
 		                Case 18 : BackgroundWorker18.RunWorkerAsync() 
 		                Case 17 : BackgroundWorker17.RunWorkerAsync() 
 		                Case 16 : BackgroundWorker16.RunWorkerAsync() 
 		                Case 15 : BackgroundWorker15.RunWorkerAsync() 
 		                Case 14 : BackgroundWorker14.RunWorkerAsync() 
 		                Case 13 : BackgroundWorker13.RunWorkerAsync() 
 		                Case 12 : BackgroundWorker12.RunWorkerAsync() 
 		                Case 11 : BackgroundWorker11.RunWorkerAsync() 
 		                Case 10 : BackgroundWorker10.RunWorkerAsync() 
 		                Case 9 : BackgroundWorker9.RunWorkerAsync() 
 		                Case 8 : BackgroundWorker8.RunWorkerAsync() 
 		                Case 7 : BackgroundWorker7.RunWorkerAsync() 
 		                Case 6 : BackgroundWorker6.RunWorkerAsync() 
 		                Case 5 : BackgroundWorker5.RunWorkerAsync() 
 		                Case 4 : BackgroundWorker4.RunWorkerAsync() 
 		                Case 3 : BackgroundWorker3.RunWorkerAsync() 
 		                Case 2 : BackgroundWorker2.RunWorkerAsync() 
 		                Case 1 : BackgroundWorker1.RunWorkerAsync() 
 		            End Select 
 		            ctr -= 1 
 		        End While 
It was every bit as wonderful as I expected it to be!

npe
Oct 15, 2004

baquerd posted:

I'm not familiar with VB, but is the solution to store a pointer to the objects in an array I assume?

Everything in there is 100% pure insanity. There is no fix.

If you must think about it, though, just know that most of the current code in there can be replaced with a few dozen lines of code that uses ThreadPool.QueueUserWorkItem() and follows some of the ideas in http://msdn.microsoft.com/en-us/library/ms973903.aspx

But we are way past that. Fuckin' arrays, how do they work?!

npe
Oct 15, 2004
Coming up next in the Coding Horrors thread, after the break:

tabs v spaces
brace styles
toilet paper under/over

npe
Oct 15, 2004
code:
        static bool IsUtf16BE(byte[] data)
        {
            if (data.Length < 7)
                return false;
            if ((data[0] == 0) && (data[2] == 0) && (data[4] == 0) && (data[6] == 0))
                return true;
            return false;
        }

        static bool IsUtf16LE(byte[] data)
        {
            if (data.Length < 8)
                return false;
            if ((data[1] == 0) && (data[3] == 0) && (data[5] == 0) && (data[7] == 0))
                return true;
            return false;
        }
:allears:

npe
Oct 15, 2004

Bozart posted:

Someone made this at work in response to the insane requests people made of him:
(redacted to protect the guilty)

Click here for the full 1284x1000 image.


I've also seen "Bug: Square Peg does not fit into Round Hole", which exists solely so that tickets can be closed as a duplicate of it....

npe
Oct 15, 2004

quote:

This is the fatal mistake made by frameworks like Spring XML, as well. As awful as Java can be, it is not improved by replacement with XML. These "configuration" files are always deployed along with the application and are never changed at run time. They dictate the wiring and behaviours of code and are rarely anything other than a representation of a shorter Java program. These configuration files are, in other words, code, albeit code with little to no compile-time checking and a more verbose syntax.

This needed to be said. Shipping "configuration" files that your application code depends on being a certain way just to function is common horror that I don't think is called out enough.

npe
Oct 15, 2004
tabchat should be in YOSPOS, post more code horrors

Today, I stumbled across this line. It made me curious, and I now regret my curiosity.

code:
public final static String NETWORK_ERROR_MSG_SYS = "java.net.SocketException: Network is unreachable: connect";
What could this possibly be used for? Well, it's referenced in a utility class...

code:
	        public static boolean isNetworkConnectionError(Exception exception) {
	               
	                if(exception.getMessage().contains(Globals.NETWORK_ERROR_MSG_SYS)) {
	                        return true;
	                } else {
	                        return false;
	                }
	        }
That's kind of weird. Where could this possibly be useful? There's a few of these floating around:

code:
	        public void checkNetworkConnectionException(Exception e) {
	
	                if(Util.isNetworkConnectionError(e)) {
	                        hasNetworkConnection = false;
	                }
	        }
I'm still confused. On the other hand, that explains all the code littered all over the place like this:

code:

catch (Exception e)
{
  checkNetworkConnectionException(e);
}

But what on earth is it DOING? How is that boolean being used? What is going on here?

code:
	        public void checkIsNetworkConnected() throws Exception{
	       
	                if(!hasNetworkConnection) {
	                        throw new Exception(Globals.NETWORK_ERROR_MSG_1);
	                }
	        }
Oh, of course...

code:
public final static String NETWORK_ERROR_MSG_1 = "Network Connection Has Been Lost";
:suicide:

npe
Oct 15, 2004
I... am not sure what's going on here. But it's funny!

code:
	public static enum ConfigFTP {
		FTP_MOUNT0_PRIMARY_USER("ftp.mount0.primary.username"),
		FTP_MOUNT0_PRIMARY_PWD("ftp.mount0.primary.password"),
		FTP_MOUNT0_PRIMARY_ROOT("ftp.mount0.primary.docroot"),
		FTP_MOUNT0_SECONDARY_USER("ftp.mount0.secondary.username"),
		FTP_MOUNT0_SECONDARY_PWD("ftp.mount0.secondary.password"),
		FTP_MOUNT0_SECONDARY_ROOT("ftp.mount0.secondary.docroot"),
		FTP_MOUNT1_PRIMARY_USER("ftp.mount1.primary.username"),
		FTP_MOUNT1_PRIMARY_PWD("ftp.mount1.primary.password"),
		FTP_MOUNT1_PRIMARY_ROOT("ftp.mount1.primary.docroot"),
		FTP_MOUNT1_SECONDARY_USER("ftp.mount1.secondary.username"),
		FTP_MOUNT1_SECONDARY_PWD("ftp.mount1.secondary.password"),
		FTP_MOUNT1_SECONDARY_ROOT("ftp.mount1.secondary.docroot"),
		FTP_MOUNT2_PRIMARY_USER("ftp.mount2.primary.username"),
		FTP_MOUNT2_PRIMARY_PWD("ftp.mount2.primary.password"),
		FTP_MOUNT2_PRIMARY_ROOT("ftp.mount2.primary.docroot"),
		FTP_MOUNT2_SECONDARY_USER("ftp.mount2.secondary.username"),
		FTP_MOUNT2_SECONDARY_PWD("ftp.mount2.secondary.password"),
		FTP_MOUNT2_SECONDARY_ROOT("ftp.mount2.secondary.docroot"),
		FTP_MOUNT3_PRIMARY_USER("ftp.mount3.primary.username"),
		FTP_MOUNT3_PRIMARY_PWD("ftp.mount3.primary.password"),
		FTP_MOUNT3_PRIMARY_ROOT("ftp.mount3.primary.docroot"),
		FTP_MOUNT3_SECONDARY_USER("ftp.mount3.secondary.username"),
		FTP_MOUNT3_SECONDARY_PWD("ftp.mount3.secondary.password"),
		FTP_MOUNT3_SECONDARY_ROOT("ftp.mount3.secondary.docroot"),
		FTP_MOUNT4_PRIMARY_USER("ftp.mount4.primary.username"),
		FTP_MOUNT4_PRIMARY_PWD("ftp.mount4.primary.password"),
		FTP_MOUNT4_PRIMARY_ROOT("ftp.mount4.primary.docroot"),
		FTP_MOUNT4_SECONDARY_USER("ftp.mount4.secondary.username"),
		FTP_MOUNT4_SECONDARY_PWD("ftp.mount4.secondary.password"),
		FTP_MOUNT4_SECONDARY_ROOT("ftp.mount4.secondary.docroot"),
		FTP_MOUNT5_PRIMARY_USER("ftp.mount5.primary.username"),
		FTP_MOUNT5_PRIMARY_PWD("ftp.mount5.primary.password"),
		FTP_MOUNT5_PRIMARY_ROOT("ftp.mount5.primary.docroot"),
		FTP_MOUNT5_SECONDARY_USER("ftp.mount5.secondary.username"),
		FTP_MOUNT5_SECONDARY_PWD("ftp.mount5.secondary.password"),
		FTP_MOUNT5_SECONDARY_ROOT("ftp.mount5.secondary.docroot"),
		FTP_MOUNT6_PRIMARY_USER("ftp.mount6.primary.username"),
		FTP_MOUNT6_PRIMARY_PWD("ftp.mount6.primary.password"),
		FTP_MOUNT6_PRIMARY_ROOT("ftp.mount6.primary.docroot"),
		FTP_MOUNT6_SECONDARY_USER("ftp.mount6.secondary.username"),
		FTP_MOUNT6_SECONDARY_PWD("ftp.mount6.secondary.password"),
		FTP_MOUNT6_SECONDARY_ROOT("ftp.mount6.secondary.docroot"),
		FTP_MOUNT7_PRIMARY_USER("ftp.mount7.primary.username"),
		FTP_MOUNT7_PRIMARY_PWD("ftp.mount7.primary.password"),
		FTP_MOUNT7_PRIMARY_ROOT("ftp.mount7.primary.docroot"),
		FTP_MOUNT7_SECONDARY_USER("ftp.mount7.secondary.username"),
		FTP_MOUNT7_SECONDARY_PWD("ftp.mount7.secondary.password"),
		FTP_MOUNT7_SECONDARY_ROOT("ftp.mount7.secondary.docroot"),
		FTP_MOUNT8_PRIMARY_USER("ftp.mount8.primary.username"),
		FTP_MOUNT8_PRIMARY_PWD("ftp.mount8.primary.password"),
		FTP_MOUNT8_PRIMARY_ROOT("ftp.mount8.primary.docroot"),
		FTP_MOUNT8_SECONDARY_USER("ftp.mount8.secondary.username"),
		FTP_MOUNT8_SECONDARY_PWD("ftp.mount8.secondary.password"),
		FTP_MOUNT8_SECONDARY_ROOT("ftp.mount8.secondary.docroot"),
		FTP_MOUNT9_PRIMARY_USER("ftp.mount9.primary.username"),
		FTP_MOUNT9_PRIMARY_PWD("ftp.mount9.primary.password"),
		FTP_MOUNT9_PRIMARY_ROOT("ftp.mount9.primary.docroot"),
		FTP_MOUNT9_SECONDARY_USER("ftp.mount9.secondary.username"),
		FTP_MOUNT9_SECONDARY_PWD("ftp.mount9.secondary.password"),
		FTP_MOUNT9_SECONDARY_ROOT("ftp.mount9.secondary.docroot");
		
		private final String name;
		
		private ConfigFTP(String name) {
			this.name = name;
		}
		
		public String toString() {
			return name;
		}
	}

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;
	}

npe
Oct 15, 2004

Zombywuf posted:

Here's the report boss, it comes with data in something that isn't Excel. What's that? I'm fired?

npe
Oct 15, 2004
code:
catch (IOException exception) {
       if (null != exception && exception.getClass().getName().contains("ClientAbortException")) {
         // Occurs if the user hits the stop button. This is
         // considered a valid response that simply never reached the
         // client per the user's request.
         found = true;
         break;
       }

npe
Oct 15, 2004
If we're just tossing out blanket statements for all applications out of our rear end, then I'll use this opportunity to say your application shouldn't be concocting *any* queries on the fly ever - not even via an ORM. Use stored procedures and marshal your complex types. Keep the SQL in the db! :mad:

(If this is not appealing to you then you should be using a document store and not a relational database anyhow.)

*Note: I don't actually believe this. As it turns out, many application domains are completely different from each other and there are very different considerations for each!

npe
Oct 15, 2004

Kim Jong III posted:

I've seen this in practice.

:smithicide:

I wasn't seriously advocating that it be used everywhere (like, it would be stupid for a web app).

However, it can be very appropriate if you are already committed to a significant amount of application logic residing in the database to begin with (which is true for applications that rely heavily on certain Oracle components, for example). At my current job we do it and it's very easy, since I'm able to treat the database as just another callable component just like any other library. The implementation of the table structures is completely hidden from me, and whenever there's some whack-rear end restructuring of things, my changes (if any) are reduced to contract changes in the API.

npe
Oct 15, 2004
code:
if(message.equals(null))
{
  throw new Exception("The Message was NULL");
}
:downs: defensive programming

npe
Oct 15, 2004
Well while I'm at it, I should post this one that's in literally every method I can see:

code:
catch (Exception e)
{
  throw new Exception(e);
}
Somewhere in here is the business logic I need to preserve before I torch this entire project, if I can only avoid blinding myself from the insanity for long enough to find it...

npe
Oct 15, 2004

Dessert Rose posted:

If it's an extension method then it won't throw on null - you can call extension methods on null. This is probably the horror.

You guys are way overthinking this. It's java, it's broken, and this paradigm is everywhere you look in this codebase (complete with matching catch (Exception e) { throw new Exception(e); } every time).

npe
Oct 15, 2004

Carthag posted:

You can do the same thing in perl if you don't use strict;, and it's a really bad idea that makes code unmaintainable.

code:
[ [email]carthag@mbp.loca[/email]l:~ ]$ perl
use Data::Dumper;

$a = { a => b, "b" => 2, 3 => "c" };

print Dumper \$a;
^D
$VAR1 = \{
            'a' => 'b',
            '3' => 'c',
            'b' => 2
          };

With use strict your code fails due to the "b" in your values, but that's hardly fair because the discussion was barewords in keys, and this indeed works just fine with strict:

code:
use strict;
use Data::Dumper;

$a = { a => "b", "b" => 2, 3 => "c" };

print Dumper \$a;
In fact, this paradigm is pretty idiomatic perl when used as object properties, in the form of $self->{foo}.

npe
Oct 15, 2004
Found this ticket lurking in an old pile of tickets opened by an ex-employee (that she had created and then assigned to herself). They are all great, but this one may be the best.

quote:

Ticket #7111 (new Enhancement (Functional))
Opened 9 months ago

Use Hexdecimal To Store Global Integer Constants

Description

This will utlizes java's GC better and faster. Additionally this will use a little less memory.

npe
Oct 15, 2004
It's also why no normal human being would ever call the character set on a column a "constraint". A constraint in database terms implies a requirement that is actually enforced. If you take a stream of multibyte utf8 data and jam it into an ISO-8859-1 column, you end up with one of two things: if the client tried to convert from utf8 to the target character set, you will get dropped characters (the infamous "question marks in my data"). If the client jams the bytes in there as if they were the target encoding, then you get actual garbage from misrepresented bytes (as McGlockenshire describes).

It's really hard to imagine a scenario where you'd want anything other than UTF8. You get 8 bits per character for the ASCII range (code points < 128) and proper support for everything else. There is literally no argument for using 7 bit ASCII, and only really bad arguments for using any legacy 8 bit encoding (involving handwaving about 3rd party applications that can't be changed).

I can't fathom how you'd construe any of this as being a "constraint" by any sensible definition of that word.

npe
Oct 15, 2004
It's like anything, whether it's music, or movies, or literature. Agreeing on what is good is impossible. Agreeing on what is terrible is way easier.

npe
Oct 15, 2004
I can vouch for how at least how one major US bank works... transfers were done via what amounted to timed FTP jobs of text files which listed each transaction. These transfers frequently failed and had to be restarted, involving manual effort to rerun the transactions that hadn't processed yet. Naturally, this was a 24x7 department of people to monitor these jobs (which ran 5 times daily, as I remember) and repair them when they failed.

As you can imagine, double transactions or missed transactions were not uncommon...

Adbot
ADBOT LOVES YOU

npe
Oct 15, 2004

Zamujasa posted:

I might be misreading this, but it looks like an infinite recursion, since if you give it a value of "EXAMPLE" it will try to return the result of IsNullOrEmpty("EXAMPLE".Trim()) (essentially, the same function call), which will call itself again and so on and so forth.

The only case that looks like it would work properly is if value == null.


(I am not an expert in C# so this may be wrong)

No because I assume the class is named something like StringUtil, so it will resolve to the right call (String.IsNullOrEmpty() vs StringUtil.IsNullOrEmpty()).

That's a perfectly useful utility function for 3.5, and don't assume that everyone was able to port their 3.5 codebase to 4.0 the day it was released. At worst, it was written in 4.0 by someone who wasn't aware of the new addition of IsNullOrWhitespace().

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