Archives
- ⺠2013 (8)
- ⺠2012 (35)
- ⺠2011 (157)
- ⺠2010 (174)
- ⺠2009 (12)
Which topics would you like us to cover more?
Latest comments
-
How to create an application s...
Maybe some of the other posts will help you too: d...
By Bas -
How to create an application s...
Hi Joe! Glad this post and the discussion is helpf...
By Bas -
How to create an application s...
Ok, I think I'm getting my head around it now... t...
By Joe -
How to create an application s...
this is probably the most helpful discussion ive c...
By Joe -
How to shutdown your server wi...
IT didn't work with centos 6
By David -
How to reset you Kindle 3, eve...
Thank you! I was in the middle of listening to a b...
By Madison Woods -
Using a client certificate wit...
Thanks Bas
By betsy -
Using a client certificate wit...
Hi Betsy, No there isn't. Java runs in a virtual m...
By Bas
Latest tweets
about 1 day ago
Noscript and fritz.box #dib0 http://t.co/zxHEedNf9Q
about 8 days ago
Social engineering from India #dib0 http://t.co/ajjp43WkVS
about 17 days ago
@unwoman Got the kickstarter Uncovered Vol. 2 today! Thank you! I love it! http://t.co/x0Tzovtq8u
about 19 days ago
A query is running #dib0 http://t.co/cRZ8Dd3nVp
15 Apr 2013
Locally save attachments from Oulook using VBScript #dib0 http://t.co/l6RhWQsvFL
1 Apr 2013
Publishing Outlook calendar for use in Google calendar through http://t.co/sfh5eNxGXM #dib0 http://t.co/IzWNPlaqNA
21 Mar 2013
http://t.co/j3B0kSLGkM Really interesting article. The church of pirates. Gods preferential option for the poor in the broadest sense.
14 Mar 2013
Happy Pi-day! And this is what's wrong with it... funny, but true. http://t.co/A8GIB8fugC
14 Mar 2013
Hey guys @piwik ! Just looking at my site stats. I love the new page overlay feature. Well done! :-)
3 Mar 2013
Really funny! The Burning Hearts Revolution: How Sesame Street is Undermining Biblical Values http://t.co/z8XFk5P4d3
26 Feb 2013
Recursively check and correct mp3 files in Linux #dib0 http://t.co/U3nzOuWzWM
26 Feb 2013
Haha! Met zo'n antwoord een terechte reactie! http://t.co/NYXIb27aP5 via @snippers
20 Feb 2013
Create random password with C#, Java and PHP #dib0 http://t.co/WgF7DtcT
| Are break-statements (in Java and .Net) as bad as taught to me? |
| Written by Division by Zero |
| Thursday, 31 December 2009 15:17 |
|
Back in my days as a student I learned tha using the break statement is bad programming. Of course using the break statement within a switch statement is an exception to this rule. Since then I became a C# developer and I come across a lot of break statements in code of other developers. After a lot of (fun and usefull) discussion about this, it's time to put it to the test.
One of the reasons why it's a bad coding practice is that the break statement messes up the the branch prediction of the processor. While this is probably true for languages like C++, the question is if it is true for Java and C#, which are not directly compiled to assembly. I used these two methods to test if a break statement is actually slower than not using a break. Compiled to IL code these methods look like this. So the foreach and the break statements generate more IL code, but this says nothing about the performance of the code. After running the methods a few thousend times and calculating the average execution time, the method with break took an average of 0.04 milliseconds and the method without the break took 0.088 milliseconds. So... the break is faster, so the branch prediction argument doesn't hold. Are there more arguments for not using the break statement? Actually, none that I can think of. It's a readable statement (if the rest of the code is readable!). I stand corrected! |
The right word may be effective, but no word was ever as effective as a rightly timed pause. - Mark Twain













