Steven said:
Its great that you can point out the flaws in other people's answers
without actually providing one yourself.
I don't think there was anything else particularly to answer on this thread,
the original question had been addressed.
But the example provided was one that I considered "dangerous" (on a very
minor scale). I've spent a heck of a lot of time over the last two years
working out the best ways of writing code that needs to run in various
different environments (WinForms, IIS) and if I'd known which techniques to
use and to avoid at the beginning then I'd have found the whole experience
much more straightforward.
My only intention when pointing out the flaw in Cor's example procedure was
to help the OP to try to avoid a way of writing code that could cause him a
lot of difficult-to-recreate problems down the line, resulting in a
potentially large amount of wasted time tracking them down. Would you be
happy including the module that was provided into your project? As a class
it would have been fine, but as a module it is not.
I've provided my fair share of answers to this newsgroup by the way, not to
anything like the extent of others such as Herfried and Cor or course, but
I'm hardly just sitting here criticising.
I am not quite sure why you thought the shared method wouldn't work.
There is no state involved.
I have no problem with a shared method. I use lots of shared methods. I have
a problem with a module that has a module-level variable. In that case,
state most definitely was involved. As I said in my previous post, any call
to another function that also tried to use the module to store its own name,
or use of this in a multi-threaded environment such as IIS, would both cause
problems that would be unexpected and hard to track down.
In fact, this example has no dependancies
at all and is perfect even for a unit test.
Public shared function FormatLocation(byval City as string, byval
State as string, byval ZipCode as string) as String
Dim location as string = City.Trim() & ", " & State.ToUpper().Trim()
& " " & ZipCode
Return location
end function
That looks absolutely fine to me, but that's not the code that I was
responding to. I have no problem at all with your example above which is, as
you say, stateless.
I think it would be better if you provided input where it was useful,
as opposed to just writing randomly. The OP would actually get
something out of it. All you seemed to do was create confusion.
I thought I was providing useful input. If you re-read my message, I don't
think the tone was particularly aggressive or confrontational, unlike your
own. I'd hate to think I confused anyone, but I'm as certain as I can be
that the OP would get confused if his code started acting strangely after
he'd been building upon it for months.