Comment On Quantum Computering

A little while back, I posted a function that generated random hexadecimal-like strings for a GUID-like string to identify events. At first, I thought it (and the rest of the system that Taka's company purchased) was just bad code. But now that I look at it further, I'm stunned at its unbelievable complexity. I can honestly say that I've never seen code that is actually prepared to run a quantum computer, where binary just isn't as simple as 1's and 0's ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Quantum Computering

2005-08-22 14:48 • by Isaac

This system is ahead of its time.  Negative quantum information was just recently discovered(http://www.physorg.com/news5621.html) and yet this system already has a -1 value for hex2dec!

Re: Quantum Computering

2005-08-22 14:49 • by JohnO
You gotta love hex2dec("11") returning -1.  Option Explicit wouldn't hurth either.

Re: Quantum Computering

2005-08-22 14:49 • by Mung Kee
What?  no dec2hex() or bin2hex()?

Re: Quantum Computering

2005-08-22 14:54 • by WTFer
And I always tought that computers numbers were binary. 

Re: Quantum Computering

2005-08-22 14:55 • by rogthefrog
I love the consistency in error case return values. -1 for one, 2222 for the other. I guess -1-1-1-1 wouldn't work.

Re: Quantum Computering

2005-08-22 14:57 • by Ross Day
41415 in reply to 41414
rogthefrog:
I guess -1-1-1-1 wouldn't work.




-4?

Re: Quantum Computering

2005-08-22 15:07 • by David
41416 in reply to 41415

Ross Day:
rogthefrog:
I guess -1-1-1-1 wouldn't work.


-4?


Brillant!


 


Sorry...someone had to say it...

Re: Quantum Computering

2005-08-22 15:09 • by Apoch
41417 in reply to 41415

This is problematic. I'm sure the lexical parser layer in the system would reduce -1-1-1-1 to (-1 * -1) * (-1 * -1) which is, of course, 1 - and 1 is plainly not the correct result. Therefore 2 is the only genuine option. Besides, everyone knows that 2 is an impossible number, so this function absolutely cannot ever fail!


 


Brillant.

Re: Quantum Computering

2005-08-22 15:09 • by Mung Kee
41418 in reply to 41416
Anonymous:

Ross Day:
rogthefrog:
I guess -1-1-1-1 wouldn't work.


-4?


Brillant!


 


Sorry...someone had to say it...



That one will live on for quite a while.  Thanks Paula!

Re: Quantum Computering

2005-08-22 15:46 • by dubwai

If you buy into the "Joel on Software: I hate exceptions" approach, this is prefectly good code.


And we all know that everywhere these methods are being called, the caller is checking that the value is not 2222 or  -1 respectively.

Re: Quantum Computering

2005-08-22 16:08 • by joe_bruin
as far as i'm concerned, the second function is perfectly valid. 
-1 is a value that cannot be stored in a hex digit, and is a good way
to return an error.  sure, the author was a bit daft, but i
wouldn't call security to escort him out of the building if i saw it in
my codebase.



the first function, on the other hand, subscribes to the theory of "if
i find an error, i'll just silently introduce more errors into the
data".  deserving of a reprimand, but still not a fireable
offence.  i just hope the fucker who wrote this is not making more
than i am.

Re: Quantum Computering

2005-08-22 16:09 • by stevekj
Alright, I know what the WTF is here... not only does this code not handle lowercase letters, but it doesn't do uppercase
numbers either!



Re: Quantum Computering

2005-08-22 16:14 • by Jake Vinson
You know, when I was doing classic WTF week, I wanted to repost the Paula Bean one.  That was one of my favorites ever, it just seemed too soon and people were already bitching about reposts.

Re: Quantum Computering

2005-08-22 16:18 • by dave
luckily my life exists with the bounds of [0,15]

Re: Quantum Computering

2005-08-22 16:18 • by Mung Kee
41427 in reply to 41425
Jake Vinson:
You know, when I was doing classic WTF week, I
wanted to repost the Paula Bean one.  That was one of my favorites
ever, it just seemed too soon and people were already bitching about
reposts.




No doubt that was an instant classic.

Re: Quantum Computering

2005-08-22 16:21 • by John
41428 in reply to 41410

hex2dec("11") would be bad. If that's the way the code is being used. But, it might instead be being used like this:



(and, sorry, I don't know visual basic; using perl)




sub some_larger_routine {
my $input = shift(@_);
my $val = 0;

($input =~ /^[A-F0-9]+$/)
|| (do something error-like);

while (length($input)) {
$val = $val * 16;
$val += hex2dec(substr($input, 0, 1, ""));
}
return ($val);
}


Of course, if that were the case, I would expect that instead of "hex2dec", the submitted code would be called something like "hexdigit2decdigit", and then the above code would be called "hex2dec" instead of "some_larger_routine".



And that still leaves the nature of how errors are being handled.


Re: Quantum Computering

2005-08-22 16:23 • by John
41429 in reply to 41428

Ugh. Why does the "preview" button show things as though it's html formatted, when the final post doesn't require html formatting? I think that's a WTF right there.

Re: Quantum Computering

2005-08-22 16:23 • by dubwai
41430 in reply to 41423

Anonymous:
as far as i'm concerned, the second function is perfectly valid.  -1 is a value that cannot be stored in a hex digit, and is a good way to return an error.  sure, the author was a bit daft, but i wouldn't call security to escort him out of the building if i saw it in my codebase.

the first function, on the other hand, subscribes to the theory of "if i find an error, i'll just silently introduce more errors into the data".  deserving of a reprimand, but still not a fireable offence.  i just hope the fucker who wrote this is not making more than i am.


I don't see why -1 is a better return code than 2222.  2222 cannot be stored in a hex digit either.  Perhaps from a convention standpoint it's better but not fundamentally.

Re: Quantum Computering

2005-08-22 16:31 • by dubwai
41431 in reply to 41425

Jake Vinson:
You know, when I was doing classic WTF week, I wanted to repost the Paula Bean one.  That was one of my favorites ever, it just seemed too soon and people were already bitching about reposts.


This has already been posted.  Try the seach tool.

Re: Quantum Computering

2005-08-22 16:33 • by emptyset
Alex Papadimoulis:

    Case Else
      hex2bin = "2222"
    Case Else
      hex2dec = -1


WRONG, WRONG, WRONG!  didn't he read the spec?  these functions are supposed to return "Z"!

Re: Quantum Computering

2005-08-22 16:35 • by DisturbedSaint
41433 in reply to 41431
dubwai:

Jake Vinson:
You know, when I was
doing classic WTF week, I wanted to repost the Paula Bean one. 
That was one of my favorites ever, it just seemed too soon and people
were already bitching about reposts.


This has already been posted.  Try the seach tool.





Now *that* is brilliant!



-ds

Re: Quantum Computering

2005-08-22 16:43 • by Volmarias
41435 in reply to 41423
Anonymous:
as far as i'm concerned, the second function is perfectly valid. 
-1 is a value that cannot be stored in a hex digit, and is a good way
to return an error.  sure, the author was a bit daft, but i
wouldn't call security to escort him out of the building if i saw it in
my codebase.



the first function, on the other hand, subscribes to the theory of "if
i find an error, i'll just silently introduce more errors into the
data".  deserving of a reprimand, but still not a fireable
offence.  i just hope the fucker who wrote this is not making more
than i am.


You can hope all you want, but given the other "code" that have been introduced as code examples of consultants, I bet he's got a porsche.

Re: Quantum Computering

2005-08-22 16:44 • by dubwai
41436 in reply to 41433
DisturbedSaint:
dubwai:

Jake Vinson:
You know, when I was doing classic WTF week, I wanted to repost the Paula Bean one.  That was one of my favorites ever, it just seemed too soon and people were already bitching about reposts.


This has already been posted.  Try the seach tool.




Now *that* is brilliant!

-ds


Especially the unorthodox spelling of 'search'.

Re: Quantum Computering

2005-08-22 16:45 • by George of the Jungle
41437 in reply to 41423

Anonymous:
as far as i'm concerned, the second function is perfectly valid.  -1 is a value that cannot be stored in a hex digit, and is a good way to return an error.  sure, the author was a bit daft, but i wouldn't call security to escort him out of the building if i saw it in my codebase.

the first function, on the other hand, subscribes to the theory of "if i find an error, i'll just silently introduce more errors into the data".  deserving of a reprimand, but still not a fireable offence.  i just hope the fucker who wrote this is not making more than i am.


Well, it depends on your machine.  If you were using 8 bit words -1 has hex value FF.  For  16 bit words, the value is FFFF.  For a 64 bit machine it is FFFF FFFF FFFF FFFF.  And that's just the tip of the problem.  I don't even want to go into Big vs Little Endian.  For the binary, do we know if its one's compliment or two's

Re: Quantum Computering

2005-08-22 17:22 • by dubwai
41439 in reply to 41437

Anonymous:
I don't even want to go into Big vs Little Endian.


The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

Re: Quantum Computering

2005-08-22 17:29 • by marijne
Bender: Whoa, what an awful dream. Ones and zeros everywhere. And I thought I saw a two.
Fry: It was just a dream, Bender. There's no such thing as two.

Re: Quantum Computering

2005-08-22 17:50 • by christoofar
41443 in reply to 41440
I've seen all sorts of math libraries which overcome the CPU's integer
limitation in order to process very large numbers and different
bases... precisely.



However, this string conversion crap... what useful purpose could it
*possibly* serve?  Unless maybe this is part of some sort of silly
scheme to accompish BinHex encoding?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconvertclasstobase64stringtopic.asp

Re: Quantum Computering

2005-08-22 17:51 • by rogthefrog
41444 in reply to 41437

Anonymous:
I don't even want to go into Big vs Little Endian.


Those are called "heavy endian" and "vertically challenged endian" these days.

Re: Quantum Computering

2005-08-22 17:56 • by Gene Wirchenko
41446 in reply to 41428
Anonymous:
Of course, if that were the case, I would
expect that instead of "hex2dec", the submitted code would be called
something like "hexdigit2decdigit", and then the above code would be
called "hex2dec" instead of "some_larger_routine".




How does hex digit B convert to *a* decimal digit?



If you are going to be pedantic, it is best to be correctly pedantic.  Otherwise, the effect is lost.



Sincerely,



Gene Wirchenko



Re: Quantum Computering

2005-08-22 17:56 • by dance2die
De Ja Vu?

Re: Quantum Computering

2005-08-22 18:11 • by joe_bruin
41448 in reply to 41430
dubwai:

Anonymous:
as far as i'm
concerned, the second function is perfectly valid.  -1 is a value
that cannot be stored in a hex digit, and is a good way to return an
error.  sure, the author was a bit daft, but i wouldn't call
security to escort him out of the building if i saw it in my codebase.

the
first function, on the other hand, subscribes to the theory of "if i
find an error, i'll just silently introduce more errors into the
data".  deserving of a reprimand, but still not a fireable
offence.  i just hope the fucker who wrote this is not making more
than i am.


I don't see why -1 is a better return code than 2222.  2222
cannot be stored in a hex digit either.  Perhaps from a convention
standpoint it's better but not fundamentally.





-1 is an integer.  When a function that's supposed to return a
positive integer returns a negative one, you know something went
wrong.  This is a common convention in many of the UNIX
APIs.  "2222" is a random string the guy pulled out of his
ass.  there is no sane error convention in which a random string
is returned as an error.  Why not "oh shit" or "SYNTAX
ERROR"?  Is the user supposed to guess, or must he read the code
to find all possible error return strings (I didn't happen to see any
comments).  NULL, or "", or whatever the favored VB equivalent is,
would have been the right thing to return.

Re: Quantum Computering

2005-08-22 18:28 • by nonDev

We all know the proper way to return an error is to return the exception.


nonDev

Re: Quantum Computering

2005-08-22 18:38 • by tim
How does one get a hexidecimal number outside the range of 0-F anyway?

The quantum bit -1 doesn't seem to have a pair. There's 0 and 1 but only -1. What's it's opposite? -0?

Re: Quantum Computering

2005-08-22 18:58 • by emptyset
41452 in reply to 41448

Anonymous:

Why not "oh shit" or "SYNTAX ERROR"?


ERROR: accumulator flooded.
ERROR: distracted by 0xCAFEBABE.
ERROR: i am error.
ERROR: died in the dungeons of doom, level 8.
ERROR: read/write tape jammed.


 

Re: Quantum Computering

2005-08-22 19:04 • by Andrei
This actually makes some bit of sense, if he never learned built-in functions.



In some pen-and-paper competitions, you were given problems in hex, and
such, and different conversions. Most proper methods of solution
involved drawing a quick look-up chart.

Re: Quantum Computering

2005-08-22 20:18 • by Bustaz Kool
41456 in reply to 41439
dubwai:

Anonymous:
I don't even want to go into Big vs Little Endian.


The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.



How about J.Lo Endian and Heroin Chic Endian?

Re: Quantum Computering

2005-08-22 22:28 • by Golly
41458 in reply to 41446
Gene Wirchenko:




How does hex digit B convert to *a* decimal digit?



If you are going to be pedantic, it is best to be correctly pedantic.  Otherwise, the effect is lost.



Sincerely,



Gene Wirchenko






Q:
How does hex digit B convert to *a* decimal digit?

A: Incorrectly.

Re: Quantum Computering

2005-08-22 22:36 • by ac
41459 in reply to 41456
A number's a number.

More and more, I see Java code (I know the wtf is not java but I feel
it's the same issue) where the programmer knows the String class and
treats everything as a String (ever saw the
"this|should|be|an|object|but|is|a|string" ?  .... wtf!).



PS: if the language is VB, doesn't it have libraries that handle string
representation for number (things like printf's '%x' or '%o') ?



Re: Quantum Computering

2005-08-23 00:04 • by foxyshadis
41460 in reply to 41450
Anonymous:
How does one get a hexidecimal number outside the range of 0-F anyway?

The quantum bit -1 doesn't seem to have a pair. There's 0 and 1 but only -1. What's it's opposite? -0?


IEEE something (the floating point specs) specify a positive and
negative 0, for instance, multiplying -5 by 0 is -0. In practice no one
cares.



Anonymous:
PS: if the language is VB, doesn't it have libraries that handle string
representation for number (things like printf's '%x' or '%o') ?


Indeed, in sane hands the Format() function is quite powerful.



Might as well just not return anything and get back garbage or an
exception, because you know they aren't checking. In fact, the
exception on assignment might be why it was done. God, someone teach
this guy about ord().

Re: Quantum Computering

2005-08-23 01:29 • by Drak
41463 in reply to 41460

foxyshadis:
Anonymous:
How does one get a hexidecimal number outside the range of 0-F anyway?
The quantum bit -1 doesn't seem to have a pair. There's 0 and 1 but only -1. What's it's opposite? -0?

IEEE something (the floating point specs) specify a positive and negative 0, for instance, multiplying -5 by 0 is -0. In practice no one cares.

Anonymous:
PS: if the language is VB, doesn't it have libraries that handle string representation for number (things like printf's '%x' or '%o') ?

Indeed, in sane hands the Format() function is quite powerful.

Might as well just not return anything and get back garbage or an exception, because you know they aren't checking. In fact, the exception on assignment might be why it was done. God, someone teach this guy about ord().


I believe in VB6 that you can do the following:


print CInt("&H" & strHexNumber)


Obviously that only works to 32k, otherwise you need a long. (Could also be &h, not sure, I like the 0x notation better)


Drak

Re: Quantum Computering

2005-08-23 02:59 • by Kayaman
41465 in reply to 41439
dubwai:

Anonymous:
I don't even want to go into Big vs Little Endian.


The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.



I think the preferred form is "native bytian".

Re: Quantum Computering

2005-08-23 03:04 • by NSCoder
41466 in reply to 41429
Anonymous:
Ugh. Why does the "preview" button show things as though it's html formatted, when the final post doesn't require html formatting? I think that's a WTF right there.


This has already been posted. Try the seach tool.

Re: Quantum Computering

2005-08-23 03:28 • by Fabian
41467 in reply to 41456
Bustaz Kool:
dubwai:

Anonymous:
I don't even want to go into Big vs Little Endian.


The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.



How about J.Lo Endian and Heroin Chic Endian?





But those are only the Back Endians, what about the Front Endians?

Re: Quantum Computering

2005-08-23 04:25 • by dhromed
41469 in reply to 41467
Anonymous:
Bustaz Kool:
dubwai:

Anonymous:
I don't even want to go into Big vs Little Endian.


The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.



How about J.Lo Endian and Heroin Chic Endian?





But those are only the Back Endians, what about the Front Endians?





Front Endians operate in a three-pipe output structure that allows 8
bits per pipe. In many preprocessing cases, there is an extra pipe for
another 8 bits.



The three pipes command a matrix of light sources, across which three
distinct radiation frequencies are approximately evenly spread. Each
dot in the matrix emits a level of light in accordance with the binary
number represented by the pipeline connected to it.



It's called 24-bit colour on a CRT monitor.

Re: Quantum Computering

2005-08-23 04:25 • by Welcome To The Machine
41470 in reply to 41466

NSCoder:
Anonymous:
Ugh. Why does the "preview" button show things as though it's html formatted, when the final post doesn't require html formatting? I think that's a WTF right there.
This has already been posted. Try the seach tool.


Brillant.[:P]

Re: Quantum Computering

2005-08-23 05:18 • by Toby (UK)
41472 in reply to 41470
> Why not "oh shit"



Oooo I like I like!!!!  Im gonna start using that one ... reminds
me of the alternative try/catch/finally standard I read somewhere





Try

Doh!

Woohoo!



he he :D


Re: Quantum Computering

2005-08-23 08:29 • by David
41476 in reply to 41472

Anonymous:
> Why not "oh shit"

Oooo I like I like!!!!  Im gonna start using that one ... reminds me of the alternative try/catch/finally standard I read somewhere


Try
Doh!
Woohoo!

he he :D


 


Haha, you could use varying error phrases to indicate how serious the error is.  It could vary from "Aw Darn" to "Well Crap" to "...We're boned." 


 


Hmm...I think once I ever actually program something with exceptions Im definitely gonna have to throw in a wereBonedException class. 

Re: Quantum Computering

2005-08-23 09:20 • by Caffeine
41477 in reply to 41437
Anonymous:

Anonymous:
as far as i'm
concerned, the second function is perfectly valid.  -1 is a value
that cannot be stored in a hex digit, and is a good way to return an
error.  sure, the author was a bit daft, but i wouldn't call
security to escort him out of the building if i saw it in my codebase.

the
first function, on the other hand, subscribes to the theory of "if i
find an error, i'll just silently introduce more errors into the
data".  deserving of a reprimand, but still not a fireable
offence.  i just hope the fucker who wrote this is not making more
than i am.


Well, it depends on your machine.  If you were using 8 bit
words -1 has hex value FF.  For  16 bit words, the value is
FFFF.  For a 64 bit machine it is FFFF FFFF FFFF FFFF.  And
that's just the tip of the problem.  I don't even want to go into
Big vs Little Endian.  For the binary, do we know if its one's
compliment or two's



Maybe I was sleeping through my CS lectures, but how would -1 be represented differently in big or little endian format?

Re: Quantum Computering

2005-08-23 09:24 • by Maurits
41478 in reply to 41477

Caffeine:
Maybe I was sleeping through my CS lectures, but how would -1 be represented differently in big or little endian format?


Big endian: FF FF ff ff


Little endian: ff ff FF FF


It's all in the intonation.

Re: Quantum Computering

2005-08-23 09:27 • by dhromed
41479 in reply to 41478
eFFF



Fehhhh



?

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment