Comment On The Friday Farrago

Alliteration and an obscure synonym of "jumble". You know that can mean only one thing ... and let me say ... it's a looooong one today! [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: The Friday Farrago

2005-09-30 14:24 • by sinistral

Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...


%S is replaced by the second as a decimal number [00,61].





This is a WTF on the face of it, but there's a very good reason for
seconds to includ e  61.  That would be when leap seconds
happen, which they do periodically to allow clocks to  synchronize
with the gradual slowing rotation of the Earth.

Re: The Friday Farrago

2005-09-30 14:24 • by Maurits
Alex Papadimoulis:
could be fairly easily simplified to ";".


isActive = (isActive == true) ? true : false;


Or ""

Re: The Friday Farrago

2005-09-30 14:27 • by dsheets
I laughed at most of the above, but I didn't see the problem with the strftime man page. I believe the values are valid because of leap seconds aren't they? Or am I missing something else that should be funny?

Re: The Friday Farrago

2005-09-30 14:27 • by Maurits
45600 in reply to 45597
sinistral:

Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...


%S is replaced by the second as a decimal number [00,61].





This is a WTF on the face of it, but there's a very good reason for
seconds to includ e  61.  That would be when leap seconds
happen, which they do periodically to allow clocks to  synchronize
with the gradual slowing rotation of the Earth.



Indeed, the linked manpage says just that:
"The range of values for %S is [00,61] rather than [00,59] to allow
for the occasional leap second and even more infrequent double leap second."

Re: The Friday Farrago

2005-09-30 14:30 • by ACoward
What's the obscure synonym of 'jumble'???

Re: The Friday Farrago

2005-09-30 14:35 • by Mung Kee
Alex Papadimoulis:
  if (this == null)

{
throw new ArgumentNullException("this");
}





I've always hated those zombie classes.  They're dead but they just keep coming at ya.

Re: The Friday Farrago

2005-09-30 14:37 • by Mung Kee
45603 in reply to 45601
Anonymous:
What's the obscure synonym of 'jumble'???


Farrago

Re: The Friday Farrago

2005-09-30 14:39 • by kipthegreat
Alex Papadimoulis:

We'll start out with this simple piece of code that Jake Vinson tripped over while chasing bugs ...


if(3 < 4)
{
if(chk.value == 'Yes')
fld.value = 'No';
else
fld.value = 'Yes';
}




I've written code vaguely similar to this to trick the compiler,
strictly debugging purposes.. I don't see how it applies here though.



When I do it, it's usually because I want to return from a function early just to test something, say:



int function() {

  statementOne;

 

  // <--   I
just want to return a "correct" value here to see if it is the calling
function that is the problem


 

  statementTwo;

 

  return realReturnValue;

}





But if I just stick a "return 5;" in where my comment is, the compiler
will complain that statementTwo can never be reached.  So I'll do
this:



int function() {

  statementOne;

 

  if (5 > 4)

   
return 5;  // I just want to return a "correct" value here to see
if it is the calling function that is the problem


 

  statementTwo;

 

  return realReturnValue;

}




And that is enough to trick the compiler.  But I don't see any
reason for the WTF code, since it is not avoiding any compiler
complaints.

Re: The Friday Farrago

2005-09-30 14:45 • by Defender?
Alex Papadimoulis:


IF (current_num - prev_num = current_num) THEN


If this is an odd way of testing "prev_num == 0", then it's a WTF.

But without knowing the types, it's hard to say.  If, for instance, they're floats, then the expression could be true with prev_num != 0.

Re: The Friday Farrago

2005-09-30 14:50 • by Romeo
45606 in reply to 45600
Maurits:
sinistral:

Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...


%S is replaced by the second as a decimal number [00,61].





This is a WTF on the face of it, but there's a very good reason for
seconds to includ e  61.  That would be when leap seconds
happen, which they do periodically to allow clocks to  synchronize
with the gradual slowing rotation of the Earth.



