3

I'm took over an old classic ASP project and as part of migrating the database from Access to SQL I need to handle a few datetime cases at various points within the app. The thought is to include a little library file with my own set of functions to handle these.

There's no "include once" directive and the site has enough funky nested imports where I can't be sure of it not being included more than once if I just put it on each page that I need it.

So, what happens if a function gets declared twice in an ASP/VBScript page? They'd be identical... ex:

Function HandleDate(fld)
  xyz
End Function

In a test with a duplicated function within a page, there appears to be no issues, but I'm wondering if there's something I should be aware of, as this certainly doesn't "feel" right.

jleach
  • 7,410
  • 3
  • 33
  • 60
  • That's bad practice, even if only for making it harder to debug: you can't really know which of the functions is actually being called. I would strongly recommend adding Option Explicit and fix all the multiple declared names. – Shadow The GPT Wizard Apr 09 '16 at 19:48
  • @ShadowWizard - it's a legacy app I just took over - I can't just throw an option explicit in everything and fix all the issues... it works as it has for the past 15yr (best practice or not). That'd be a far more trouble than it's worth (might as well rewrite the whole thing at that point). My question was whether including identical functions twice would be problematic. – jleach Apr 09 '16 at 21:13
  • Fair enough, then the answer is right on spot. Cheers! – Shadow The GPT Wizard Apr 10 '16 at 06:43

2 Answers2

1

According to the docs, it doesn't look like it matters too much. The main concern is making sure you don't cause a loop by file A including file B, and then file B including file A (which it doesn't really sound like you are doing). Read more here...

Including Files: Tips and Cautions

Steve Holland
  • 619
  • 1
  • 12
  • 29
  • Thanks, it's at least an official page (closer than I'd found), but still doesn't define the behavior I was curious about. In any case, any duplicates would be identical procedure bodies, and it seems to be working without issue, so I'll go with it. – jleach Apr 09 '16 at 21:14
0

I have a legacy classic ASP site and the previous coder had doubled up on functions quite often (perhaps he forgot they were already there), so two versions existed with each page load. This has never created any errors for me and I've been running these for years now.

Ralpharama
  • 441
  • 4
  • 20