tags:

views:

302

answers:

6

Hi everyone!

I recently began to read some F# related literature, speaking of "Real World Functional Programming" and "Expert F#" e. g.. At the beginning it's easy, because I have some background in Haskell, and know C#. But when it comes to "Language Oriented Programming" I just don't get it. - I read some explanations and it's like reading an academic paper that gets more abstract and strange with every sentence.

Does anybody have an easy example for that kind of stuff and how it compares to existing paradigms? It's not just academic fantasy, isn't it? ;)

Thanks, wishi

+2  A: 

The term language Oriented Programming may be overloaded in that it might have different meanings to different people.

But in terms of how I've used it, it means that you create a DSL(http://en.wikipedia.org/wiki/Domain%5FSpecific%5FLanguage) before you start to solve your problem.

Once your DSL is created you would then write your program in terms of the DSL.

The idea being that your DSL is more suited to expressing the problem than a General purpose language would be.

Some examples would be the make file syntax or Ruby on Rails ActiveRecord class.

chollida
that means generally I generate a custom subset of the language to express specific stuff, that would be too hard to put in the general language?
wishi
+4  A: 

In Object Oriented Programming, you try to model a problem using Objects. You can then connect those Objects together to perform functions...and in the end solve the original problem.

In Language Oriented Programming, rather than use an existing Object Oriented or Functional Programming Language, you design a new Domain Specific Language that is best suited to efficiently solve your problem.

Justin Niessner
Downvotes for both me and chollida without any reasons? Harsh...I'd like to know what I got wrong.
Justin Niessner
+9  A: 

F# has a few mechanisms for doing programming in a style one might call "language-oriented".

First, the syntax niceties (function calls don't need parentheses, can define own infix operators, ...) make it so that many user-defined libraries have the appearance of embedded DSLs.

Second, the F# "quotations" mechanism can enable you to quote code and then run it with an alternative semantics/evaluation engine.

Third, F# "computation expressions" (aka workflows, monads, ...) also provide a way to provide a type of alternative semantics for certain blocks of code.

All of these kinda fall into the EDSL category.

Brian
+2  A: 

I haven't directly used language oriented programming in real-world situations (creating an actual language), but it is useful to think about and helps design better domain-driven objects.

In a sense, any real-world development in Lisp or Scheme can be considered "language-oriented," since you are developing the "language" of your application and its abstract tree as you code along. Cucumber is another real-world example I've heard about.

Please note that there are some problems to this approach (and any domain-driven approach) in real-world development. One major problem that I've dealt with before is mismatch between the logic that makes sense in the domain and the logic that makes sense in software. Domain (business) logic can be extremely convoluted and senseless - and causes domain models to break down.

emptyset
+9  A: 

Language oriented program (LOP) can be used to describe any of the following.

Creating an external language (DSL)

This is perhaps the most common use of LOP, and is where you have a specific domain - such as UPS shipping packages via transit types through routes, etc. Rather than try to encode all of these domain-specific entities inside of program code, you rather create a separate programming language for just that domain. So you can encode your problem in a separate, external language.

Creating an internal language

Sometimes you want your program code to look less like 'code' and map more closely to the problem domain. That is, have the code 'read more naturally'. A fluent interface is an example of this: Fluent Interface. Also, F# has Active Patterns which support this quite well.

I wrote a blog post on LOP a while back that provides some code examples.

Chris Smith
Hi Chris,Got your book and I'm really liking it so far. :-) Hoping to really ratchet up my F# game by the time I work through it.
Onorio Catenacci
A: 

An easy example of a domain-specific language, mentioned here, is SQL. Also: UNIX shell scripts.

Of course, if you are doing a lot of basic ops and have a lot of overlap with the underlying language, it is probably overengineering.

ctd