| « Prev | Page 1 | Next » |
|
The division algorithm is absolutely beautiful.
|
|
throw-ing has GOT to be faster than return-ing, right?
|
|
Well... I really miss ASM programming times :(
|
|
Of course it's faster. For every method that gets called, you save a whole return operation.
captcha: smaile :-) |
|
Egads!
Nice work. Although not nearly enough exception abuse for my tastes. Given that C++ supports exceptions, I'd be surprised if there wasn't at least one entry that introduces the wonderful paradigm of "exceptional programming". |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 13:46
•
by
Welbog
|
Why thank you. I hope you guys enjoy reading my code as much as I enjoyed writing it. This contest is a lot of fun and I can't wait to see the rest of the entries. |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 13:53
•
by
Look at me! I'm on the internets
(unregistered)
|
|
Well, even if it doesn't win, It should get an honourable mention for Best Comment:
This algorithm is pre-optimized so as to not confuse the compiler. |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 14:01
•
by
%USERNAME%
(unregistered)
|
|
That's the first of the entries which I'm looking at, and it's cute. I especially like the version number of the documentation. I am just wondering whether the next version will be "Err+1" or "Err^2".
|
|
CAPTCHA: tastey.
It sucks to install a captcha remover that doesn't work. |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 14:24
•
by
Foobar
(unregistered)
|
|
CAPTCHA: Testing
Ninjas? |
|
If the programmer was REALLY talented, he'd have used recursive exceptions!
CAPTCHA: riaa. And I'm listening to Internet radio... |
|
Ah! Returning values by throwing, that's clever. It also supports dynamic typing, unlike return! E.g. a function can have variant return types by throwing them instead of using the return keyword. Something like:
try { GetValue(); } catch(int i) { /* int was returned */ } catch(string s) { /* string was returned */ } ... I will definitely start replacing all my returns with throws in my future projects. |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 15:11
•
by
SomeCoder
(unregistered)
|
Oh dear god! The pain! My eyes! The goggles do nothing! :) |
|
I love this so much!
The savings of layerjumping and the namespace mumbo jumbo is encredible. |
Then i guess all those ExceptionHandlers (one for each function!) and stack unwinding are faster than returning. Come on! As everybody knows, you must pass the result via a global variable. You're encouraged to have a doeen an decide on which one should the result be stored based on a dice, you never know if the memory position where you store results get corrupted. Easier than adding mathematical coprocessors, computers should provide some fast-access memory for this variables, something called Earning Access Xpeed or abbreviated, EAX. Ah, and for unwiding, you simply set the stack to 0 and manually set EIP. Why throw something when you can JUMP? |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-05 17:46
•
by
dkf
(unregistered)
|
Only in threaded code... |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-06 18:27
•
by
bill
(unregistered)
|
|
I especially like the last 4 lines of the division function:
a 25 char buffer because obviously a number cannot be more than 25 chars long; sprintf with a conditional statement inside it for the special case of having a remainder (and a remainder doesn't appear to actually be a remainder, but rather a fractional part; that, according to the comment documentation, can only be one digit long) throwing the return value unreachable code that would throw an ERROR. |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-07 06:40
•
by
Welbog
|
|
The remainder can be more than one digit long if you use #define TEN 100 instead of #define TEN 10. The logarithm of TEN base 10 is the number of decimal places it can print. The trouble is #defining TEN to anything other than 10 results in incredibly slow division. It has the added bonus of giving a non-base-10 decimal result if you set it to something other than a power of 10.
And I'm sad that, of all the entries currently presented, mine has the fewest comments. :( |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-10 15:02
•
by
miraculix.x
(unregistered)
|
|
throw-ing certainly is NOT faster than return-ing. Consider that for every throw-operation the compiler has to ensure the stack gets cleaned up. In fact, any code block with exception handling in it will cause additional epilog / prolog code to register/handle any throw and catch blocks. At the end that means more statements to execute, less efficiency. some stuff to read: http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx http://www.nwcpp.org/Downloads/2006/ehc.ppt http://www.codeproject.com/cpp/exceptionhandler.asp |
Re: OMGWTF Finalist #04: TerseCalc
2007-06-12 05:39
•
by
Mania
(unregistered)
|
|
Miraculix, apparently you missed some lectures on exceptions. Whilst it is *not* recommended to use as an alternative to returning in the general case, in exceptional cases it *is* recommended.
Your links state this exactly. An exceptional circumstance would be for a function designed to be recursively called hundreds of levels deep, to actually return without calling itself again. Also, by the very fact that you've arrived at the end shows that an exception hasn't been raised recently. This is easily proved through mathematical induction. Now what's the quickest way to return from this deep nest, once you've got your result? To throw an exception clearly. Yes, more work has to be done then a simple ret and stackptr--, but if you can skip past hundreds of these simple rets by a throw, it's bound to be quicker. Your code becomes more readable, it's faster, and it employs generally accepted programming principles. |
Re: OMGWTF Finalist #04: TerseCalc
2009-07-22 11:27
•
by
A-Nona-Mouse
(unregistered)
|
|
Actually I HAVE seen this in production code!!!!!
|
Re: OMGWTF Finalist #04: TerseCalc
2011-03-25 16:46
•
by
tharpa
|
miraculix, i think you must be a newbie here. |
| « Prev | Page 1 | Next » |