The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

    • RT @nadineswagerman: Iemand mailde me dat een 13-jarig meisje mijn novelle had uitgekozen om te lezen/bespreken op school. Het boek bevat 9… 3 hours ago
    • RT @jilles_com: Afgelopen 10 dagen hebben we door NL gereisd, elke dag een nieuw hotel en op heel veel locaties gegeten. In 60% van de geva… 3 hours ago
    • RT @FTM_nl: Sywert van Lienden plaatste bewust een serie tweets om het ministerie onder druk te zetten om de omstreden mondkapjesdeal met h… 4 hours ago
    • RT @ArmsControlWonk: China just used a rocket to put a space plane in orbit and the space plane glided back to earth. Orbital bombardment i… 4 hours ago
    • RT @shossontwits: O jee. Nu dit weer. 4 hours ago
  • 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,482 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.

–jeroen

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.

    W

  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)
    Result:=True;

  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:

WordPress.com Logo

You are commenting using your WordPress.com 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: