Comment On Not Doing Nothing

Nathan was going through some of his company's fairly buggy JavaScript calendar code, and saw this perfectly described function. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Not Doing Nothing

2007-10-24 09:17 • by Mathimaz (unregistered)
...

Nothing

2007-10-24 09:18 • by morpcat

Re: Not Doing Nothing

2007-10-24 09:21 • by blupp
function DoNothing()
{
Nothing();
}

function Nothing()
{
}

Re: Not Doing Nothing

2007-10-24 09:26 • by aythun
function DoNothing()

{
Nothing();
}

function Nothing()
{
DoNothing();
}

Re: Not Doing Nothing

2007-10-24 09:31 • by RogerC
158507 in reply to 158504
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?

Re: Not Doing Nothing

2007-10-24 09:31 • by Strider
158508 in reply to 158506
aythun:
function DoNothing()

{
Nothing();
}

function Nothing()
{
DoNothing();
}



Brrriiliant!!

Re: Not Doing Nothing

2007-10-24 09:37 • by Bosshog (unregistered)
The real WTF would be if it did something.


function Nothing()
{
runGalaxySimulation();
updateBankBalances();
archiveTheInternet();
floodSiliconValley();
}

Re: Not Doing Nothing

2007-10-24 09:39 • by sweavo (unregistered)
Maybe one of them doesn't return anything, whereas the other has no side effects.

function LaLaLalalalaa()
{
while(!WholeDayThrough)
{
DoNothing();
try
{
thing=find_next(!ToDo);
}

GoNowhere();

if (Time!=NULL)
{
BeUnhappy();
}
}
}


'scuse my language, I don't speak java

Re: Not Doing Nothing

2007-10-24 09:40 • by codemonkey (unregistered)
Maybe they forgot to define what "doing nothing" entails and intended on filling it in at a later time...say, just before production release?

I would love to see their reasoning behind making nothing functions though.

Re: Not Doing Nothing

2007-10-24 09:41 • by doom (unregistered)
captcha: doom

Re: Not Doing Nothing

2007-10-24 09:44 • by Storme
Doing nothing = waiting to eventually do something

Re: Not Doing Nothing

2007-10-24 09:49 • by gabba
I'm not seeing the wtf here. Obviously there's a difference between nothingness and not doing anything.

Re: Not Doing Nothing

2007-10-24 10:02 • by Guran (unregistered)
This must be som sort of bug-prevention. How many times have you heard the following?

"The application crashed, you did the last check-in, what did you change?"
"Nothing"

So by assuring a really harmless implementation of Nothing() such things should never occur...

Re: Not Doing Nothing

2007-10-24 10:03 • by GPC (unregistered)
DoNothing should call Nothing though:

function DoNothing{
Nothing();
}

Re: Not Doing Nothing

2007-10-24 10:06 • by JS (unregistered)
158522 in reply to 158502
Don't do what Donny don't does. Even if Donny Don't doesn't do anything.

Re: Not Doing Nothing

2007-10-24 10:07 • by Marcel (unregistered)
Function MakeComment
{
}

Re: Not Doing Nothing

2007-10-24 10:24 • by Raymond Chen
The person who wrote Nothing() didn't realize that somebody had already written it. A simple matter of duplicate code (for a dummy callback).

Re: Not Doing Nothing

2007-10-24 10:30 • by rd (unregistered)
158528 in reply to 158507
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?

Re: Not Doing Nothing

2007-10-24 10:31 • by Brandon (unregistered)
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--;
}

Re: Not Doing Nothing

2007-10-24 10:31 • by zolf (unregistered)
"""python version"""

def nothing():
global nothing, do_nothing, really_nothing
nothing = do_nothing
def do_nothing():
global nothing, do_nothing, really_nothing
do_nothing = really_nothing
def really_nothing():
global nothing, do_nothing, really_nothing
really_nothing = nothing

Re: Not Doing Nothing

2007-10-24 10:33 • by Aidan (unregistered)
doNothing()
{
}

dontDoNothing()
{
doNothing() ;
}