Indeed, the linked manpage says just that:
"The range of values for %S is [00,61] rather than [00,59] to allow
for the occasional leap second and even more infrequent double leap second."




Do they ever thought about a even more infrequent triple leap second?

Re: The Friday Farrago

2005-09-30 14:53 • by Ronaldo Arribanorte
Regarding the last example (dot net DrawImage method), I'm pretty sure
the (this == null) check is useful when the method is invoked via
reflection, and the "this" object is actually a parameter to the method
invocation.  Can anyone confirm this?

Re: The Friday Farrago

2005-09-30 14:54 • by Apoch
Alex Papadimoulis:


public void DrawImage(Image image, int x, int y)

{
if (this == null)
{
throw new ArgumentNullException("this");
}
}


I've seen this idiom quite a bit in C++ to help cushion against null pointer problems, since 0->func(a,b,c); compiles with thiscall as _decorated_func(0,a,b,c) -- but in .Net? WTF indeed...

Re: The Friday Farrago

2005-09-30 14:58 • by Scott B.
45609 in reply to 45604
So who's got the COBOL -> 2005 translation? :)

Re: The Friday Farrago

2005-09-30 15:04 • by Alex Papadimoulis
45610 in reply to 45609

Scott B.:
So who's got the COBOL -> 2005 translation? :)


CONST FIVE = 4


Nothing new certainly, but fun to see it in COBOL.


 

Re: The Friday Farrago

2005-09-30 15:04 • by Matt B
45611 in reply to 45607
Anonymous:
Regarding the last example (dot net DrawImage method), I'm pretty sure
the (this == null) check is useful when the method is invoked via
reflection, and the "this" object is actually a parameter to the method
invocation.  Can anyone confirm this?




'this' is a reserved keyword, that code would never compile:



Test.cs(17): Identifier expected, 'this' is a keyword



Re: The Friday Farrago

