- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The division algorithm is absolutely beautiful.
Admin
throw-ing has GOT to be faster than return-ing, right?
Admin
Well... I really miss ASM programming times :(
Admin
Of course it's faster. For every method that gets called, you save a whole return operation.
captcha: smaile :-)
Admin
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".
Admin
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.
Admin
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.
Admin
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".
Admin
CAPTCHA: tastey.
It sucks to install a captcha remover that doesn't work.
Admin
CAPTCHA: Testing
Ninjas?
Admin
If the programmer was REALLY talented, he'd have used recursive exceptions!
CAPTCHA: riaa. And I'm listening to Internet radio...
Admin
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.
Admin
Oh dear god! The pain! My eyes! The goggles do nothing!
:)
Admin
I love this so much! The savings of layerjumping and the namespace mumbo jumbo is encredible.
Admin
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?
Admin
Admin
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.
Admin
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. :(
Admin
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
Admin
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.
Admin
Actually I HAVE seen this in production code!!!!!
Admin
miraculix, i think you must be a newbie here.