Re: Not Doing Nothing

2007-10-24 10:34 • by jbosss (unregistered)
I have only one thing to add: ""

Captcha: tesla. man, I miss my old TV

Re: Not Doing Nothing

2007-10-24 10:36 • by JoC
158533 in reply to 158530
It's really just a clever deployment solution. See, who wants to go through that pesky compile step every time?

They just add calls this function and then insert code directly into it in memory at run time until it behaves as desired.

Re: Not Doing Nothing

2007-10-24 10:38 • by AdT (unregistered)
function DoNothing()
{
// TODO: Inline assembler does not seem to work in JavaScript :-(
// TODO: Find a different way to do nothing
// asm { NOP };
}

Re: Not Doing Nothing

2007-10-24 10:51 • by Spock (unregistered)
Very enterprisy.

Capta: Stinky.... ewww

Re: Not Doing Nothing

2007-10-24 10:52 • by Spock (unregistered)
Very Enterprisy

Re: Not Doing Nothing

2007-10-24 11:05 • by DAVE_CHANG (unregistered)
I have days that emulate this function.

Worth a chuckle

2007-10-24 11:20 • by Joe User (unregistered)
http://imgs.xkcd.com/comics/exploits_of_a_mom.png

Re: Not Doing Nothing

2007-10-24 11:21 • by TheRider
158544 in reply to 158531
Of course, this should be:
Aidan:
doNothing()
{
Nothing();
}

dontDoNothing()
{
!doNothing();
}

Re: Not Doing Nothing

2007-10-24 11:24 • by Synonymous Coward (unregistered)
158545 in reply to 158527
Maybe it was written by someone who didn't know about the void operator.

function Nothing() { }

alert(Nothing() === void(0));

Re: Not Doing Nothing

2007-10-24 11:25 • by Southern (unregistered)
Compiles
Does what it says
Does not have extra lines
Does not need comments
Does not waste nanoseconds

Etc

It's utopical

Re: Not Doing Nothing

2007-10-24 11:27 • by Daz (unregistered)
Does exactly what it says on the tin!

Re: Not Doing Nothing

2007-10-24 11:32 • by BBT (unregistered)
the second function should be named doAnything(). When you doNothing, you don't doAnything. Then it would make complete sense that doAnything() does not get called by doNothing().

Re: Not Doing Nothing

2007-10-24 11:32 • by vt_mruhlin
Maybe some crafty API takes two callbacks, say onFail and onFailFail. This way, if the function fails you can do failure handling in onFail. If onFail fails, you call onFailFail to log an error or something.

And the API is friendly enough to yell at you for using the same function for both. Obviously if onFail fails, you don't want to call it again! Are you trying to create an infinite loop?

/Man, I'm totally going to put stuff like that n my next application just to give people a headache.

Re: Not Doing Nothing

2007-10-24 11:32 • by Loren Pechtel (unregistered)
There's nothing wrong with a function called Nothing or something of the sort. I've done it more than once.
It can make it clearer what a piece of code is doing.

Re: Not Doing Nothing

2007-10-24 11:35 • by DAVE_CHANG (unregistered)
doAnything()
{
var h = Math.random();
for (var i=0; i < h; i++)
{
doNothing();
}
}

Re: Not Doing Nothing

2007-10-24 11:50 • by Random832
158555 in reply to 158512
sweavo:

'scuse my language, I don't speak java


It's javascript, not java. Your only problems are: try with no catch, and null should be lowercase. And none of the variables you're using exist, but they could be defined at any time elsewhere, so it's a runtime error only.

Synonymous Coward:
Maybe it was written by someone who didn't know about the void operator.

function Nothing() { }

alert(Nothing() === void(0));


It never occured to me that undefined was a specific entity that could be compared to itself.

Re: Not Doing Nothing

2007-10-24 11:53 • by chris (unregistered)
Both functions are clearly necessary to keep the code readable:

if (0 == 1) {
DoNothing();
}

but

do {
Nothing();
} while (0 == 1);