2005-09-30 15:14 • by 604
45612 in reply to 45609
Well, I was forced to take cobol in HS (I swear I'm only 31 not 50) so I'll take a stab at it...



The field name is FIVE but its being set with the value of 4. 



I guess I didn't need my cobol for that either.


/took cobol in college even
//Never learned any JCL so all my cobol knowledge is probably a waste

///thats fine by me.

Re: The Friday Farrago

2005-09-30 15:16 • by fregas

How in the world could "this" ever equal null?????


Hey Alex, when you gonna post my Coldfusion wtf?

Re: The Friday Farrago

2005-09-30 15:19 • by Paul Tomblin
45614 in reply to 45606
They didn't consider "even more infrequent triple leap second" because the standard defines single and double leap seconds, but triple leap seconds are forbidden.



Actually, leap seconds are all going away.  They (damn, can't
remember the standards body) is going to let the time drift until it
reaches some large quanta like a minute in a few centuries.



Re: The Friday Farrago

2005-09-30 15:20 • by Mung Kee
45615 in reply to 45607
Anonymous:
Regarding the last example (dot net DrawImage method), I'm pretty sure
the (this == null) check is useful when the method is invoked via
reflection, and the "this" object is actually a parameter to the method
invocation.  Can anyone confirm this?




So what you're essentially saying is, this check guards against callers
trying to call this method after dynamically creating the owner
object?  In the immortal words of Gene Wirchenko:



I hope you're not serious



Sincerely,

Gene Wirchenko

Re: The Friday Farrago

2005-09-30 15:36 • by Matt
The strftime(3) man page on OpenBSD give more detail as to why %S goes all the way to 61.

"%S is replaced by the second as a decimal number
(00-61). The range of seconds is (00-61) instead of (00-59) to allow for the periodic occurrence of leap seconds and double leap seconds."

Re: The Friday Farrago

2005-09-30 15:37 • by makomk
45617 in reply to 45614
Anonymous:
Actually, leap seconds are all going away.  They (damn, can't remember the standards body) is going to let the time drift until it reaches some large quanta like a minute in a few centuries.


And $DEITY only knows what all the computer systems in the world will make of the time leaping forward a minute. (Especially any still using Unix-style timekeeping, of which there probably will be some, barring the total collapse of civilisation.)

Re: The Friday Farrago

2005-09-30 15:51 • by Jenny Simonds

Alex Papadimoulis:


And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".



isActive = (isActive == true) ? true : false;


Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?

Re: The Friday Farrago

2005-09-30 15:52 • by Mung Kee
45620 in reply to 45619
Jenny Simonds:

Alex Papadimoulis:


And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".



isActive = (isActive == true) ? true : false;


Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?





If it was a Boolean, yes, but since its a boolean (small 'b'), no.

Re: The Friday Farrago

2005-09-30 15:53 • by Alexis de Torquemada
Alex Papadimoulis:
#define private private




#define genius idiot



The guy who wrote this is surely the greatest genius born to this world in a long time.



Re: The Friday Farrago

2005-09-30 15:53 • by Ytram
45622 in reply to 45611
Matt B:
Anonymous:
Regarding the last example (dot net DrawImage method), I'm pretty sure
the (this == null) check is useful when the method is invoked via
reflection, and the "this" object is actually a parameter to the method
invocation.  Can anyone confirm this?




'this' is a reserved keyword, that code would never compile:



Test.cs(17): Identifier expected, 'this' is a keyword






That's essentially the point of the WTF in the code.  this refers to the instance of the object, and if it was null that method would never execute.



I have no clue regarding Renaldo's comment, as my experience with
Reflection in .NET is confined primarily to type checking and property
information.

Re: The Friday Farrago

2005-09-30 15:54 • by Cq
45623 in reply to 45604



int function() {

  statementOne;

 

  if (5 > 4)

   
return 5;  // I just want to return a "correct" value here to see
if it is the calling function that is the problem


 

  statementTwo;

 

  return realReturnValue;

}



ever tryed :

if (true) return 5;



or better:



if (IsTrue(5 > 4)) return5;



private bool IsTrue(int x, int y)

{

bool istrue;

if (x ==y) { istrue = true }

else { istrue = false }

return istrue



}



-C

Re: The Friday Farrago

2005-09-30 15:57 • by Mung Kee
45624 in reply to 45620
Mung Kee:
Jenny Simonds:

Alex Papadimoulis:


And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".



isActive = (isActive == true) ? true : false;


Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?





If it was a Boolean, yes, but since its a boolean (small 'b'), no.




Sorry, on second glance, this wasn't very helpful.  The value of
an uninitialized boolean is false in Java and there is no no-arg
constructor for the object type Boolean, so left uninitialized it would
be null.

Re: The Friday Farrago

2005-09-30 15:59 • by Alexis de Torquemada
45625 in reply to 45600
Maurits:

Indeed, the linked manpage says just that:
"The range of values for %S is [00,61] rather than [00,59] to allow
for the occasional leap second and even more infrequent double leap second."




And the moral to the story: RTFMB4UWTF.



Re: The Friday Farrago

2005-09-30 16:01 • by Alexis de Torquemada
45626 in reply to 45598
Maurits:
Alex Papadimoulis:
could be fairly easily simplified to ";".


isActive = (isActive == true) ? true : false;


Or ""




Not always.



Re: The Friday Farrago

2005-09-30 16:01 • by dubwai

I've seen another form of the if (this == null) construct in Java.


Foo foo = new Foo();


if (foo == null) return;

Re: The Friday Farrago

2005-09-30 16:05 • by Alexis de Torquemada
45628 in reply to 45604
kipthegreat:


But if I just stick a "return 5;" in where my comment is, the compiler
will complain that statementTwo can never be reached.




This is because the Java compiler especially is full of WTFs like emitting errors when it should only be emitting warnings.



Re: The Friday Farrago

2005-09-30 16:06 • by Alexis de Torquemada
45629 in reply to 45606
Anonymous:
Do they ever thought about a even more infrequent triple leap second?




Not in this tense.



Re: The Friday Farrago

2005-09-30 16:06 • by Ytram
45630 in reply to 45627
dubwai:

I've seen another form of the if (this == null) construct in Java.


Foo foo = new Foo();


if (foo == null) return;





You've gotta be careful, sometimes those pesky constructors will actually return a null reference.

Re: The Friday Farrago

2005-09-30 16:07 • by captain damage
45631 in reply to 45605
IF (current_num - prev_num = current_num) THEN


This is a method of testing that the change in numbers is
too small to have any effect. I've seen and used that construct
a lot in doing numeric analysis there the algorithm converges
on some value.

Re: The Friday Farrago

2005-09-30 16:08 • by Jonas Grumby
45632 in reply to 45597
sinistral:
  That would be when leap seconds
happen, which they do periodically to allow clocks to  synchronize
with the gradual slowing rotation of the Earth.





You're right about the leap seconds, but it's not that the earth is
slowing.  It's because the length of a solar year isn't exactly
the 365.24x days that the gregorian calendar allots for it.  If
you have to adjust a wall clock every few months, it's because it's too
fast, not because it's getting faster.

Re: The Friday Farrago

2005-09-30 16:11 • by Ben Scheirman
45633 in reply to 45623
That .NET one was pasted from Reflector, and you'll find a lot of that nonsense in the reflected code.


Here's a pop quiz:  What's going on in this reflected code?



public sealed abstract class Foo

{

    //stuff

}


Re: The Friday Farrago

2005-09-30 16:11 • by x
45634 in reply to 45620
Mung Kee:
Jenny Simonds:
Not familiar with
Java, but couldn't isActive have been set earlier to something like
null, NaN, or undefined?
If it was a Boolean, yes, but since its
a boolean (small 'b'), no.
Autoboxing?

Re: The Friday Farrago

2005-09-30 16:12 • by Alexis de Torquemada
45635 in reply to 45630
Ytram:
You've gotta be careful, sometimes those pesky constructors will actually return a null reference.




Not in any of C#, C++ or Java, so what language are you talking about?



Re: The Friday Farrago

2005-09-30 16:17 • by Alexis de Torquemada
45636 in reply to 45633
Anonymous:
That .NET one was pasted from Reflector, and you'll find a lot of that nonsense in the reflected code.


Here's a pop quiz:  What's going on in this reflected code?



public sealed abstract class Foo

{

    //stuff

}




Seems perfectly alright to me if you don't ever want your class to be
instantiated or subclassed. The C# compiler won't allow a mere mortal
to write this, though. It would be better to just define only a private
constructor.



Re: The Friday Farrago

2005-09-30 16:25 • by Ytram
45637 in reply to 45635
Alexis de Torquemada:
Ytram:
You've gotta be
careful, sometimes those pesky constructors will actually return a null
reference.




Not in any of C#, C++ or Java, so what language are you talking about?






Go into a C# project and create a class with a constructor.  In the constructor, do the following:



1.  Have the constructor take any value type, reference types won't work.

2.  Within the constructor, set the parameter to null.

3.  Add the line, "return null;" to the end of the constructor.

4.  Realize that I am being sarcastic.



Hopefully that should show you what I'm talking about.

Re: The Friday Farrago

2005-09-30 16:40 • by CornedBee
45638 in reply to 45632
Anonymous:
You're right about the leap seconds, but it's not that the earth is
slowing.  It's because the length of a solar year isn't exactly
the 365.24x days that the gregorian calendar allots for it.  If
you have to adjust a wall clock every few months, it's because it's too
fast, not because it's getting faster.




Not only because of the solar year length, but also to keep 00:00 at
precisely the moment when the sun is opposite the 0° meridian. The
earth's rotation isn't 100% uniform; it slows and speeds up due to the
moon and the other planets.

Re: The Friday Farrago

2005-09-30 16:55 • by Fj
45639 in reply to 45622

I suppose, something written here http://www.andymcm.com/dotnetfaq.htm, have produced such a confusion of ideas in the head of a programmer who wrote "if (this == null)". Actually, destructor may have been called during the method call in some circumstances, you know. 

Re: The Friday Farrago

2005-09-30 17:01 • by Alexis de Torquemada
45641 in reply to 45637
Ytram:
4.  Realize that I am being sarcastic.





Steps 1 to 3 were easy, but now I'm stuck at number 4. Tough one.



Re: The Friday Farrago

2005-09-30 17:08 • by Ytram
45643 in reply to 45641
I'm sorry, I should have clarified that you need to compile after step 3. [:P]

Re: The Friday Farrago

2005-09-30 17:13 • by emptyset
45644 in reply to 45631
Anonymous:

IF (current_num - prev_num = current_num) THEN


This is a method of testing that the change in numbers is
too small to have any effect. I've seen and used that construct
a lot in doing numeric analysis there the algorithm converges
on some value.


this is why mathematicians cannot program.  QED.

Re: The Friday Farrago

2005-09-30 17:19 • by Anonymous
45645 in reply to 45597
The strftime() documentation is still wrong. Unless you modify a struct
tm's fields yourself, the seconds will never be more than 59. struct
tm's are generated by the gmtime and localtime functions, which take a
time_t so there it no way they can distinguish between

2004/12/31 23:59:60 and 2005/01/01 00:00:00, since they both would have a time_t value of 1104537600.

Re: The Friday Farrago

2005-09-30 17:21 • by John Smallberries
45646 in reply to 45620
Mung Kee:
Jenny Simonds:

Alex Papadimoulis:


And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".



isActive = (isActive == true) ? true : false;


Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?





If it was a Boolean, yes, but since its a boolean (small 'b'), no.


What if it's not a boolean?

Couldn't it be some other type with the == operator overloaded?

(I'm not that familiar with Java; does it even support operator overloading?)

Re: The Friday Farrago

2005-09-30 17:24 • by Maurits
45647 in reply to 45645
Anonymous:
The strftime() documentation is still wrong. Unless you modify a struct
tm's fields yourself, the seconds will never be more than 59. struct
tm's are generated by the gmtime and localtime functions, which take a
time_t so there it no way they can distinguish between

2004/12/31 23:59:60 and 2005/01/01 00:00:00, since they both would have a time_t value of 1104537600.


Usually true, not always.
http://en.wikipedia.org/wiki/Leap_second

The next leap second will occur at the very end of December 31 2005.
Let me count the new year down for you...
2005/12/31 23:59:51 TEN!
2005/12/31 23:59:52 NINE!

2005/12/31 23:59:53 EIGHT!

2005/12/31 23:59:54 SEVEN!
2005/12/31 23:59:55 SIX!
2005/12/31 23:59:56 FIVE!
2005/12/31 23:59:57 FOUR!
2005/12/31 23:59:58 THREE!

2005/12/31 23:59:59 TWO!

2005/12/31 23:59:60 ONE!

2006/01/01 00:00:00 HAPPY NEW YEAR!

It will be interesting to see if the ball drops a second early.

Re: The Friday Farrago

2005-09-30 17:24 • by travis
45648 in reply to 45646
John Smallberries:
Mung Kee:
Jenny Simonds:

Alex Papadimoulis:


And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".



isActive = (isActive == true) ? true : false;


Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?




If it was a Boolean, yes, but since its a boolean (small 'b'), no.

What if it's not a boolean?
Couldn't it be some other type with the == operator overloaded?
(I'm not that familiar with Java; does it even support operator overloading?)


Nope...no operator overloading in Java

Re: The Friday Farrago

2005-09-30 17:32 • by Anonymous
45649 in reply to 45647
The time_t will have the same value, 1136073600, on both of those last
two seconds. So there's no way localtime/gmtime can distinguish them,
unless it does something really weird.

« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment