Monday, 13 September 2010

Sin Citi

It started out harmlessly enough…

I wanted to make a payment to my credit card.

When I tried to add a payment, though, the website responded in large red print with the message of:

You are permitted 4 online payments per billing cycle. You have already made 4 payments totaling 315.55 this billing cycle.

Surely, this was an oversight… Perhaps, it was even the result of a programmer with good intentions who had never actually USED a credit card before. Who knows…

Unable to consider any scenario where this would be considered a good business decision, I contacted their online Customer Support staff to find out the scoop.

The next day, I received the following response:

We appreciate your inquiry and regret any inconvenience you may have experienced.

I am sorry but the computer only allows 4 payments in a billing cycle as stated on the website.

To make additional payments you can call customer service, mail a payment or set up billpay through your bank.

That made me feel better… Obviously, it’s “the computer” that is to blame… Wait… what?!?!?

So let me get this straight…

Citi’s systems can handle receiving more than 4 payments within a billing cycle, since — as their message said — additional payments can be made through customer service, postal mail, and bank bill payment systems.

Since that’s the case, there’s obviously no business or system reason behind not being able to accept more than four payments in a single billing cycle.

This means someone made a conscious decision to limit the website’s ability to handle this — a limitation not found ANYWHERE else in Citi’s practices or, really, in another other credit card company, as far as I know.

I know, I know… I don’t have the best track-record with credit card companies… I left American Express simply because I didn’t like their password security rules (maximum of 8 characters, guys…? Really?), but at least I could make as many payments to them as I wanted… But I really think this is absolutely asinine on their part.

The second response I got was:

Only 4 payments can be made in a statement period and the total of all payments cannot exceed the account balance due to system constraints. This is to ensure proper storage capacity and the ability to fulfill your payment requests.

Haha. This just gets better and better… ;)

Entertainingly, I also received the following Twitter response a few days later:

Sorry for ur experience. Another option would be to process no fee pmts via automated ph system. If u still have ?s let us know

I understand there’s a character limit, but that was just painful…

I suppose I’ll just need to give-in, set up a Bill Pay account for them on my bank, and move on to bigger and better issues.

Still, I really hope this is something Citi addresses at some point soon. Given how hard it is for businesses to keep users on their sites these days, it’s amazing anyone would go out of their way to limit their user’s online abilities in favor of having them go elsewhere to complete their tasks.

Monday, 12 July 2010

XNABEE

A friend of mine made his first open source project on Codeplex, XNABEE.

He uses a tool from Microsoft called XNA for making DirectX-based games.

For basic effects on lighting, textures, etc., you have to make a change, recompile, and see if it was what you wanted. Major pain.

He made an external tool that lets folks import in the object and then adjust all of the BasicEffect settings in real-time.

When the user gets it how they want, they can save all of the properties and throw it back into XDA.

Sunday, 13 June 2010

C-Sharp. C-Sharp Run.

I HATE OLD VB!

A pet-peeve of mine is when I work on code that written with legacy VB6-style methods and functions rather than the more current .NET versions.

Is there a huge performance penalty between calling Len() on a string versus .Length and that sort of thing? Not really. I mean, I’m sure there probably is on some level, but nothing a user is likely to notice in an average application.

My big gripe is that by forcing yourself to use what’s in the framework only, you can sometimes find better ways of doing things.

The best example for that I can give is the use of IsNumeric(). In applications I’ve worked on, I’ve often seen code where the validation of a textbox (for the input of an order number, for instance) uses IsNumeric to check to see if the number is valid and then will blindly set the value of a variable, parameter, etc. to it that is an Integer, a Long, or whatever.

For this example, let’s assume that the order number field is an Integer.

Here are a few inputs that pass the IsNumeric() test:

  • 5
  • -5
  • +5
  • $5
  • 5.5
  • 2147483648
  • The first three are mathematically valid, so let’s ignore those for now. I rather not accept leading + or – characters unless we are working with values that can legitimately be negative or positive.

    The last three items on the list are a bit more interesting, though.

    In strict terms, “$5” isn’t a valid number. If we explicitly cast it to an integer with CInt(), it’s smart enough to trim off the dollar-sign, but is that what you want? Call me old-fashioned, but I like predictability… If I have a field that only is meant for numbers, it shouldn’t work if I throw in something that isn’t a number.

    With “5.5”, it’s clearly not an integer. If the code simply checks the input against IsNumeric() and then runs CInt(), it will round the value up to 6. Assuming it was a legitimate typo, if the user attempted to search for order 55 and got back order 6, it might lead to confusion. It’s better to err on the side of caution up front, having them fix the input before searching again.

    Lastly, there’s a search for “2147483648”, which is one digit higher than the maximum size an integer data-type can be. It will pass the IsNumeric() test, but will cause an overflow when CInt() is attempted. Not good. Unless you have pretty robust exception-handling (and I don’t mean just tossing everything into a Try/Catch block), this can either result in unexpected behaviors within the app or, more often, user-facing errors that aren’t easy for them to understand.

    The alternative solution to the above scenario is to use Integer.TryParse() With that method, you’re not only evaluating the string value to see whether it can be converted to an integer, but (assuming it can be converted and you passed in a variable as the second parameter instead of Nothing) it also does the conversion for you. With the above list of inputs, the only ones that pass the Integer.TryParse() method are the first three. And, again, if I wanted to be even more picky, I could reject the + or – prefixed input for maximum consistency.

    Regular-expressions might be good for an initial validation pass, I guess, but that’s a whole other topic…

    Ok, great, but so what…?

    What does this all have to do with C#? Very little… I just wanted to explain my motivations for wanting to prevent some of this stuff from finding its way into new code and to identify legacy implementations that probably need cleaned up. It’s not just IsNumeric() that I have an issue with, it’s also IsDate(), which can be easily handled through Date.TryParse, UCase, Len, Space, Left, Right, Mid, InStr, MsgBox, Format, Replace, LikeString, etc., etc., etc.

    I needed to identify where in the code these were being called, but it should be done in such a way as to allow me to make exceptions when needed and to differentiate between the Good, Bad, and the Ugly of VB calls…

    For that, I needed FxCop…

    That is where the C# stuff came in.

    Aside from there not seeming to be any (at least not useful) official documentation on FxCop, I had to rely on third-party examples. Once I got over the initial issues of using the newest version of FxCop with samples code made for old versions of it, I eventually got the gist of what was being done.

    To make a custom FxCop rule required me to make a C# library DLL with the various introspection rules. It also needed an XML file saved as an embedded resource, which wasn’t too involved.

    Really, the hardest part of writing the custom rules was figuring out how the introspection was evaluating the code and, more importantly, what I needed to change in order for it to evaluate what I wanted.

    My goal was simple enough. For starters, just show everything that referenced the Microsoft.VisualBasic namespace. Once I got that working, I’d figure out how to narrow it down just to the stuff that I wanted to no longer use in new code.

    I’m still tweaking it a bit, but I finally got it working (mostly) the way I want. I go within the MethodCall and examine the Method’s DeclaringType.FullName… If it starts with “Microsoft.VisualBasic”, I know I’m on the right track… There are a couple namespaces that I exclude right off the bat (like “Microsoft.VisualBasic.CompilerServices.Conversions” and “Microsoft.VisualBasic.CompilerServices.ProjectData”). Otherwise, I call a custom routine of mine that categorizes the call into a few different rule categorizes I came up with.

    To categorize the call, I use a combination of the method’s namespace as well as GetUnmangledNameWithoutTypeParameters(true)

    Everything In Its Place

    I came up with four categorizes:

  • Unknown -- Anything that isn't explicitly assigned to one of the following three categories by this routine
  • Allowed -- Anything that is something that there isn't a good alternative for in the .NET framework or isn't worth tackling just yet
  • LegacyVB -- Methods and routines that there are better .NET alternatives to (e.g. Len, MsgBox, InStr, Replace, UCase, etc.)
  • ConsiderAlternative -- Methods and routines that might be better suited for native .NET methodology (e.g. DateAdd, IsNumeric, IsDate, etc.)
  • This seemed to do the trick. I could now analyze any project I was working with an see how many calls were using “the old way”

    Ultimately, it came down being more of a conversation starter than anything else.

    Some calls, like with those to MsgBox, were brought over from older code, while all of the new code was written using the .NET Framework alternatives. Other times, there were calls even in the new code being made because no one had realized there were other (better?) ways of doing the same thing.

    For more, the call I used a lot, but hadn’t realized there was an alternative to was IsNothing() I’ve slowly been trying to break my habit, if for no other reason than it’s so much easier to read “If SomeValue Is Not Nothing” rather than “If Not IsNothing(SomeValue)”. It’s a subtle difference when writing it, but more of a value when it’s being read (especially by someone else).

    Ultimately…

    I enjoyed learning and working with C# a bit. I still think case-sensitivity is retarded, but there’s a lot about C# that I started to get used to really quickly.

    I don’t know, I’ll probably do a few more small projects with it and see how it goes.

    Tuesday, 16 March 2010

    Problem 019

    You are given the following information, but you may prefer to do some research for yourself.

    * 1 Jan 1900 was a Monday.
    * Thirty days has September,
    April, June and November.
    All the rest have thirty-one,
    Saving February alone,
    Which has twenty-eight, rain or shine.
    And on leap years, twenty-nine.
    * A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.

    How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

    Solution:
    Function Prob019() As Long
    Dim dt As Date = CDate("01/01/1901")
    While dt < = CDate("12/31/2000") If dt.DayOfWeek = System.DayOfWeek.Sunday Then Prob019 += 1 dt = dt.AddMonths(1) End While End Function

    Summary:
    I'm not above cheating by using built-in functions ;)

    Problem 014

    The following iterative sequence is defined for the set of positive integers:

    n → n/2 (n is even)
    n → 3n + 1 (n is odd)

    Using the rule above and starting with 13, we generate the following sequence:
    13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

    It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.

    Which starting number, under one million, produces the longest chain?

    NOTE: Once the chain starts the terms are allowed to go above one million.

    Solution:
    Function Prob014() As Long
    Prob014 = 0
    Dim NumWithLargestChain As Long = 0
    Dim ChainCount As Long = 0
    For StartNumber As Long = 999999 To 1 Step -1
    Dim tmpNum As Long = StartNumber
    Dim tmpCount As Long = 0
    Do
    tmpCount += 1
    If tmpCount > ChainCount Then
    ChainCount = tmpCount
    NumWithLargestChain = StartNumber
    End If
    If tmpNum = 1 Then Exit Do
    If tmpNum Mod 2 = 0 Then
    tmpNum = tmpNum / 2
    Else
    tmpNum = (tmpNum * 3) + 1
    End If
    Loop
    Next
    Return NumWithLargestChain
    End Function

    Summary:
    Thankfully, this was a lot easier than the previous problem I did. I skipped problem 12 and 13, but I’ll probably come back to them at some point. Problem 12 dealt with triangle numbers, which I’m not really familiar with. Problem 13 dealt with adding up a hundred 50-digit numbers, which seems like it would be easy, but I either would need a crazy-big numeric datatype or I’d need to come up with a new way to add the stuff up through some other fashion.