views:

330

answers:

5

Recently i get in touch with Empire-db. The project doc. stated that they are using "string-free coding", intended to use less constant strings as possible to avoid typos and use the force of the compiler.

I was always a big fan of this principle, because i think as Java is a formal language it could be expresive for configuration like properties or xml and gives extra value by checking thru the compiler. Maybe at runtime there are less posibilities to changes without recompiling but this depends on each case.

Do you now more references or readings about this term/principle/design pattern ?

+4  A: 

Though I've never heard that particular term, I know what you mean, it makes sense.

Neil McKeown
+4  A: 

I know little about Java, but this idiom is famous in modern C++. For example, Xpressive is a regular expression library that allows the programmer to write regex in C++, and does compile-time checking. Spirit is another example, where you could write EBNF in C++, and the compiler can check the syntax for you also :)

I think the term you are looking for is Embedded Domain Specific Languages.

AraK
Qt has something related too, but that's because of the way translations work there. Basically you encapsulate every user-visible string with "tr( ... )", and the app looks it up dynamically at runtime, only using the given string when no suitable translation was found.
Jurily
+1  A: 

Never heard the particular expression, but Effective Java recommends to "avoid strings where other types are more appropriate" (Item 50).

Fabian Steeg
+5  A: 

This is the same thing as magic number vs constants. Using constants raises maintainability and readability. Constants also encapsulate change: a change in constant value is automatically propagated and, as for string-free coding, a misspelled constant is a compile-time error.

dfa
A: 

The famous Pragmatic Programmer mentions this principle especially in connection with metadata handling. One of the tips about this is:

Put Abstractions in Code, Details in Metadata

Program for the general case, and put the specifics outside the compiled code base.

It is worth reading the book anyway.

rics