The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,575 other followers

which kind of IsHex() function do you like most, and why?

Posted by jpluimers on 2012/07/10

Though the sample question is in C#, it applies to almost any language and framework: for relatively simple checks like IsHex(), you can go the RegEx way, or the compound if-statement way.

Which kind of function do you like most?

I’m not only interested in the percentages, so let me know in the comments why.


PS: if you want to use RegEx in .NET, you can compile them to IL, but be very cautious for the compilation overhead.

8 Responses to “which kind of IsHex() function do you like most, and why?”

  1. WarrenP said

    The gratuituous use of Regular Expressions should get you banished from Delphi land, and you should be forced to write everything for 5 years using Perl, or PHP, the two scripting languages I abhor most.


  2. Eric said

    RegEx saves typing, but that’s about the only thing going for it in that case.

    And if the languages supports “in” like Pascal does, then the RegEx doesn’t save very much code.

    for c in str do
    if not c in [‘0’..’9′, ‘a’..’f’, ‘A’..’F’] then Exit(False)

  3. What Danny said. :)

  4. If expressions over regex. Two reasons: discrete logic is easier to debug than regex codes, and you don’t need monster truck to cross a street. Regex is overkill.

    • Dk said

      all said.

    • Jacob said

      Long before there were programmers, carpenters have said “When all you have is a hammer, everything looks like a nail.”

      Somehow, for programmers, regular expressions have become the hammer.

      • jpluimers said

        You nailed it (:

        I was wondering why so many answers on stackoverflow, newsgroups, etc include RegEx even for things that can be done in a simple if/then or case/switch way.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: