Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: I am in love <3 PinmemberAmgad Fahmi17-Jan-13 22:54 
GeneralRe: I am in love <3 PinmemberChris Quinn17-Jan-13 22:15 
GeneralRe: I am in love <3 PinmemberPIEBALDconsult17-Jan-13 13:43 
QuestionRe: I am in love <3 PinmemberGuirec Le Bars17-Jan-13 15:15 
GeneralRe: I am in love <3 PinmemberPIEBALDconsult17-Jan-13 18:17 
AnswerRe: I am in love <3 PinmemberAmgad Fahmi17-Jan-13 22:56 
GeneralRe: I am in love <3 Pinmemberdeepakaitr1234522-Jan-13 3:08 
GeneralReversing time, without a flux capacitor PinmemberGary R. Wheeler17-Jan-13 5:03 
Our C# application uses TCP/IP sockets for interprocess communication. I use the Socket class asynchronous methods to process received messages, something like this:
// start initial receive operation
s.BeginReceive(...,OnReceive);
...
void OnReceive(...)
{
   lock(...)
   {
       // fetch incoming message
       ...
       // start next receive operation
       s.BeginReceive(...,OnReceive)
   }
   // process received message outside of lock to avoid holding it for a long time
   ...
}
I discovered that the OnReceive was being called recursively under heavy traffic conditions, resulting in messages being processed in reverse order for brief periods D'Oh! | :doh: Sigh | :sigh: . The solution went something like this:
// start initial receive operation
s.BeginReceive(...,OnReceive);
...
void OnReceive(...)
{
   lock(...)
   {
       // fetch incoming message
       ...
   }
   // process received message outside of lock to avoid holding it for a long time
   ...
   // start next receive operation
   s.BeginReceive(...,OnReceive)
}
The time-reversing version has been in the product since 2008, and I only discovered it a week ago. One petard-wedgie, coming up.
Software Zen: delete this;

GeneralRe: Reversing time, without a flux capacitor PinmemberLloyd Atkinson17-Jan-13 6:57 
GeneralRe: Reversing time, without a flux capacitor PinmemberGary R. Wheeler17-Jan-13 10:25 
GeneralRe: Reversing time, without a flux capacitor PinmemberLloyd Atkinson17-Jan-13 12:40 
GeneralRe: Reversing time, without a flux capacitor PinmemberBobJanova21-Jan-13 5:52 
GeneralRe: Reversing time, without a flux capacitor PinmemberBrisingr Aerowing17-Jan-13 15:25 
GeneralRe: Reversing time, without a flux capacitor PinmemberBobJanova21-Jan-13 5:56 
GeneralRe: Reversing time, without a flux capacitor Pinmemberenglebart23-Jan-13 4:35 
GeneralRe: Reversing time, without a flux capacitor PinmemberGary R. Wheeler23-Jan-13 12:45 
GeneralRe: Reversing time, without a flux capacitor PinmemberMember 793197823-Jan-13 6:44 
GeneralRe: Reversing time, without a flux capacitor PinmemberGary R. Wheeler23-Jan-13 12:58 
JokeRe: Reversing time, without a flux capacitor PinmemberRafagaX23-Jan-13 7:21 
GeneralRe: Reversing time, without a flux capacitor PinmemberPaulo Zemek23-Jan-13 8:37 
GeneralRe: Reversing time, without a flux capacitor PinmemberJonathan C Dickinson3-Feb-13 23:47 
GeneralThe best refactoring I have ever seen Pinmembermatt_taws17-Jan-13 2:29 
GeneralRe: The best refactoring I have ever seen PinmemberSuper Lloyd17-Jan-13 3:42 
GeneralRe: The best refactoring I have ever seen PinmemberJonathan C Dickinson17-Jan-13 4:22 
GeneralRe: The best refactoring I have ever seen PinmemberPIEBALDconsult17-Jan-13 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 23 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid