Put Your Code Window In the Upright and LOCKED Position
-
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad: -
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:ROFL, MAN! This brings back nightmares of my old days migrating from MS Access to Oracle/SQL Server, some stuff programmed by secretaries and probably the janitorial staff it seemed like. Good luck! Glad it's not me...X|
if (!interested){return false;} amclint
-
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:Perhaps they're just not professional software developers. Of course, that works out nicely for you, since it creates a demand for your talents.
Author of The Career Programmer and Unite the Tribes www.PracticalStrategyConsulting.com
-
Perhaps they're just not professional software developers. Of course, that works out nicely for you, since it creates a demand for your talents.
Author of The Career Programmer and Unite the Tribes www.PracticalStrategyConsulting.com
ROTFLMAO When I saw the subject I thought it was about rotating your LCD Monitor 90 degrees. One of my colleagues does that. :laugh: Can you imagine how disappointed I was to get VBed? :(( [mod] Why does Bob keep misfiling my posts? :((
Last modified: 29mins after originally posted -- DAMN YOU BOB!
led mike
-
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:What is wrong with it? There ARE at least these three versions of what the user considers "empty" - and even when the data comes from some component, it takes wild guesses which of them is the "empty de jour". The names are silly, and IIRC VBA can do boolean assignments which would allow to reduce LOC (on the sake of readability for lesser skilled coworkers), but that's all not the end of good reason.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist -
What is wrong with it? There ARE at least these three versions of what the user considers "empty" - and even when the data comes from some component, it takes wild guesses which of them is the "empty de jour". The names are silly, and IIRC VBA can do boolean assignments which would allow to reduce LOC (on the sake of readability for lesser skilled coworkers), but that's all not the end of good reason.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighistpeterchen wrote:
What is wrong with it?
You want the long answer or short? I don't know much VBA, but I know classic VB pretty darn well and this is code I'd also scoff at for several reasons. So, with that being said; short or long? :-D
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
-
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:nullGumby wrote:
I mean wtf.
I so know how you feel. :laugh: VBers seem to really be bad at this crap. Yeah, bad code is everywhere, but I see it a LOT with VB. I mean really, it's like they barely learn how to program and consider themselves uber 1337 because they can make an ActiveX DLL (and mistakenly think it's a regular DLL to boot) to impress grandma who doesn't even know how to check email.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
-
peterchen wrote:
What is wrong with it?
You want the long answer or short? I don't know much VBA, but I know classic VB pretty darn well and this is code I'd also scoff at for several reasons. So, with that being said; short or long? :-D
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
long :) (I do have some VBA memories scars, so I might not be objective...)
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist -
long :) (I do have some VBA memories scars, so I might not be objective...)
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighistpeterchen wrote:
long
That's what I was hoping for. :) I'll repost the code here just for reference's sake:
Public Function IsThere(what As Variant) As Boolean
IsThere = Not NotThere(what)
End FunctionPublic Function NotThere(what As Variant) As Boolean
If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then
NotThere = True
Else
NotThere = False
End If
End FunctionI'll disregard naming conventions on this one.
- IsThere and NotThere do the exact same thing, both of which return True or False if a passed variable is what they consider empty or not. This is ambiguous.
- This ain’t C/C++, classic VB doesn’t short circuit, so if you don’t want all three of those checks to fire off every time regardless of the value passed, then don’t use it (personally I always make speed a consideration, and considering the goal of these routines I imagine they would be called often).
- Don't compare against "" in VB unless you enjoy wasting 8 bytes of memory and an allocation time, compare against vbNullString instead.
- Only use Trim$ when evaluating to a string for comparison rather than Trim, this saves time because VB won’t have to figure what to do with it.
- Lastly, the use of these functions can most likely indicate the misuse of Variants. VB already provides simple checks for most data types, but as you can see the Variants take a bit more because of all the conditions they can meet. While this is no guarantee, it is indicative of what I've typically seen as Variant abuse and you loose what little type safety VB already has when doing it.
I think my biggest peeve with all of the VB hoopla is people want to call themselves professionals and don’t know the simple things about the environment they claim to be pros in. If the guy that wrote this was a new guy, so be it. But, I’d kindly let them know how/where things can be improved upon.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
-
peterchen wrote:
long
That's what I was hoping for. :) I'll repost the code here just for reference's sake:
Public Function IsThere(what As Variant) As Boolean
IsThere = Not NotThere(what)
End FunctionPublic Function NotThere(what As Variant) As Boolean
If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then
NotThere = True
Else
NotThere = False
End If
End FunctionI'll disregard naming conventions on this one.
- IsThere and NotThere do the exact same thing, both of which return True or False if a passed variable is what they consider empty or not. This is ambiguous.
- This ain’t C/C++, classic VB doesn’t short circuit, so if you don’t want all three of those checks to fire off every time regardless of the value passed, then don’t use it (personally I always make speed a consideration, and considering the goal of these routines I imagine they would be called often).
- Don't compare against "" in VB unless you enjoy wasting 8 bytes of memory and an allocation time, compare against vbNullString instead.
- Only use Trim$ when evaluating to a string for comparison rather than Trim, this saves time because VB won’t have to figure what to do with it.
- Lastly, the use of these functions can most likely indicate the misuse of Variants. VB already provides simple checks for most data types, but as you can see the Variants take a bit more because of all the conditions they can meet. While this is no guarantee, it is indicative of what I've typically seen as Variant abuse and you loose what little type safety VB already has when doing it.
I think my biggest peeve with all of the VB hoopla is people want to call themselves professionals and don’t know the simple things about the environment they claim to be pros in. If the guy that wrote this was a new guy, so be it. But, I’d kindly let them know how/where things can be improved upon.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
(1) Kids program that way. Jumping though hoops to save three letters. I don't really care. Maybe they grow up, maybe they don't. For the time being, I rather have IsThere/NotThere, than a single IsTh. (2) 100% Undebated Point! I completely missed that one. (3) This might be different in VBA. (4) VBA doesn't have a trim$ (IIRC) (5) Well... No type safety in VBA. You get the oddest variants from the weirdest places. They have default value coercion - so that empty string might actually be an object that suddenly is no more after you said rowset.MoveNext. Anytime I do VBA, I'm tracking the VARTYPEs in my head I think the biggest difference is: You can write a serious application in VB - it's painful, but not impossible with some discipline - exactly what you miss in above code. When you do VBA you are either a "maybe" programmer, struggling with all that fancy programming - for such a guy it's good code (trust me). Or you are a well-rounded programmer stuck with a shit job you want to get over with. While I normally subscribe to "No matter how bad you are on a job, do it as good as you possibly can!" there are some exceptions. VBA is one of them: You don't want to become the VBA expert.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist -
(1) Kids program that way. Jumping though hoops to save three letters. I don't really care. Maybe they grow up, maybe they don't. For the time being, I rather have IsThere/NotThere, than a single IsTh. (2) 100% Undebated Point! I completely missed that one. (3) This might be different in VBA. (4) VBA doesn't have a trim$ (IIRC) (5) Well... No type safety in VBA. You get the oddest variants from the weirdest places. They have default value coercion - so that empty string might actually be an object that suddenly is no more after you said rowset.MoveNext. Anytime I do VBA, I'm tracking the VARTYPEs in my head I think the biggest difference is: You can write a serious application in VB - it's painful, but not impossible with some discipline - exactly what you miss in above code. When you do VBA you are either a "maybe" programmer, struggling with all that fancy programming - for such a guy it's good code (trust me). Or you are a well-rounded programmer stuck with a shit job you want to get over with. While I normally subscribe to "No matter how bad you are on a job, do it as good as you possibly can!" there are some exceptions. VBA is one of them: You don't want to become the VBA expert.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighistWell, I don't use VBA and it's on purpose. :laugh: So, I'd have to look up some of these things for VBA, but I really can't imagine how it would be that much different seeing the engine is the same practically. Anyway, I can't agree with your first (counter)point because I believe code should not be ambiguous and always have a single point of execution. Yeah, this is a simple example of it, but not keeping those two things in check make learning a new system that's complex a real PITA later on (or even if you haven't touched the project in years and forgot most of it). If I have two routines serving the same exact purpose, one of them would get wiped, no matter if I had to type three more characters or not IMO.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
-
Well, I don't use VBA and it's on purpose. :laugh: So, I'd have to look up some of these things for VBA, but I really can't imagine how it would be that much different seeing the engine is the same practically. Anyway, I can't agree with your first (counter)point because I believe code should not be ambiguous and always have a single point of execution. Yeah, this is a simple example of it, but not keeping those two things in check make learning a new system that's complex a real PITA later on (or even if you haven't touched the project in years and forgot most of it). If I have two routines serving the same exact purpose, one of them would get wiped, no matter if I had to type three more characters or not IMO.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
Jeremy Falcon wrote:
the engine is the same practically
I'm not sure about that. After all, there are three VB dialects (VBScript, VBA, VB) out there, with ever so subtle differences that I would hazard a guess they are sparate implementations. I've worked a lot with coders on different skill levels, and I learnt to concentrate on the "big" issues. Like Copy & Paste Prgramming, SQL injection, trusting user input, missing borderline cases, etc.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist -
Jeremy Falcon wrote:
the engine is the same practically
I'm not sure about that. After all, there are three VB dialects (VBScript, VBA, VB) out there, with ever so subtle differences that I would hazard a guess they are sparate implementations. I've worked a lot with coders on different skill levels, and I learnt to concentrate on the "big" issues. Like Copy & Paste Prgramming, SQL injection, trusting user input, missing borderline cases, etc.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighistpeterchen wrote:
I'm not sure about that.
You could be right. And, I'd look it up, but I'm heeding your word and making sure I don't become a VBA expert. :->
peterchen wrote:
I've worked a lot with coders on different skill levels, and I learnt to concentrate on the "big" issues. Like Copy & Paste Prgramming, SQL injection, trusting user input, missing borderline cases, etc.
I tend to focus on both. A bunch of little issues left unchecked can lead up to big issues that can't be solved because nobody knows what's going on.
Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]
-
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:My only question is: Why are you StillThere? ;P Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith -
Every once in awhile someone will ask me to add something to their Access database they've been pouring macro code into for years... So then I have to debug through stuff like this:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function Public Function NotThere(what As Variant) As Boolean If IsNull(what) Or Trim(what) = "" Or IsEmpty(what) Then NotThere = True Else NotThere = False End If End Function
I mean wtf. :mad:nullGumby wrote:
Public Function IsThere(what As Variant) As Boolean IsThere = Not NotThere(what) End Function
Wow! The smartest implementation! :laugh:
Luis Alonso Ramos Intelectix Chihuahua, Mexico
Not much here: My CP Blog!