|
After my well deserved vacation I returned to work.
Beeing happy I received a task to modify a DotNetNuke module, made by some externals from a country far far away.
Happyness didn't last long when I came along a SearchEngine class:
public const string SELECT = "SELECT";
public const string DISTINCT = "DISTINCT";
public const string FROM = "FROM";
public const string WHERE = "WHERE";
public const string HAVING = "HAVING";
public const string AND = "AND";
public const string OR = "OR";
public const string IN = "IN";
public const string ON = "ON";
public const string AS = "AS";
public const string GROUP_BY = "GROUP BY";
public const string ORDER_BY = "ORDER BY";
public const string DESC = "DESC";
public const string ASC = "ASC";
this continues for about 1500 lines of code declaring every possible table/column etc I could think of.
90% of the consts aren't even in use... and it all ends up in statements like that:
sqlString.AppendFormat("{0} {1} {2}.{3},{2}.{4},{2}.{5},{2}.{6},{2}.{7},{2}.{8},{2}.{9},{2}.{10},{2}.{11},{12} {13} {14} {15} {2} {16} {17} = @{17}",new string[]
{
SqlConsts.SELECT,
SqlConsts.DISTINCT,
SqlConsts.TBL1,
SqlConsts.OBJECT_NO,
SqlConsts.OBJECT_ID,
SqlConsts.COUNTRY,
SqlConsts.REGION,
SqlConsts.SUBREGION,
SqlConsts.TOURAREA,
SqlConsts.LATITUDE,
SqlConsts.LONGITUDE,
SqlConsts.CITY,
SqlConsts.COUNT_ANY,
SqlConsts.AS,
SqlConsts.UNIT_COUNT,
SqlConsts.FROM,
SqlConsts.WHERE,
SqlConsts.YEAR
});
...am I missing something or is this an acceptable way of solving database related tasks?
Can you spot a reason for this? If so, please make my happiness return... somehow... please...
Happy new year
Andy
|
|
|
|
|
Great Zarquon! Thermite the disk immediately before that corrupts something else. Not even I would do that*.
There is absolutely nothing good about that and all sorts of bad. The worst thing I can think of now (no coffee yet) is that you can't copy and paste it to SSMS (or similar) to test it. Just below that would be lack of syntax colouring if available.
You just ruined my day. Thanks for sharing.
* If I did, I'd use an enumeration.
|
|
|
|
|
I like the "thermiting" idea of you...
And this is just a small snippet of the project... it's like a "Coding Horror" blog that came to live...
As a grown up man I am not ashamed of my tears
|
|
|
|
|
Good heavens. Shoot the purp!
|
|
|
|
|
Oh my god.
What did I just read about "my eyes are bleeding"?
"some externals from a country far far away" ... indeed.
And to think they were all public constants
|
|
|
|
|
Were they getting paid by the line of code?!
This is what happens when you remove the "adult supervision" from a bunch of idiots writing code.
|
|
|
|
|
My best guess is misuse of intellisense.
Maybe the perpetrator (amongst other) is dyslexic and has invented his own spellchecker.
People say nothing is impossible, but I do nothing every day.
|
|
|
|
|
Yes, this is the first normal form of the so called "Bakers Binding". It's very robust and flexible,you know! provide excellent abstraction without too much complexity!
In the second normal form, you introduce a
public const string COLUMNSEPARATORFORSELECTSTATEMENT = ",";
To be fair, hunting down select statements when the db scheme changes is painful; you have to exercise every code paht that contains a select.
That solution is akin to smashing your toe to forget a flea bite, though.
|
|
|
|
|
...good one though
there actually exists such a seperator iuhasdfhu,gvsd.fgzdfjhb (sorry, I just had to smash my head into the keyboard... it reliefs the pain)
|
|
|
|
|
An attempt to create new, better LINQ to SQL?
|
|
|
|