# Embracing Languages Inside Languages

**URL:** <https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443>\
**Category:** blog\
**Created:** [October 30, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443 "2007-10-30T00:00:00Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![JoshuaF](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/j/7993a0/32.png) [@JoshuaF](https://discourse.codinghorror.com/u/JoshuaF)\
**Post date:** [October 31, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/101 "2007-10-31T00:00:00Z")

</div>

Wow, I should have re-read that last comment before posting it. It comes across a lot “snippier” than I like. Here’s the same comment without the attitude:  
I agree that programmers that are using regular expressions should learn regular expression syntax.  
I do not agree that solves the problem of them being hard to read.

---

<div class="post-metadata">

**Author:** ![Steve](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/f19dbf/32.png) [@Steve](https://discourse.codinghorror.com/u/Steve)\
**Post date:** [October 31, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/102 "2007-10-31T00:00:00Z")

</div>

I wasn’t questioning your ability to read reg-ex’s, just making the point that some things need to be understood in order to be used. I’ve met people who used GUI SQL builders because they didn’t understand SQL. The result? Garbage. One guy thought that if he got a result, any result, the SQL call was correct. Of course it wasn’t even close because he didn’t understand how a “group by” worked. Programmers need to understand code. People who don’t understand code shouldn’t be programmers. Code isn’t easy to read, that’s why it’s called code. 😉

---

<div class="post-metadata">

**Author:** ![KashifS](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/k/ea5d25/32.png) [@KashifS](https://discourse.codinghorror.com/u/KashifS)\
**Post date:** [October 31, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/103 "2007-10-31T00:00:00Z")

</div>

Jeff,

There is a difference between adding features to a language or “ObjectJunk” libraries.

If you add native SQL features to the core language, then the core language gets polluted with all these specialized keywords, and you can throw backward compatibility out the door, if code written for language 2.5 is not compatible with prior releases. And if you continue the trend with native features, you will get to a point where namespace gets polluted…e.g. orderby keyword referring to a list or a database?

However if you added SQL features to an “ObjectJunk” library, you should be able to use the library with older versions of the languages (provided the library itself can run on older language releases!).

Language designers are always fighting the battle between native vs library.

---

<div class="post-metadata">

**Author:** ![FrancisF](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/f/838e76/32.png) [@FrancisF](https://discourse.codinghorror.com/u/FrancisF)\
**Post date:** [November 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/104 "2007-11-01T00:00:00Z")

</div>

The “sql is different across platforms” argument is pure nonsense. If you stick to the ANSI syntax it will work across MySQL/Oracle/DB2 and most of the others.

If you use something like Oracle avoid decode() and the (+) operator for outer joins - the standard syntax will work.

Stick to the standards and you’ll be fine.

I code in Ruby on Rails these days and use ActiveRecord for most of my database needs. Interestingly, the design goal for this was to make the simple stuff really easy (finding things, getting sets of child records etc.). But you can still put raw SQL in for more complex tasks that can’t be expressed in Object crud. This works really well.

Ruby’s metaprogramming makes it really easy to implement ActiveRecord, it has a method\_missing method that allows it to intercept things like

Person.find\_by\_first\_and\_last\_name “fred”, “smith”

and turn it into SQL (and also add this method into the class on the way so there isn’t any runtime penalty after the first invocation). You can write really fluent-looking code that reads well, and also dive into SQL for grouping and so on (or proprietary hacks) if you must.

I can’t go back to Java and have never had to work with its child C#. I can just write code that reads like English. If I were going back I’d use Hibernate though - again it does the 95% really well and you don’t have to care about your database engine.

Regular expressions are part of the Ruby language and are first-class members of the object hierarchy. Working with them is really easy and they have the standard syntax. Again … Java … C# … shudder.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse-cdn.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [November 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/105 "2007-11-01T00:00:00Z")

</div>

I am not advocating the “one right way” to do anything. Use whatever approach you feel works best for what you’re doing.

This post is meant to incite discussion and thought on the topic. Consider what you’re doing, why you’re doing it, and what the alternatives really are. E.g., if you really need to talk to 5 different databases, then by all means, use an ORM that can help you do that. But also think about the limitations of your toolset and why those limitations exist. Don’t blindly accept the status quo because your toolset forces you to.

I believe in the inherent power and flexibility of domain specific languages, and that’s exactly what SQL (for data) and Regex (for strings) are. Every developer should be conversant in these languages. The idea that all code should be in one, and only one, language is obsolete. The world is now a patois of different domain-specific languages. Don’t fight it with object wrappers. Learn to embrace it and love it.

---

<div class="post-metadata">

**Author:** ![Srdjan](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/e495f1/32.png) [@Srdjan](https://discourse.codinghorror.com/u/Srdjan)\
**Post date:** [November 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/106 "2007-11-01T00:00:00Z")

</div>

@Jeff,  
I understand the need to incite discussion about this, however, I don’t understand why I chose to attack SubSonic. However you may wrap it and explain it, that’s what it is. Your example can be represented in one line. In fact, I easily identified with it, because it’s what Ruby and Rails do almost everywhere. I liked it, just for that reason.

So, why SubSonic? Why hang it out like that?

---

<div class="post-metadata">

**Author:** ![Sean](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/f0a364/32.png) [@Sean](https://discourse.codinghorror.com/u/Sean)\
**Post date:** [November 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/107 "2007-11-01T00:00:00Z")

</div>

I think it’s funny that so many people wrap SQL in the name of “database independence”.

“Database independence” is the reason SQL exists.

All you’re doing is abstracting the abstraction.

Target SQL92 and it’ll work in a wide variety of databases.

---

<div class="post-metadata">

**Author:** ![John\_Rusk](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/j/919ad9/32.png) [@John\_Rusk](https://discourse.codinghorror.com/u/John_Rusk)\
**Post date:** [November 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/108 "2007-11-01T00:00:00Z")

</div>

I’m with you Jeff.

In fact, I’ve gone so far as to post a complete re-working of Joshua’s example. The re-worked example is concise and readable, but NOT fluent.

I’ve also proposed an explaination for why the fluent style may be necessary in Java, but not in C#.

---

<div class="post-metadata">

**Author:** ![Ian\_Pender](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/i/b5ac83/32.png) [@Ian\_Pender](https://discourse.codinghorror.com/u/Ian_Pender)\
**Post date:** [November 2, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/109 "2007-11-02T00:00:00Z")

</div>

Hi Jeff,

I’ve been coding for 10 years and have stubbornly kept RegExs at arms length - dealing with them clumsily and only when I needed to.

You’ve put forward a great arguemtn and I’ve really started to ‘get’ RegExs. Indeed I spotted this article which demonstrates commetnign of RegExes, which I didn’t know of. Yes it’s verbose, and yes I can now read the whole Regex without it now, but it looks like a great way of leaving a trail for others to follow. Anyhoo… [http://msmvps.com/blogs/jon.skeet/archive/2007/11/02/i-love-linq-simplifying-a-tedious-task.aspx](http://msmvps.com/blogs/jon.skeet/archive/2007/11/02/i-love-linq-simplifying-a-tedious-task.aspx)

---

<div class="post-metadata">

**Author:** ![Nicolas](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/n/67e7ee/32.png) [@Nicolas](https://discourse.codinghorror.com/u/Nicolas)\
**Post date:** [November 2, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/110 "2007-11-02T00:00:00Z")

</div>

Quote: I would argue that most of these benefits could be realized with smarter IDEs that actually understood native SQL strings (or regular expressions)

Well, gvim syntax highlighting for PHP can highlight regular expressions. I think it doesn’t highlight SQL (yet). Better than a slow bloated IDE.

---

<div class="post-metadata">

**Author:** ![MaksymS](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/m/f07891/32.png) [@MaksymS](https://discourse.codinghorror.com/u/MaksymS)\
**Post date:** [November 2, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/111 "2007-11-02T00:00:00Z")

</div>

It seems, that people are continuing invent new approaches…  
forgetting (and not using) the best from old ones.

---

<div class="post-metadata">

**Author:** ![willd](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/w/f4b2a3/32.png) [@willd](https://discourse.codinghorror.com/u/willd)\
**Post date:** [November 2, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/112 "2007-11-02T00:00:00Z")

</div>

“If I’m not mistaken, in the .NET world, SQL is best handled by leaving the queries on your SQL Server and using parameter calls to prevent injection for best security and performance.”

This has not been the case unless you are using MS-SQL Server predating MS-SQL 2000 in a client/server environment.  
Using stored procedures still leaves you open to SQL injection, and stored procedures are no faster then the other SQL commands. Actually in the way most people use stored procedures for CRUD they are slower than parameterized queries because of all the coalesce or isnull are very very slow.

---

<div class="post-metadata">

**Author:** ![Matijsv](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/m/e99b99/32.png) [@Matijsv](https://discourse.codinghorror.com/u/Matijsv)\
**Post date:** [November 3, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/113 "2007-11-03T00:00:00Z")

</div>

For another way of using the power of your programming language to produce SQL that is known to be valid at compile time, take a look at this solution in OCaml:

[http://eigenclass.org/hiki/addressing-orm-problem-typed-relational-algebra](http://eigenclass.org/hiki/addressing-orm-problem-typed-relational-algebra)

---

<div class="post-metadata">

**Author:** ![PhillipC](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/p/dfb087/32.png) [@PhillipC](https://discourse.codinghorror.com/u/PhillipC)\
**Post date:** [November 4, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/114 "2007-11-04T00:00:00Z")

</div>

Fluent Interfaces are adaptation to languages to make them ‘feel better’. SQL, RegExp and LINQ are Domain Specific Languages and they’re not directly related to Fluent Interfaces.

By using a fluent interface you give up your language syntax a bit to get something more readable. By using a DSL you use a language specialized on the problem being solved.

The problems of getting a nice DSL and transforming it on tons of lines of a General purpose Language are not related to Fluent Interfaces.

---

<div class="post-metadata">

**Author:** ![AndreasK](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/a/b782af/32.png) [@AndreasK](https://discourse.codinghorror.com/u/AndreasK)\
**Post date:** [November 4, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/115 "2007-11-04T00:00:00Z")

</div>

“First show a regex expression which is completely unreadable to anyone not versed in regex’s, compared it to a test interface that makes it into something readable by any competent programmer.”

Two mistakes. A competent programmer nowadays know regepxs. And it is much more efficient to make a practical solution than let everybody wade through something that verbose. (For educational purposes write a regexp-to-verbose-objects converter and use that to understand the code.)

Or just imagine how a language would look like if it were designed for competent programmers that are just not well versed in OO and where every method invocation would explain what it does…shudder.

“…your one line of sql starts becoming several lines of conditionals, parameters, and concatenations.”

Not with proper interpolation at hand. Unfortunately, user-defined string interpolation doesn’t exist and can’t be implemented in most current languages.

“And you are still embedding sql in the middle of your app.”

So what? Code is code. 🙂

---

<div class="post-metadata">

**Author:** ![marcelo2](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/m/fbc32d/32.png) [@marcelo2](https://discourse.codinghorror.com/u/marcelo2)\
**Post date:** [November 6, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/116 "2007-11-06T00:00:00Z")

</div>

“But in my professional opinion, that regex was a well written one.”

Even if it matches things that it obviously shouldn’t match, like divclass="game"id=…, uhm? (and it uses grouping constructs without any useful purpose besides making it look more complicated than it actually is)

---

<div class="post-metadata">

**Author:** ![engtech](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/e/46a35a/32.png) [@engtech](https://discourse.codinghorror.com/u/engtech)\
**Post date:** [November 9, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/117 "2007-11-09T00:00:00Z")

</div>

The problem with wrapper code of any kind is that it HAS TO BE TRANSPARENT. If you loose some of the capability of the base language, or if it introduces new bugs and complexity that the base language didn’t have then it’s a complete failure.

My personal pet peeve is slightly differing regexp syntaxes between programs. Especially you, emacs.

---

<div class="post-metadata">

**Author:** ![Scott](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/3e96dc/32.png) [@Scott](https://discourse.codinghorror.com/u/Scott)\
**Post date:** [March 13, 2008, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/118 "2008-03-13T00:00:00Z")

</div>

I was thinking about this and had to search for this post but surely generics would count as a language in a language? It’s like a preprocessor language and pretty tidyly implemented (in C# atleast).

---

<div class="post-metadata">

**Author:** ![grumlin](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/g/df705f/32.png) [@grumlin](https://discourse.codinghorror.com/u/grumlin)\
**Post date:** [September 4, 2008, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/119 "2008-09-04T00:00:00Z")

</div>

I think the point of frameworks like SubSonic is not to save lines of code in how I write a SQL Sentence, but in how I express the sentence in an environment that will handle the Impedance Mismatch between the SQL World and the objects world, saving code.

These two lines of code:

---

<div class="post-metadata">

**Author:** ![SteveJ](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/ce7236/32.png) [@SteveJ](https://discourse.codinghorror.com/u/SteveJ)\
**Post date:** [February 6, 2010, 12:00am UTC](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443/120 "2010-02-06T00:00:00Z")

</div>

I hadn’t looked at it that way. I thought the effective use of fluent interfaces was to get closer to a domain specific language, rather than just to rewrite regex in objectese. So rather than call 8 separate variable tweaks on an object to perform an action, I can chain them into code that expresses what a customer might think.

Programmer steve = new Programmer().hasName(“Steve”)  
.hasOOPExperience()  
.doesntget(“FluentInterfaces”)  
.dockPay(200%);

[Previous page](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443.md?page=5)

[Next page](https://discourse.codinghorror.com/t/embracing-languages-inside-languages/443.md?page=7)
