gregbeech


Comments:

Using the Luhn algorithm to validate credit cards

posted by gregbeechgregbeech(76) 4 years, 1 month ago 0

Well really the best way to do it is with both regex and Luhn validation. Also, the fastest way to add up digits in a number is to use modulus-9, not to convert to a string then walking the chars converting them as you go...

Reply

Using Interlocked to allow a single thread access to a resoure.

posted by gregbeechgregbeech(76) 3 years, 11 months ago 0

You might also want to check out Jeffrey Richter's SpinWaitLock which is a more complete implementation of the same concept (with the required things such as Begin/EndCriticalRegion calls): http://msdn.microsoft.com/en-us/magazine/cc163726.aspx

Reply

IIF equivalent in C#

posted by gregbeechgregbeech(76) 3 years, 11 months ago 0

Actually the C# ternary operator isn't equivalent to IIF in VB, because the IIF function always evaluates both the true and false actions, whereas the ?: operator is a lazily evaluated left-associative operator which only associates the appropriate action. e.g. IIf(a IsNot Nothing, a.ToLower(), String.Empty) will throw a NullReferenceException in VB if a is null because it will try to evaluate a.ToLower() anyway, whereas a != null ? a.ToLower() : string.Empty will not throw in C#. The C# ternary operator didn't have an equivalent in VB until VB9, where you can now write the rather confusing If(a IsNot Nothing, a.ToLower(), String.Empty).

Reply

.NET Synchronised Dictionary

posted by gregbeechgregbeech(76) 3 years, 11 months ago 0

It's not actually thread-safe though:

if (dictionary.ContainsKey(someKey))
{
var value = dictionary[someKey]; // could throw as the key has been removed by another thread after the check
}

This is why the SyncRoot property was removed from the collections in the first place, because it was synchronising at too low a level. A thread-safe version would not have either of those APIs, and would instead implement something like

bool dictionary.TryGetValue(out TValue value);

Reply

ADO .NET Entity Framework Vote of No Confidence

posted by gregbeechgregbeech(76) 3 years, 11 months ago 0

Saying "experts in entity-based applications" is like saying "experts in doing things fundamentally wrong". Any ORM framework is inappropriate for complex projects, not just EF. It will be absolutely fine for the audience ORM is aimed at, i.e. former Access developers. Vote of no confidence? Sure, for any complex project. But no more than any other ORM.

Reply

A Money Type for the CLR

posted by gregbeechgregbeech(76) 3 years, 9 months ago 0

Main problem with this article is summed up in the extract below:

"In this type, I kept the integral value storage, but opted to represent the fraction as a completely separate Int32, which is scaled by 10^9 (the largest power of 10 which fits into an Int32). [...] Another alternative was to represent the money value with a System.Decimal. The problem with this approach is that System.Decimal is a binary floating-point type, and binary floating-point types give us all sorts of headaches when computing with them and not treating the round-off or computational error accumulation with extreme care."

Um... except System.Decimal *isn't* a floating-point type, it's a scaled integer; from MSDN:

"The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28."

Reply

Hitchhikers Guide To ALT.NET

posted by gregbeechgregbeech(76) 3 years, 6 months ago 0

Hmm I think the article is somewhat biased though

> the folks that are coalescing around the concept of ALT.NET are the leading minds in your professional peer group

Loudest and most opinionated quite possibly, but there's far too much of a cargo cult around things like ORM, TDD, Agile, etc. in the ALT.NET space to describe them as the leading minds.

Reply

Simple Password Encryption Program

posted by gregbeechgregbeech(76) 3 years, 3 months ago 0

Encryption??? That's barely secure enough to be classed as obfuscation!

Reply

Rarely used C# Keywords

posted by gregbeechgregbeech(76) 3 years ago 0

Rarely used?? The "using" keyword should be used frequently by anybody dealing with disposable resources. And the rest aren't even keywords: (yield is a contextual keyword, which anyone using a functional style will use frequently, ?? is an operator, @ is syntax, and ForEach is a method!

Reply

A field agent's law enforcement application enabled for web

posted by gregbeechgregbeech(76) 2 years, 10 months ago 0

LOL yeah I'm sure the problems were caused by the ASP.NET framework... not.

Reply

TFS Sucks, here is a list why

posted by gregbeechgregbeech(76) 2 years, 8 months ago 0

This is mostly just a rant from somebody who doesn't understand how TFS works. May as well just have called it "TFS isn't Subversion and I don't like it because of that". It doesn't even touch on the points that are important in a source control system such as branching/merging (excellent) change tracking (excellent, even for renamed files etc) and reliability (we've been using it for years with no major issues). Yes, there are some annoyances, and it's by no means perfect, but this article doesn't really cut it.

Reply

URL Encryption in ASP.NET

posted by gregbeechgregbeech(76) 2 years, 4 months ago 0

Using encrypted query strings as any form of 'security' is just a joke. Security by obscurity is no security at all; just the illusion of it. Access to private pages should be controlled by proper security based on the principal, not using this kind of obfuscation technique which is trivially subverted.

Reply

Writing Efficient String Functions in C#

posted by gregbeechgregbeech(76) 2 years, 3 months ago 0

Wow, that's one of the most incorrect articles I've ever read. The author clearly has no real idea about how memory allocation works (value types are not stored on the stack, they are stored inline, so they will be on the heap if they are stored in a reference type such as an array) and has clearly never heard of StringBuilder which is rather important if you want to write efficient string functions.

Reply

CompletIT with a New Website Done Entirely in Silverlight

posted by gregbeechgregbeech(76) 1 year, 11 months ago 0

It's a great example of how *not* to build a website anyway... took 19.7 seconds to download and show the front page on my company's 100Mbps connection. Most users would be gone at least 15 seconds before that.

Reply