|
I've just come across the following query in an Access ( ) application. It's supposed to run against a SQL database, but is littered with it's own views against the real database. The Name field stores a name as '[surname]; [firstname]', which makes queries unwieldy enough, but I just love how the guess the person's initials:
Left([Name],IIf(InStr([name],';')=0,Len([Name]),InStr([name],';')-1)) AS Surname,
Right([Name],Len([Name])-InStr([name],';')) AS Firstname,
Left([Name],2) AS Initials,
Now a related table stores a name as '[surname] [firstname]', and the drop-down for filtering that table has surname and first name as two separate columns. Names have no key values, and just 'exist'. The UI looks like it was designed by a three-year old on acid, and it's anybodies guess which button is going to work and which isn't.
Here are example 1[^] and example 2[^] of the Access UI.
Last modified: 51hrs 13mins after originally posted --
|
|
|
|
|
LOL, SABS = SA Bureau of Standards???
|
|
|
|
|
Yes!
|
|
|
|
|
I can't resist. "Standards are slipping!"
|
|
|
|
|
Brad (can I call you Brad?), forget about the code. That is not an UI, it is 'test bed button box from hell' gone mad. With cream.
My advice is to use the force. If you can't use the force, use a sledgehammer.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
My brief is to add the Access functionality to their intranet app. Mine looks prettier, but I've had to forego data integrity checks etc. just to get it to work. I have another brief to actually revise the whole web app, where I have the opportunity to introduce some modicum of sense.
|
|
|
|
|
Not much of a horror, but it still made me chuckle...
int x = 1 + y - 1;
Dybs
|
|
|
|
|
...if you replace the "magic numbers" with variables, this will make sense to do this way...in a readability sort of way.
|
|
|
|
|
Well. Not if it's the SAME variable!
int x = z + y - z;
|
|
|
|
|
What if z is volatile?
This would mean that the value of z could change between the add and the subtraction.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
What if z is volatile?
If Z is volatile, then the code would go from being an idiosyncrasy to a horror, since the two reads would not be equivalent but there would be no sequence point to guarantee which would happen first.
In some cases, it's fine to read a volatile variable twice without an intervening sequence point (e.g. using something like while (*mem != *mem); to determine whether a flash chip is busy). If the order in which the reads take place won't matter, then it won't matter if the compiler rearranges them. On the other hand, in an expression like foo = vol + something - vol, the effect on foo if vol changes will be indeterminate. Far better would be something like foo = vol + something; foo -= vol;. Under that scenario, the semantics if vol changes would be clear.
|
|
|
|
|
In this case, it was for setting the position for modifying a string, so it could certain make sense for clarifying exactly where the update is inserted/replaced. But still, the "magic numbers" were there, not variables.
|
|
|
|
|
This may be a code signature
|
|
|
|
|
SELECT @ValueList = ''''+REPLACE(ISNULL(CAST([Amount] as varchar(8000)),'Null'),'''','''''') + ''',''' + REPLACE(ISNULL(CAST([ActualCost] as varchar(8000)),'Null'),'''','''''') + ''',''' + REPLACE(ISNULL(CAST([Notes] as varchar(8000)),'Null'),'''','''''') + ''',''' + REPLACE(ISNULL(CAST([Qty1] as varchar(8000)),'Null'),'''','''''') + ''' FROM Documents
I'm supposed to edit this, then place it in an update statement - it's the contents of a table field, not a literal query! I would rather write a quote doubler/divider than take my chances, but I was crafty and pasted my edit back into the field in Management Studio, now I just script the data of the table using the Publishing Wizard.
|
|
|
|
|
Why kind of monster can write such SQL?
|
|
|
|
|
It gets worse. When I escape the quotes to script an update of that field, I get the SQL below. The reason for all the casts is historical, and the reason for all the quotes is that the SQL gets passed through several layers of stored proc before actually being executed.
UPDATE [csForm] SET [CopyCommand] = N'SELECT @ValueList = ''''''''+REPLACE(ISNULL(CAST([Amount] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''','''''' + REPLACE(ISNULL(CAST([DocTitle] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''' FROM Documents WHERE DocID =|SELECT ''''''&IDENTITY&'''','''''' + REPLACE(ISNULL(CAST([WorkType] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''','''''' + REPLACE(ISNULL(CAST([WorkTypeID] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''','''''' + REPLACE(ISNULL(CAST([Amount] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''','''''' + REPLACE(ISNULL(CAST([Notes] as varchar(8000)),''Null''),'''''''','''''''''''') + '''''','''''' + REPLACE(ISNULL(CAST([LineType] as varchar(8000)),''Null''),'''''''','''''''''''')+'''''''' AS ValueList FROM DocItems WHERE DocID =|'
|
|
|
|
|
Brady Kelly wrote: The reason for all the casts is historical ...
Don't you mean hysterical
|
|
|
|
|
this is why they created linq !
|
|
|
|
|
You have my utmost condolences...
|
|
|
|
|
Hi, I saw this some time ago:
for(int i = 0; i < 2; i++)
{
if(i==0)
if(i==1)
}
this is pretty much a horror
|
|
|
|
|
Your are correct, he/she should have used a switch instead of the if statements. Like this:
for(int i= 0; i < 2; i++)
{
switch(i)
{
case 0:
break;
case 1:
break;
};
}
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
I guess there is no need for a loop at all.
Nothing is being repeated here.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: Nothing is being repeated here.
We don't know that.
|
|
|
|
|
I believe the point was that without the loop and the if's the (equivalent) code becomes
// do something
// do something else
which of course is simply normal program flow! So the whole looping business seems a bit convoluted.
|
|
|
|
|
Probably, but do //Do something and //Do something else alter the value of i ?
|
|
|
|
|