Re: Java Code Convention Guidelines question...

From: Chris Smith (cdsmith_at_twu.net)
Date: 01/06/04


Date: Tue, 6 Jan 2004 09:38:41 -0700

rkm wrote:
> > That's not the issue. The issue is invoking a static method while
> > thinking that it is (and therefore expecting it to act like) an instance
> > method. Since the two behave in completely different ways, this could
> > add bugs to code very easily.
> >
> Again, show an example.

Okay. I fixed a bug about three or four months ago in which someone
called Thread.sleep using an instance reference, and expected it to put
a different thread to sleep. See? The instance method syntax caused
confusion, by implying that the method "sleep" acted on a specific other
instance, when it really doesn't.

I realize that's a little bit different from our conversation, which is
about whether a developer should intentionally pretend to act on some
specific object when they really aren't. Doing so intentionally is so
strange and twisted, though, that I can't possibly think of any sort of
realistic example of someone doing so; so I'm resorting to an example of
accidentally doing so to show how confusing it is.

> Let's not confuse things by extending the argument to "any
> arbitrary change". No-one said that.

Right. I'm *trying* to prompt you to tell me why you think that
instance and static methods ought to be interchangable... but you're not
taking the hint. So why is it?

-- 
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Relevant Pages

  • Re: Rationale for CS0536?
    ... >> current thread to sleep since Sleep is a static method. ... > design or even naming problem, nothing that would have to be ... Weren't you just asking why the compiler didn't let you call static methods ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Help with Thread Sleep Calls causing lack of SLEEP
    ... sleepis a static method. ... Java allows static members to be accessed via references, ... *always* the one which is set to sleep. ... > waiting a random set amount of time for something else to finish - you ...
    (comp.lang.java.help)
  • Re: form object
    ... early on I thought about using a timer since a counter does not run ... concerned about the differing speeds on the various local workstations. ... any static method should probably be thread-aware; ... You don't want to Sleep(), as this will hang the UI thread (unless you spin ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Socket Client , abnormal behavior when sending byte
    ... >>1) Are you using UDP instead of TCP? ... Ooohhh. ... sleep() is a static method that operates on whatever the current thread ...
    (comp.lang.java.programmer)
  • Re: form object
    ... any static method should probably be thread-aware; when dealing with ... and push the method onto the owning UI's thread; ... You don't want to Sleep(), as this will hang the UI thread (unless you spin ...
    (microsoft.public.dotnet.languages.csharp)