Is Linq to String a Regular Expression DSL?

I was reading an old post by Phil Haack and followed the link to the Source of the famous “Now you have two problems” quote link. It got me to thinking that Linq is to objects as regular expressions are to strings… but, of course, the String class implements IEnumerable<char> (IEnumerable(of Char) for you VB-ers out there) so you can use Linq against strings inherently. Does this make Linq, when applied to a string, qualify as a regular expression DSL? A quick search for Linq to String revealed this post by Mike Hadlow. Just thinking out loud…

Advertisements

One thought on “Is Linq to String a Regular Expression DSL?

  1. Actually not really. Absolutely cool that your asking the question however as shows your insights.
     
    Regualr Expressions are a DSL. They are a ‘DSL for Language Representation via Text’ one could say as they understand things like sentence construct and other ‘language’ / ‘usage’ context.
     
    Linq is a technology we now use routinely to implement DSLs, and indeed you would be well served if you had to create a new RegEx library to use Linq (but we already have one).
     
    So your question:
     
    Is Linq to String a Regular Expression DSL?
     
    fails as that assumed two incorrect assumptions:
     
    If just for C# 3.0/Linq I would say (not perfect but a start):
     
    1) Linq to X != DSL for X
     
    2) DSL for X = (Y ) + (Linq to X)
          where Y = Domain Specific Exposed Fluent API for X +
                           Linq Provider (custom or not) for X +
                           Core Technical Framework API (.NET 3.5) Abstracted +
                           Other Vendor Offerings at any level necessary +
                           (likely) Internal Non-DSL Assets Wrapped ot Repurposed
     
    In other words,you could USE the RefEx classes indeed while APPLYING Linq to Objects where the Sequence (object) is a IEnumerable<Char> (a string). Then you could apply transforms, where clauses, etc. etc. sourcing them from the RegEx classes, but you still have Linq to Objects + Regex.
     
    Indeed this is very cool however as you STARTED with a DSL (RefEx) and now you’ve fained a vastly more powerful ‘fluent’ entry point into that DSL which you can extend to be vastly more accessible to developers. The goal of a DSL includes usability, and while true RefEx is one, it is not usable in hpw we expect today.
     
    So if you wanted to make this happen, you could :
     
    1) Write a new Linq Provider or just Wrap via Extension Methods (or a combination)
    2) In doing this you will reduce/eliminate the RegEx nasty syntax
    3) Now it’s no longer RegEx it’s a NEW DSL! You are doing the next evolution in DSLs!
     
    The next evolutions is ‘building DSLs which leverage/extend other DSLs’.
     
    Male sense? More can be found here:
     
    If you do write this it would be fantastic. Let me know as I’d love to check it out.
     
    Join the debate here.
     
    Kind Regards,
    Damon Wilder Carr
    http://blog.domaindotnet.com
     
                          
                                                 
     
                          
     

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s