To my dearly departed colleague
-
He left on Friday, I got stuck with making some updates to an existing system...here are a few code samples I came across today...
1. He was a bit of a whizz with SQL...and no, there is no valid reason for this crap...
private static String SELECT_TAG_MEASURE_STATEMENT =
"select measure_id, name "
+ "from measure "
+ "where measure_id in "
+ "(select measure_id from tag_measure where tag_action_id in "
+ "(select tag_action_id from tag_action where action_id = ?)) "
+ "order by name";
2. ???????
Calendar todaysDate = Calendar.getInstance();
Date trialTime = new Date();
todaysDate.setTime(trialTime);
3. Is anyone else familiar with 'leftONLOAD'? My IDE and my (other) colleagues aren't - and yes, I am aware of the crap link color handling even though every jsp also has css included...
<BODY ALINK="#993333" BGCOLOR="#DFD1AD" topmargin=0 leftmargin=0 rightmargin=0 onload="initialiseForm(insertMenu, '<%=subcommand%>')" leftONLOAD="MM_showHideLayers('parent.frames[\'left\'].document.layers[\'Layer1\'][0]','parent.frames[\'left\'].document.all[\'Layer1\'][0]','hide')" LINK="000000" VLINK="#8F7134" ALINK="#333333">
4. Some sample logging (from production system supplied to client)System.out.println("Srini 1");
do something (1 thing only, mind you...)
System.out.println("Srini 2");
System.out.println("Srini 3");
System.out.println("Srini 4");
System.out.println("Srini 5");etc...
-
@wiggzie said:
This is typical for ad-hoc statements (making an already written query a subquery is easier than turning it into a join), but shouldn't make it into production code.He left on Friday, I got stuck with making some updates to an existing system...here are a few code samples I came across today...
1. He was a bit of a whizz with SQL...and no, there is no valid reason for this crap...
2. ???????
Calendar todaysDate = Calendar.getInstance();
Date trialTime = new Date();
todaysDate.setTime(trialTime);
4. Some sample logging (from production system supplied to client)System.out.println("Srini 1");
do something (1 thing only, mind you...)
System.out.println("Srini 2");
System.out.println("Srini 3");
System.out.println("Srini 4");
System.out.println("Srini 5");etc...
That's what people did in C, when a program crash wasn't that easy to pinpoint in the code. Obviously useless in Java. Obviously not usefull in production code, though that stuff is often forgotten.
-
This is typical for ad-hoc statements (making an already written query a subquery is easier than turning it into a join), but shouldn't make it into production code.
There are 152 occurances of selects within selects...
That's what people did in C, when a program crash wasn't that easy to pinpoint in the code. Obviously useless in Java. Obviously not usefull in production code, though that stuff is often forgotten.that's why we use log 4 j...
-
@wiggzie said:
that's why we use log 4 j...
Even without that, such dense trace statements are useless in Java. In C, it was usefull because the program run might look like that:$ ./foobar
segmentation fault
$
With such trace statements, it turns into that:
$ ./foobar
Erich 1
Erich 2
Erich 3
segmentation fault
$So whatever code is between "Erich 3" and "Erich 4", it's the point where the program crashes. In Java, you'll always get a stack trace, no need for such tricks.
-
@ammoQ said:
4. Some sample logging (from production system supplied to client)System.out.println("Srini 1");
do something (1 thing only, mind you...)
System.out.println("Srini 2");
System.out.println("Srini 3");
System.out.println("Srini 4");
System.out.println("Srini 5");etc...
That's what people did in C, when a program crash wasn't that easy to pinpoint in the code. Obviously useless in Java. Obviously not usefull in production code, though that stuff is often forgotten.
This is necessary in C only when you have an environment that lacks a proper debugger. I had to do this several times in a playstation game, but at least I didn't commit it after the problem was found.
It could be useful in java aswell, mind you, if you're in a situation where you can't run the code in a debugger and the crash isn't an exception but an infinite loop or a deadlock.
-
@ammoQ said:
This is typical for ad-hoc statements (making an already written query a subquery is easier than turning it into a join), but shouldn't make it into production code.
Do you think it would make a difference? I recon the optimiser would resolve them the same anyway.
I must confess to doing some weird stuff like this. I had to create some SQL to achieve something behind an interface, so I had something like 3 parameters that would magically get assigned to a ? in a particular order. Unfortunately the SQL got a bit gnarly because I couldn't easily get the sequence right and ended up doing some quite unnecessary stuff just to get around it.
-
leftONLOAD
Possibly a ditzy way of disabling thus "commenting" an event.
-
@LoztInSpace said:
Do you think it would make a difference? I recon the optimiser would resolve them the same anyway.
Maybe, maybe not. Nesting subqueries means nested loops in a certain layout, dictated by the query.
If it was a join instead, the optimizer might, based on the statistics, choose another strategy, e.g. full table scans, followed by a hash join.
Or nested loops with the other table doing the outer loop.
-
Another gem:
<FONT color=#000080 size=2>for</FONT><FONT size=2>(</FONT><FONT color=#000080 size=2>int </FONT><FONT size=2>i=0;i < 4;i++) {
</FONT><FONT color=#000080 size=2>switch</FONT><FONT size=2>(i) {
</FONT><FONT color=#000080 size=2>case </FONT><FONT size=2>0 : </FONT><FONT color=#000080 size=2>if</FONT><FONT size=2>(search_start_month == </FONT><FONT color=#000080 size=2>null</FONT><FONT size=2>) {
search_start_month = </FONT><FONT color=#008000 size=2>""</FONT><FONT size=2>;
}
</FONT><FONT color=#000080 size=2>break</FONT><FONT size=2>;
</FONT><FONT color=#000080 size=2>case </FONT><FONT size=2>1 : </FONT><FONT color=#000080 size=2>if</FONT><FONT size=2>(search_start_year == </FONT><FONT color=#000080 size=2>null</FONT><FONT size=2>) {
search_start_year = </FONT><FONT color=#008000 size=2>""</FONT><FONT size=2>;
}
</FONT><FONT color=#000080 size=2>break</FONT><FONT size=2>;
</FONT><FONT color=#000080 size=2>case </FONT><FONT size=2>2 : </FONT><FONT color=#000080 size=2>if</FONT><FONT size=2>(search_end_month == </FONT><FONT color=#000080 size=2>null</FONT><FONT size=2>) {
search_end_month = </FONT><FONT color=#008000 size=2>""</FONT><FONT size=2>;
}
</FONT><FONT color=#000080 size=2>break</FONT><FONT size=2>;
</FONT><FONT color=#000080 size=2>case </FONT><FONT size=2>3 : </FONT><FONT color=#000080 size=2>if</FONT><FONT size=2>(search_end_year == </FONT><FONT color=#000080 size=2>null</FONT><FONT size=2>) {
search_end_year = </FONT><FONT color=#008000 size=2>""</FONT><FONT size=2>;
}
</FONT><FONT color=#000080 size=2>break</FONT><FONT size=2>;
}
}
</FONT>
-
@wiggzie said:
Another gem:
<font color="#000080" size="2">
</font><font color="#000080" size="2">for</font><font size="2">(</font><font color="#000080" size="2">int </font><font size="2">i=0;i < 4;i++) {</font>
<font color="#000080" size="2">
</font><font color="#000080" size="2">switch</font><font size="2">(i) {</font>
<font size="2">...
<font color="#000080" size="2"></font>
</font>
Ah, the classical for-switch-construct. The sure mind of an insane mind.
-
The sure sign of an insane mind.
-
The sure mind of an insane sign?
-
@wiggzie said:
He was a bit of a whizz with SQL...
Your colleague was a squirt of urine? Interesting. :)