• r (unregistered)

    i can see how this would happen... some js frameworks require callback functions; the developer probably simply wasn't aware of anonymous functions.

  • Stinky McPooty (unregistered) in reply to rd
    rd:
    RogerC:
    blupp:
    function DoNothing() { Nothing(); }
    function Nothing() 
    {
    }
    
    Brillant! You've removed the WTF-ness.

    You're quite the party pooper. Now what do we talk about?

    How about wooden tables, captcha, fist, and file not found?

    BRILLANT!

  • j_johnso (unregistered) in reply to r

    See the code for /bin/true included with Solaris. http://forums.worsethanfailure.com/forums/thread/90649.aspx

    Or IEFBR14 which sometimes fails at doing nothing

  • fanha (unregistered) in reply to codemonkey

    Self-documenting code. A blank line without code before a semicolon is often suspect as something that got accidentally deleted or accidentally prematurely terminates an if statement (the classic "oops I put a semicolon after the if line"). Using a dummy function that explicitly shows you are intending to do nothing creates no overhead and makes your code more readable and easier to debug.

  • (cs)

    A function named "DoNothing" is very Dilber-esque!

  • Jon (unregistered)

    You're the WTF today that's a design pattern moron

  • Val (unregistered) in reply to DAVE_CHANG
    DAVE_CHANG:
    doAnything() { var h = Math.random(); for (var i=0; i < h; i++) { doNothing(); } }

    A good compiler will surely optimize it...

  • joshu (unregistered) in reply to gabba

    A very Zen observation.

    "There once was a master programmer who wrote unstructured programs. A novice programmer, seeking to imitate him, also began to write unstructured programs. When the novice asked the master to evaluate his progress, the master criticized him for writing unstructured programs, saying, ``What is appropriate for the master is not appropriate for the novice. You must understand the Tao before transcending structure.''" - Tao of Programming

  • nobody (unregistered)

    function DoNothing() { var x = 1; for(var i=0; i<1000; i++) { x *= i; } return; }

    function Nothing() { var i=4; while(i > 7) DoNothing(); }

  • s. (unregistered)

    Been somewhere there not long ago.

    There was somefunction(callback) and I wanted no callback. So I recalled there already IS a 'nothing' function called 'void', and so happily wrote somefunction(void(null)); And it took me more than half a hour to recall you need to pass the reference and it's the (null) that breaks my code.

  • (cs) in reply to Artem Ploujnikov
    Artem Ploujnikov:
    Empty functions are useful for overriding or specifying default event handlers in certain cases.

    e.g. click

    Why would you want to do that? That's horrible design. Use unobtrusive and accessible JavaScript or a ninja kills a kitten.

  • Evan (unregistered)

    It actually makes sense to declare an empty function (though perhaps it wasn't the code authors intention). It's useful when you need to pass callback handlers to function, for example:

    function empty()
    {
    }
    
    function x(name, callback)
    {
       if (!callback)
          callback = empty;
    }
    
    x('no callback');
    
  • AH (unregistered)

    Since a function in JavaScript is also an object, Nothing not only DOES nothing, it IS nothing ;-)

  • An apprentice (unregistered) in reply to Anon
    Anon:
    Obviously, if this were Java instead of JavaScript, it would be: <snip>

    Not enterprisey enough. If this were Java, it would need more XML. To be, uh, more interoperable or something.

  • (cs)

    function NoQuack() { }

  • (cs)

    Shouldn't DoAnything() be something like: DoAnything() { *() Function; Function = ( *() )Random(); *Function(); }

    (Or however that should be written)?

    (In case my intent is unclear, Create a pointer to a function, Fill it with random number, and then attempt to execute it. Of course, the possibility that it would do anything other than sig 11 is very low.....)

  • (cs) in reply to Dustin_00

    Or....

    function(){} as the callback?

    Or....

    function DoNothing() { Do(Nothing); } function Do(f) { f(); } function Nothing() {}

  • Anonymous Coward (unregistered)

    Boo! Not enterprisey at all!

    THIS is how you do is:

    public interface NihilismProvider {
    
      public void nothing();
    
    }
    
    public class Nothing implements NihilismProvider {
    
      public void nothing() {
      }
    
    }
    
    public class DoNothing implements NihilismProvider {
    
      public void nothing() {
      }
    
    }
    
    public class NihilismFactory {
    
      public NihilismProvider getNothing(Object something) {
        if (something == null) {
          return new Nothing();
        } else {
          return new DoNothing();
        }
      }
    
    }
    
    public class Program {
      public static void main(String[] args) {
        NihilismFactory fact = new NihilismFactory();
        NihilismProvider nothing = fact.getNothing(null);
        nothing.nothing();
        System.exit(42);
      }
    }
    
  • Flea done but fly undone (unregistered)

    In Soviet Russia nothing do you.

  • steph (unregistered)

    As advertised.

  • csrster (unregistered) in reply to Evan
    Evan:
    It actually makes sense to declare an empty function (though perhaps it wasn't the code authors intention). It's useful when you need to pass callback handlers to function, for example:
    
    function empty()
    {
    }
    
    function x(name, callback)
    {
       if (!callback)
          callback = empty;
    }
    
    x('no callback');
    

    In addition, in almost any OO language there are going to be times when you have to give an empty body to the implementation of a method. For example I recently implemented a little state engine in which the states implemented an interface containing a moveToNextState() method. For the end-states the method does nothing (but at least has a comment explaining why).

    Of course the real wtf is that I'm writing this instead of doing real work.

  • (cs) in reply to Brandon
    Brandon:
    Entirely not enough recursion, global variables, magic numbers, or infinite loops...
    var i = 0;
    function DoNothing()
    {
      if (i < 42)
      {
        i++;
        DoNothing();
      }
      else
      {
        Nothing();
      }
    }
    
    function Nothing()
    {
      i--;
    }
    

    (...)

    That loop isn't infinite. At some point when DoNothing() is called, i will be 42 at which time it'll call Nothing() and i will be 41... However, at that point DoNothing() is not called again and the game is over...

    Why do we need functions that DoNothing anyway, when we have so many managers doing a great job at that already!

    (I had to add (...) between [ /code ] and [ /quote ] or my first line of comment would have been part of his quote ???)

  • Cloak (unregistered)

    I thibnk we're missing one function that's somewhere in darker parts of the code:

    Do(noThing) { if(!noThing) DoNothing() else Nothing() }

    Nothing() { DoNothing() ; }

    DoNothing() { Do(Nothing) ; }

  • iogy (unregistered)

    Maybe someone didn't know how to implement a nice delay.

    // pseudo as hell, also unsafe function Wait(seconds) { SetTimeout(seconds, "Nothing();") }

  • Cloak (unregistered)

    ... and when I think that people are laughing about VB or Coldfusion. Of course, you can write a function that does nothing

    private sub DoNothing: end sub

    But, for sure, you don't need such WTFs just to make compilers happy

    CAPTCHA: quake (Shoot'em up, those people who create (so-called modern) programming languages)

  • Anon (unregistered)

    DoNothing() is clearly ambiguous, it can be intepreted in two different ways.

    1. Doing nothing, not doing anything. Not even Nothing().
    2. Doing "nothing", where "nothing" could be something even if it's not and it's actually Nothing(). Altough if Nothing() is something then its not nothing since something isn't nothing.

    So when you look it like this, you can do nothing by not doing anything or actually doing nothing. Both will do the same thing (which is nothing) as long as Nothing() is not something.

    I think Jerry Seinfeld wrote these functions just to annoy people.

  • dkf (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    Boo! Not enterprisey at all!

    THIS is how you do is:

    [...]

    public class Program {
      public static void main(String[] args) {
        NihilismFactory fact = new NihilismFactory();
        NihilismProvider nothing = fact.getNothing(null);
        nothing.nothing();
        System.exit(42);
      }
    }
    Even that isn't enterprisey enough. Remember, you've got to avoid hard-coded constructors, which leads to things like this (I'll just write the contents of main to keep things short...)
    InitialContext ctx = new InitialContext();
    NihilismFactoryService service = (NihilismFactoryService)
        PortableRemoteObject.narrow(ctx.lookup(
                "java:com.worsethanfailure.notDoingNothing.NihilismFactoryService"), 
                NihilismFactoryService.class);
    NihilismFactory nothingFactory = (NihilismFactory)
        service.getNihilismFactoryQueryPort();
    NihilismProvider nothing = nothingFactory.getNothing(null);
    nothing.nothing();

    Now if you'll excuse me, I need to take something to cure me of the pain of writing code with its head that far up its enterprise...

  • iw (unregistered)

    At least it wasn't:

    [code] DoNothing() { }

    Nothing() { DoNothing(); }

  • iw (unregistered)

    At least it wasn't:

    DoNothing() {
    }
    
    Nothing() {
      DoNothing();
    }
    
  • Mr Steve (unregistered) in reply to joshu
    joshu:
    A very Zen observation.

    "There once was a master programmer who wrote unstructured programs. A novice programmer, seeking to imitate him, also began to write unstructured programs. When the novice asked the master to evaluate his progress, the master criticized him for writing unstructured programs, saying, ``What is appropriate for the master is not appropriate for the novice. You must understand the Tao before transcending structure.''" - Tao of Programming

    Somebody needs to get laid

  • csrster (unregistered) in reply to Mr Steve

    public class ThreeMonkeys {

    public void seeNoEvil(){} public void hearNoEvil(){} public void speakNoEvil(){}

    }

  • Max Romantschuk (unregistered) in reply to Artem Ploujnikov
    Artem Ploujnikov:
    Empty functions are useful for overriding or specifying default event handlers in certain cases.

    e.g. click

    For clean code you'd probably wish to use: click

    When onclick gets false it won't follow the URL, and if JavaScript is turned off it will.

  • Pat (unregistered)

    The latter is obviously for: do{Nothing();} while(...)

  • yonil (unregistered) in reply to Pat

    function Nothing() {
    }

    function Do(f) { f(); }

    function DoNothing() { Do(Nothing); }

  • Mkdir (unregistered)

    function Goggles() { DoNothing(); }

  • (cs) in reply to Mkdir
    Mkdir:
    function Goggles() { DoNothing(); }
    You win!
  • Stefan W. (unregistered)

    javascript doesn't know functionpointers - does it?

    Else you could test:

    if (&doNothing() == &Nothing ()) // ... why should we do so? // for the pure enlightment.

    Syntax is probably wrong - when did I do C/C++ the last time? cuptchu: bathe

  • poop (unregistered)

    /**

    • @author: nobody
    • @license:
    • @date: 00-00-00 00:00:00 */

    class DoNothingTest implements TestCase {

    tearUp(){

    }

    tearDown(){

    }

    testDoNothing(){ assert(ReflectionTools.getCode(NothingTools, "doNothing")); }

    }

  • poop (unregistered) in reply to poop

    /**

    • @author: nobody
    • @license:
    • @date: 00-00-00 00:00:00 */

    class DoNothingTest implements TestCase {

    tearUp(){

    }

    tearDown(){

    }

    testDoNothing(){ assert(ReflectionTools.getCode(NothingTools, "doNothing").size() == 0); }

    }

  • (cs) in reply to poop

    DoNothing is misnamed. It very definitely does something. It returns. A REAL DoNothing would do ABSOLUTELY nothing. The processor would simply cease executing the thread, without changing any memory locations or registers. I am aware that may be impossible.

    Maybe DoNothing should even halt all electron motions in the computer. Including those which cause DRAM to lose its contents if not regularly refreshed.

    So essentially, DoNothing should stop time for the computer system. And somehow do so without doing anything.

  • (cs) in reply to r
    r:
    i can see how this would happen... some js frameworks require callback functions; the developer probably simply wasn't aware of anonymous functions.
    Yes, indeed, all too many people claim to be "JavaScript developers" despite not being aware of basic features of the JavaScript language.

    If this ludicrous state of affairs isn't a WTF, I'd like to know what would be.

    (Mind you, I can understand incompetent monkeys who probably shouldn't be using computers at all having trouble with anonymous functions. It's the people who beg you not to use 'with' blocks because they're "too complicated" that depress me.)

  • srp (unregistered)

    Empty functions are useful for writing viruses on c/++

  • Roland Illig (unregistered)

    From NetBSD's pkgsrc:

    # How to do nothing.  Override if you, for some strange reason, would rather
    # do something.
    DO_NADA?=               ${TRUE}
    
  • Roland Illig (unregistered)

    Hmmm, that HTML code doesn't look good:


    # How to do nothing.  Override if you, for some strange reason, would rather
    
    # do something.
    DO_NADA?= ${TRUE}

    Why should anyone need
    inside

    ? WTF.

  • Q (unregistered)

    Noting() is for debug breakpoint.

  • Capt. Obvious (unregistered) in reply to Brandon
    Brandon:
    var i = 0;

    function DoNothing()

    {

    if (i < 42)

    {

    i++;
    
    DoNothing();
    

    }

    else

    {

    Nothing();
    

    }

    }

    function Nothing()

    {

    i--;

    }

    Three out of four ain't bad. But you missed infinite loops/infinite recursion.

  • veidelis (unregistered) in reply to aythun

    Please, fix! It doesnt work!!

    Chrome gives me "RangeError: Maximum call stack size exceeded" when running this:

    function DoNothing(){ Nothing(); }

    function Nothing(){ DoNothing(); }

    Nothing();

    How do i make sure it does nothing??

  • Sebastian Ramadan (unregistered)
    function nothing() {
        return new nothing();
    }
    

    Checkmate for prototypical inheritance.

Leave a comment on “Not Doing Nothing”

Log In or post as a guest

Replying to comment #:

« Return to Article