|
Ed Bouras wrote: zen-like Yes: [Email] will always be an empty string, not null (except when ISNULL evaluates NULL as something different from NULL). String.Empty and NULL is an enormous difference for MS SQLServer and most (or all?) object-oriented programming languages. But not for zen-lacking Oracle.
|
|
|
|
|
Bernhard Hiller wrote: String.Empty and NULL is an enormous difference
Yes, obviously.
And I wish XML would recognize that too.
This space intentionally left blank.
|
|
|
|
|
|
Hence the post in this forum.
Honestly this was probably done in haste and without care for proper coding as part of a set of replacements in the stored proc of the "Email" field with NULL. Things do happen fast and furious around here and there is no dba to oversee/filter.
I found it humorous enough to share with those who like to smack themselves in the forehead 
|
|
|
|
|
This probably came up for .. historic reason!
|
|
|
|
|
|
|
After long though i decided to share this wonderful gem in c#
Today cannot get "better".
public enumType GetValueByInfo(string name, string id)
{
enumType result = enumDictionary[id];
return result;
}
And the enumDictionary is just declared Dictionary<string, enumtype=""> with (string, enumType) pairs
The names are changed.
This beautiful thing is written in c# from someone else than me, a colleague who worked longer than me in the firm. He is working mainly with c# projects i am working mainly with vc++ and MFC(oh the joy) When i have to change something my boss always says to me to write it in the same manner like the things are done in the project.
The worst part is this gem is written in my dll (the dll i should be working but all other are adding things but me)
I hate when someone else is touching my code.
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
haha awesome!
I would be interested to see, in the places where this is being called, the variety of values being supplied for name.
Well fads they come and fads they go.
And God I love that rock and roll!
Well the point was fast but it was too blunt to miss.
Life handed us a paycheck, we said, "We worked harder than this!"
|
|
|
|
|
I would like to see this working with a string which is not set as key in the dictionary.
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
Just supplying the correct name and an empty id string should do the trick.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Time to institute code reviews.
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: Time to institute code reviews hire good programmers.
FTFY 
|
|
|
|
|
/ravi
|
|
|
|
|
In one function, the following is used to call SomeFunc (names changed to protect the guilty):
If UCase(SomeFunc("" & int_var, bool_var)) = "YES" Then
F.chkBox.Value = 1
Else
F.chkBox.Value = 0
End If
(with two more calls to the same function further down).
Where F is a form variable (because frm would be too hard to type)
Looking at the definition...
Private Function SomeFunc(Result As Long, Optional cond As Boolean) As String
If cond = True Then
Select Case (Result)
Case Is < 3
SomeFunc = "No"
Case Is > 2
SomeFunc = "Yes"
End Select
Else
Select Case (Result)
Case 1
SomeFunc = "No"
Case Is >= 2
SomeFunc = "Yes"
End Select
End If
End Function
Why use a Boolean when a string comparison, case conversion and check for null string will do?
Why is that Boolean argument optional, when it is always supplied?
(before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages.
The real real WTF is that people who produce such garbage are still employed.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Rob Grainger wrote: (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages.
But VB seems to bring out the best in bad programming.
|
|
|
|
|
You need to try "View Source" on a few web pages then
I think it applies generally to many "high-level"/scripting languages, unless (like Dart, Smalltalk) they were well-designed in the first place.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
As I always say, it ain't the tool that is used, it's the tool that uses it that's the problem.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Spot on!
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
You missed one: it converts int_var (which is presumably a Long ) to a String , and then relies on VB's implicit conversion to convert it back to a Long .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well spotted - I left that one deliberately to ensure folk are paying attention
Actually, most of the real horrors in this particular code base are more subtle and hard to illustrate in short snippets and more to do with putting too much business logic in event handlers for controls. When a form loads, info from the database is written to a control, which fires an event handler, which writes to another control, which fires an event handler, which... I think you get the picture. Business logic is totally interspersed with UI logic - often broken out into separate modules the contents of which have no logical relation. Global variables are used for all sorts of purposes. "Option Strict" has not been used, and frequently variables are not declared anywhere at all... GoTo's and even GoSub's are used liberally.
I'm just glad I'm tasked with rewriting it rather than maintaining it, but it can be software archaeology trying to determine what the heck the original logic was intended to accomplish.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Rob Grainger wrote: "Option Strict" has not been used
I didn't think VB6 had Option Strict ? From my hazy memory, it only had Option Explicit , Option Compare and Option Base .
MSDN also lists Option Private [^], but I don't think I ever saw that used.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
What happens, if you pass cond as False and Result as 0 (or anything < 1)? Does the function return a Null value and cause an Exception in the If?
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
It should return null, but no exception. it will just be evaluated as false, because null != "YES"
|
|
|
|