Really, who would want to read "do DoNothing()"?

(Hey, what about "PLEASE DO NOTHING"?)

Re: Not Doing Nothing

2007-10-24 12:00 • by Harrow (unregistered)
158558 in reply to 158548
BBT:
the second function should be named doAnything(). When you doNothing, you don't doAnything. Then it would make complete sense that doAnything() does not get called by doNothing().
Yes. Thank you. I could see that the code was wrong, but I couldn't quite see how to fix it.

-Harrow.

Re: Not Doing Nothing

2007-10-24 12:19 • by Dustin_00
function DoNothing()
{
Do();
Nothing();
}

function Do()
{
}

function Nothing()
{
}

Re: Not Doing Nothing

2007-10-24 12:28 • by Graham (unregistered)
Damn- I hope that function was well tested.

Re: Not Doing Nothing

2007-10-24 12:36 • by Scott tiger (unregistered)
I thought this looked funny.
Found it in all the sites that we do.


function nothing(){
return;
}

Re: Not Doing Nothing

2007-10-24 12:47 • by sweavo (unregistered)
158566 in reply to 158555
Random832:
sweavo:

'scuse my language, I don't speak java


It's javascript, not java. Your only problems are: try with no catch, and null should be lowercase. And none of the variables you're using exist, but they could be defined at any time elsewhere, so it's a runtime error only.


Oh cock it! You mean after all these years of avoiding JS like the plague it is, I've gone and written some for fun?!

Enter your First Name: 20
Enter your last Name: 15
Your email address is: 35@javascript_sucks.com

Re: Not Doing Nothing

2007-10-24 12:47 • by Artem Ploujnikov (unregistered)
Empty functions are useful for overriding or specifying default event handlers in certain cases.

e.g.
<a onclick="SomeThirdPartyLibrary.callThis()" href="javascript:DoNothing()" >click</a>

Re: Not Doing Nothing

2007-10-24 13:02 • by Dude (unregistered)
...

I wont tell anyone. My Lips are sealed. Now i have to call a friend. (Evil laughg)


Capacha: Ewww (When i will think of food that i dont like, i will think about this capacha)

Re: Not Doing Nothing

2007-10-24 13:04 • by O Thieu Choi (unregistered)
Positively (well, negatively) Heideggerian!

Re: Not Doing Nothing

2007-10-24 13:25 • by Stephen Baker (unregistered)
Perhaps they think the empty function in prototype is a WTF too? http://www.prototypejs.org/api/prototype

Re: Not Doing Nothing

2007-10-24 13:38 • by TimJ (unregistered)
The solution is easy: DoNothing is a function. Nothing is a constructor for instances of Nothing. So you invoke it like that:

DoNothing();
var something = new Nothing();


Re: Not Doing Nothing

2007-10-24 13:43 • by Anon (unregistered)
158581 in reply to 158512
sweavo:
'scuse my language, I don't speak java

Obviously, if this were Java instead of JavaScript, it would be:

public final class Utils {

/**
* Does nothing.
*/
public static final void doNothing() {
nothing();
}
/**
* @deprecated replaced with {@link #doNothing()}
*/
public static final void nothing() {
// nothing
}
}


And while that is a joke, it's unfortunately fairly normal, as this excerpt from Sun's current implementation java.awt.Component demonstrates:

    /**

* Prompts the layout manager to lay out this component. This is
* usually called when the component (more specifically, container)
* is validated.
* @see #validate
* @see LayoutManager
*/
public void doLayout() {
layout();
}

/**
* @deprecated As of JDK version 1.1,
* replaced by <code>doLayout()</code>.
*/
@Deprecated
public void layout() {
}


That is real, as anyone with Sun's JDK can verify by peeking in src.zip.

Re: Not Doing Nothing

2007-10-24 14:05 • by iMalc (unregistered)
Presumably Nothing uses these funtions.
I guess the author felt that it was good to know that they could DoNothing if they wanted to, which would be nice to know.
« PrevPage 1 | Page 2Next »

Add Comment