Sure ? SURE ?!
-
<FONT size=2>I am looking at some code a older employee at my company made (vb.net) :
IsRegistered = IIf(value <> 0, </FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>)</FONT>
<FONT style="BACKGROUND-COLOR: #000000" size=2></FONT><FONT color=#0000ff size=2><FONT color=#000000>And just why was that nesecary ?</FONT></FONT>
<FONT size=2></FONT>
<FONT size=2>Now this is just fucking ugly :</FONT>
<FONT size=2></FONT>
<FONT size=2></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> pPara(25) </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> SqlParameter
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> cSource() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = {"nv", "dt", "nv", _
"nv", "nv", "nv", _
"nv", "nv", "nv", _
"nv", "nv", "nv", _
"nv", "nv", "nv", _
"nt", "nv", "nv", _
"nv", "nv", "nv", _
"nv", "nv", "nv", "nv"}
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> iSource() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Integer</FONT><FONT size=2> = {20, 0, 40, 60, 60, _
40, 20, 255, 60, 60, _
60, 20, 40, 40, 40, _
0, 40, 60, 60, 60, _
60, 60, 60, 60, 255}
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> aSource() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = {"OrderNo", "OrderDate", "OptionalText1", _
"OrderText", "Name", "City", _
"Customer", "Email", "Address1", _
"Address2", "Address3", "RecvNo", _
"OptionalText2", "OptionalText3", "OptionalText4", _
"Remarks", "OptionalText5", "Ship1", _
"Ship2", "Ship3", "Ship4", _
"Ship5", "Ship6", "Ship7", _
"ShipEmail"}
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> bSource() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = {"@OrderNo", "@OrderDate", "@OptionalText1", _
"@OrderText", "@Name", "@City", _
"@Customer", "@Email", "@Address1", _
"@Address2", "@Address3", "@RecvNo", _
"@OptionalText2", "@OptionalText3", "@OptionalText4", _
"@Remarks", "@OptionalText5", "@Ship1", _
"@Ship2", "@Ship3", "@Ship4", _
"@Ship5", "@Ship6", "@Ship7", _
"@ShipEmail"}
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> bOk() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Boolean</FONT><FONT size=2> = {</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>False</FONT><FONT size=2>}
</FONT><FONT color=#0000ff><FONT color=#000000></FONT></FONT>
-
And the last part is used for filling sql-parameters, using this fantastic method:
</FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Function</FONT><FONT size=2> FillParameter(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> p </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> SqlParameter, _
</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> pn </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> pt </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>, _
</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> ps </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Integer</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> pv </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>) _
</FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> SqlParameter
</FONT><FONT color=#0000ff size=2>Try
</FONT><FONT size=2></FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> p
.ParameterName = pn
</FONT><FONT color=#0000ff size=2>Select</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> pt
</FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> "nv"
.SqlDbType = SqlDbType.NVarChar
</FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> ps > 0 </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> .Size = ps
</FONT><FONT color=#008000 size=2>'pv.GetType(System.String)
</FONT><FONT size=2></FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> Len(</FONT><FONT color=#0000ff size=2>CType</FONT><FONT size=2>(pv, </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>)) > 20 </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> pv = Mid(</FONT><FONT color=#0000ff size=2>CType</FONT><FONT size=2>(pv, </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>), 1, 20)
</FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> "nt"
.SqlDbType = SqlDbType.NText
</FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> "dt"
.SqlDbType = SqlDbType.DateTime
</FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> "fl"
.SqlDbType = SqlDbType.Float
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select
</FONT><FONT size=2>.Value = pv
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>With
</FONT><FONT size=2>FyldParameter = p
</FONT><FONT color=#0000ff size=2>Catch</FONT><FONT size=2> ex </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Exception
MessageBox.Show(ex.Message)
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Try
</FONT><FONT size=2></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Function
</FONT>
-
Oh that is just nasty.
Apparently this guy never heard of a constructor before.
-
He should :-)
He has been coding for big companies several times i've heard (oracle maybe? :D)
I was to modify that application (actually quite small... ) for a other client, and belive me, its was impossible..
No libraries, just applications.. no classes, just forms.. no objects, datasets work fiiine.
He doesnt use app.config, or ini's.. noooo no, all hardcoded... .Or,
hardcoded is too strong a word! the first client had several computers
it had to be installed on, and of course the settings wasnt allways the
same! No problemo.. He just edited the source, and build it for that
specific computer.. I cant imagine the nightmares im gonna get!
Luckily, i convinced my boss, we could at well throw it all out.. I
belive he used over 100 hours, on a small project transfering data from
one database (Onlineshop) to a other (ERP)..
-
A year ago I inherited a web project that had over 300 code files, All their classes inherited from the same base:
Public Class TNSPage
Public MustInherit Sub ProcessIt()
End Class
Then all the subclasses had stuff like this:
Public Class Foo
Inherits TNSPage
Public Var1 As String
Public Var2 As Integer
Public Overrides Sub ProcessIt()
' Starts Everything Running <- Their comment, not mine.
End Sub
End Class
No property procedures, just public fields, and everything has a ProcessIt method that's MILES long, making hundreds of thousands of hits to the database. And it all went something like this: (no stored procedures here. Just bare SQL thrown at the server)
Get a SqlDataReader on several hundred thousand records, then loop over them, loading them into a HashTable, then loop over the hashtable loading them into an empty datatable (Which they acquired by re-running the same select statement with WHERE 0 = 1) and then loop over the data table doing minor manipulations, and then loop over the data table AGAIN doing an ExecuteNonQuery() on each record.
When I got done with that one, it was 4 SqlParameters and a stored procedure call.
Sheesh.