+1 -1 code patch.... or how to make my brain explode....
-
Consider a text box with auto complete checking for the existence of the char . or [ Brilliant outsource developer sitting far far away writes the following:
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; if (caretIndex > 0) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, caretIndex); }
...
And of course commits the change... 10 minutes after update contracts kick-in in run time and
ContractException was unhandled
Precondition failed: this == String.Empty || startIndex - count >= 0Then I go :mad::mad::mad: Update and get this
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; try { if (caretIndex > 0) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, caretIndex); } } catch (Exception x) { }
...
Absolutely brilliant. Let's not fix it.. let's circumvent it... :wtf: :wtf: By this time curses in Greek are being launched... Next day update and...
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; int count = caretIndex - 2; if (caretIndex > 0 && count > 0 ) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, count); }
...
:doh: :doh: what the... Pen and paper just to make sure I am not hallucinating... yep we always go back one to check one character forward... Also we have an innovation... one would start an expression for a struct or an array with a . or a [ from position 0 without a variable first. Just brilliant... :wtf: :wtf: Oh well... it should at least be...
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; if (caretIndex > 1) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, 1); }
...
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)
-
Consider a text box with auto complete checking for the existence of the char . or [ Brilliant outsource developer sitting far far away writes the following:
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; if (caretIndex > 0) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, caretIndex); }
...
And of course commits the change... 10 minutes after update contracts kick-in in run time and
ContractException was unhandled
Precondition failed: this == String.Empty || startIndex - count >= 0Then I go :mad::mad::mad: Update and get this
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; try { if (caretIndex > 0) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, caretIndex); } } catch (Exception x) { }
...
Absolutely brilliant. Let's not fix it.. let's circumvent it... :wtf: :wtf: By this time curses in Greek are being launched... Next day update and...
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; int count = caretIndex - 2; if (caretIndex > 0 && count > 0 ) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, count); }
...
:doh: :doh: what the... Pen and paper just to make sure I am not hallucinating... yep we always go back one to check one character forward... Also we have an innovation... one would start an expression for a struct or an array with a . or a [ from position 0 without a variable first. Just brilliant... :wtf: :wtf: Oh well... it should at least be...
private TextOffsets getTextOffsets(string text, int caretIndex)
{
var heirarchyChars = HeirarchyChars.ToArray();int previousSeparatorOffset = -1; if (caretIndex > 1) { previousSeparatorOffset = text.LastIndexOfAny(heirarchyChars, caretIndex - 1, 1); }
...
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)
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: I'll go ahead and check this in without even seeing if it will compile...
-
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: I'll go ahead and check this in without even seeing if it will compile...
well this code never reached production' This is what I was hired for... to kick them out. This code tries to check if the last character typed was . or [ this is an autocomplete for structs and arrays on a PLC Dev. system's only the last char needs to be checked. And in WPF the caret position is after the last character. Finally because of politics (they got their notice so they are still around till Jan. first and I can't fully touch their code.
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)
-
well this code never reached production' This is what I was hired for... to kick them out. This code tries to check if the last character typed was . or [ this is an autocomplete for structs and arrays on a PLC Dev. system's only the last char needs to be checked. And in WPF the caret position is after the last character. Finally because of politics (they got their notice so they are still around till Jan. first and I can't fully touch their code.
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)
Why pass an index field at all? Get the count, subtract 1, use that as the first integer and 1 as your second. If you can't get rid of the field, ignore it and do the same thing. Don't know enough about WPF, but a string is a string and the caret is either the last character, earlier than the last, or doesn't exist in the string.
-
well this code never reached production' This is what I was hired for... to kick them out. This code tries to check if the last character typed was . or [ this is an autocomplete for structs and arrays on a PLC Dev. system's only the last char needs to be checked. And in WPF the caret position is after the last character. Finally because of politics (they got their notice so they are still around till Jan. first and I can't fully touch their code.
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)
-
Why pass an index field at all? Get the count, subtract 1, use that as the first integer and 1 as your second. If you can't get rid of the field, ignore it and do the same thing. Don't know enough about WPF, but a string is a string and the caret is either the last character, earlier than the last, or doesn't exist in the string.
I know! Politics! I can't touch it yet :-(
Alberto Bar-Noy --------------- “The city’s central computer told you? R2D2, you know better than to trust a strange computer!” (C3PO)