Click here to Skip to main content
15,889,714 members

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, embarrassing 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: What should you do if assigning is going to crash your application? Pin
YvesDaoust1-Dec-11 2:41
YvesDaoust1-Dec-11 2:41 
GeneralRe: What should you do if assigning is going to crash your application? Pin
BobJanova1-Dec-11 5:25
BobJanova1-Dec-11 5:25 
GeneralRe: What should you do if assigning is going to crash your application? Pin
dawmail3331-Dec-11 14:53
dawmail3331-Dec-11 14:53 
GeneralRe: What should you do if assigning is going to crash your application? Pin
BobJanova2-Dec-11 0:11
BobJanova2-Dec-11 0:11 
GeneralRe: What should you do if assigning is going to crash your application? Pin
TorstenFrings2-Dec-11 0:21
TorstenFrings2-Dec-11 0:21 
GeneralRe: What should you do if assigning is going to crash your application? Pin
KP Lee2-Dec-11 21:44
KP Lee2-Dec-11 21:44 
Rant+1 -1 code patch.... or how to make my brain explode.... PinPopular
Alberto Bar-Noy28-Nov-11 1:12
Alberto Bar-Noy28-Nov-11 1:12 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee2-Dec-11 23:35
KP Lee2-Dec-11 23:35 
Nice development environment you have there. Somebody offshore can commit a change that immediately hits production without going through test environment, not bothering with code review, your offshore idiot remains hired... (You are saving $ not paying somebody local, breakdowns of your application reduces costs of running the system for no customers because it doesn't work...)
I'm not too sure about you...

Alberto Bar-Noy wrote:
yep we always go back one to check one character forward...

That's for?:

Alberto Bar-Noy wrote:
previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, count);


If caretIndex==10, count would be 8, the start of looking in the array is at 9. If text is a 5 character string, you are allowing the search to start 5 characters past the first valid index location. Same situation, except the string is 10 characters long. You can only look 1 character ahead, yet you are asking for 8, that will blow with the original error you got. (The string has to be 18 characters long or longer for that to work.)

Your statement to look only 1 character forward doesn't make sense either. Going from where you start to the end of the string makes sense to me. Why you are going back 1 character from the index passed doesn't make sense to me either. I'd want to use the last index found to find the next index to be found.

Here's an alternate version:
private TextOffsets getTextOffsets(string text, int caretIndex)
{
	var heirarchyChars = HeirarchyChars.ToArray();//one upper case to lower makes it really obvious it's new.
	var cnt = heirarchyChars.Count();//total length of the string to be searched.
	var strt = caretIndex + 1;//Point to the NEXT index's starting point
// change "+" to "-" if I'm all wet
	int NewIndex = -1;
	
	if (strt < cnt)// make sure at least ONE character is searched
	{
		NewIndex = text.LastIndexOfAny(heirarchyChars, strt, cnt - strt);
	}


Pass in 9 for the starting index for a 10 character string, cnt is 10, strt is 10, doesn't check the string at all.
Of course, since I'm perfect, Laugh | :laugh: I'll go ahead and check this in without even seeing if it will compile...
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
Alberto Bar-Noy3-Dec-11 0:57
Alberto Bar-Noy3-Dec-11 0:57 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee3-Dec-11 2:16
KP Lee3-Dec-11 2:16 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
Alberto Bar-Noy3-Dec-11 4:27
Alberto Bar-Noy3-Dec-11 4:27 
GeneralRe: +1 -1 code patch.... or how to make my brain explode.... Pin
KP Lee3-Dec-11 2:32
KP Lee3-Dec-11 2:32 
Questionzero int? Pin
b1054374821-Nov-11 12:33
b1054374821-Nov-11 12:33 
AnswerRe: zero int? Pin
CDP180221-Nov-11 23:30
CDP180221-Nov-11 23:30 
GeneralRe: zero int? Pin
Nagy Vilmos21-Nov-11 23:50
professionalNagy Vilmos21-Nov-11 23:50 
GeneralRe: zero int? Pin
CDP180221-Nov-11 23:52
CDP180221-Nov-11 23:52 
GeneralRe: zero int? Pin
KP Lee2-Dec-11 23:51
KP Lee2-Dec-11 23:51 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 2:11
harold aptroot3-Dec-11 2:11 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 3:02
KP Lee3-Dec-11 3:02 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 3:27
harold aptroot3-Dec-11 3:27 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 10:21
KP Lee3-Dec-11 10:21 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 10:42
harold aptroot3-Dec-11 10:42 
GeneralRe: zero int? Pin
KP Lee3-Dec-11 11:06
KP Lee3-Dec-11 11:06 
GeneralRe: zero int? Pin
harold aptroot3-Dec-11 11:19
harold aptroot3-Dec-11 11:19 
GeneralRe: zero int? Pin
Chris Berger22-Nov-11 8:46
Chris Berger22-Nov-11 8:46 

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

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