News for hackers. Stuff that matters.
Re:Programming Languages Are Simply Not Powerful Enough by tikhonj on Thursday February 28, 2013 @11:58PM (#5302917)
I think this roughly reflects my philosophy in languages as well. You basically have two options: you can bend your problem to your language or your language to your problem. The former is epitomized by Java and Python--all Java and Python code looks the same, regardless of what it's actually doing. The latter is the domain of Lisp and Haskell and Forth and so on.

I'm unabashedly in favor of the latter.

Ultimately, it's easier to reason about some domain in that domain. I would love my code for any particular project to look very similar to what I would write on a whiteboard when solving the problem. If I'm solving something inherently mathematical, I want the code to resemble math notation. If I'm writing some parsing code, I want it to resemble a grammar. If I'm writing an interpreter, I want it to resemble the operational semantics of the language. This fits into more "practical" domains as well: if I'm writing a web app, I want the routing to look like, well, routing and the database code to look as close to the database structure as possible.

Any details in the implementation rather than the domain should be separated from the domain logic. If you're trying to make the domain logic mirror the domain itself, this is essentially inevitable. This makes your code more general and easier to debug. You can redirect your domain logic to a different backend, and it's much easier to figure out whether you have a problem in the implementation or the logic.

More generally, such a strict separation of concerns is extremely important. The difficulty of a problem increases exponentially with its complexity: all the parts affect each other. If you manage to neatly split a problem like this in two, each sub-problem will be less than half as difficult as the main problem. So splitting away the high-level logic from the IO and the memory management and the other implementation details is inherently valuable. In fact, this is valuable even if the sum of both sub-problems is a bit greater than the original problem.

The malleable language approach gives you a very natural way to split your problems up: one part is implementing the DSL, modifying the host language or writing a library--creating abstractions. The other part is actually using these abstractions. I find this sort of split to not only be very useful but also very natural; it mirrors how I usually think about things.

One very interesting recent development taking this idea to the extreme is OMeta. There your program is essentially a tower of DSLs, with the base language just being a simple way to specify the DSLs. This idea really is extreme: for example, the code for implementing TCP is actually the ASCII art diagrams describing it! [1]

Of course, all the usual suspects like Lisp and Haskell are also worth looking at. Embedded DSLs in these langauges can go quite far, and they have some of their own advantages to consider.

[1]: http://www.moserware.com/2008/04/towards-moores-law-software...

Re:Programming Languages Are Simply Not Powerful Enough by wvenable on Friday March 01, 2013 @01:41AM (#5303148)
The problem with writing a DSL for every problem (and every programmer writing different DSLs) is that you end up with all these different languages with different vocabularies and different semantics. It's like a million different variations of Esperanto.

Using a programming language is like speaking in common tongue to every other programmer who knows that language. And most languages are so similar that most programmers can communicate even between languages.

Having code that looks the same, regardless of what it's actually doing, allows everybody to be able to read it.

Re:Programming Languages Are Simply Not Powerful Enough by cjh_ on Friday March 01, 2013 @01:49AM (#5303177)
>Using a programming language is like speaking in common tongue to every other programmer who knows that language

As much as I love DSLs, I Couldn't agree more.

>The problem with writing a DSL for every problem (and every programmer writing different DSLs) is that you end up with all these different languages

When writing in a DSL of my design, it is amazing. It feels like the program models exactly how I am thinking about it.

When modifying/maintaining a DSL made by someone other than me, often this can be horrifying, it feels as though this models my thoughts so poorly (and it does, it was designed to model their thoughts).

Re:Programming Languages Are Simply Not Powerful Enough by invalidOrTaken on Friday March 01, 2013 @02:31AM (#5303264)
Programmers already know the DSL for every problem: English (or their native tongue). If they're writing programs for a specific domain without knowing the language of the domain, they have problems that won't be solved by using programming terms they already know.

How many people have learned what MVC means from Rails? Or the term "routing" in the context of a webapp?

One caveat I'll give: the DSL must be well-conceived. Writing a DSL that is dissimilar to both the underlying language and the domain vernacular is obviously horrible.

Re:Programming Languages Are Simply Not Powerful Enough by jclos on Friday March 01, 2013 @02:46AM (#5303312)
I couldn't agree more. As much as I like languages that facilitate DSLs, this is an unrealistic view of software development.

To add to what you wrote, you have to also consider that all developers in one team have to agree on a common DSL beforehand, which is an investment of time in itself, and the fact that if there is an unusually big change in requirements mid-development (which, let's be honest, is not a rare event), you might have to go back and change your "pyramid of DSLs" to accommodate it, maintain compatibility and update all your colleagues on the new languages.

Re:Programming Languages Are Simply Not Powerful Enough by protomyth on Friday March 01, 2013 @10:22AM (#5304639)
How is this any different than a team building a set of APIs?
Re:Programming Languages Are Simply Not Powerful Enough by AnIrishDuck on Friday March 01, 2013 @12:17PM (#5305514)
The syntax required to use the API will be instantly accessible to new developers. Many programming languages provide semantic guidelines for APIs as well. So knowing the language an API is programmed in gives you a huge advantage in beginning to understand it.

With a DSL, all that goes out the window. The syntax of the language is potentially unknown to you. The semantics are an even deeper mystery. You're in terra incognito, trying to understand the mental process of the developer of the DSL before you can even understand what the code written in the DSL intends to do.

The primary goal of programming languages is not to describe how to perform a complex task to a computer. It is to describe how to perform a complex task to other humans in a form that computer can also execute.

Re:Programming Languages Are Simply Not Powerful Enough by protomyth on Friday March 01, 2013 @12:55PM (#5305770)
I'm not sure I buy the whole syntax argument. I programmed in Forth for a while and it seemed like it was much easier to build up an understandable vocabulary than some of the C++ / Smalltalk class hierarchies I have seen. REBOL has dialects that work fairly well. I cannot help but think that DSLs are refinement of APIs the same way C is a refinement of Assembler.

When I talk to someone about what happens in a system it seems like a DSL flows from that conversation.

"It is to describe how to perform a complex task to other humans in a form that computer can also execute."

I think a DSL does that much better than a set of API calls, particularly when you involve non-developers. That is the point of a DSL.

Re:Programming Languages Are Simply Not Powerful Enough by jclos on Friday March 01, 2013 @11:13AM (#5305037)
I see APIs as a less extreme version of DSLs (in that they share a common language, while building a DSL frees you from almost any restriction), but I honestly don't have enough experience building APIs or DSLs to give you a satisfying answer. Sorry.
Re:Programming Languages Are Simply Not Powerful Enough by silverlake on Friday March 01, 2013 @09:38AM (#5304390)
There's very little difference between a DSL and an API. You already know dozens of APIs. Why not DSLs?
Re:Programming Languages Are Simply Not Powerful Enough by geon on Saturday March 02, 2013 @07:30AM (#5309329)
That has been bugging a long time. Exactly what is the difference?

And statements like (paraphrasing the quote in the article)

> You shouldn't build an app in Forth. You should build a language to model your problem domain in forth and use it to build the app.

They just doesn't make sense to me. Isn't that the very definition of how to program?

Re:Programming Languages Are Simply Not Powerful Enough by KingMob on Saturday March 02, 2013 @02:00PM (#5310570)
For a lot of languages, I agree, because there's no way to create a DSL as part of the language itself. Think of the difference as one of direction; are you fitting the domain into the language, or extending the language to fit the domain? Most languages are either general-purpose (C, Java) or their domain is fixed upon creation (SQL, Mathematica).

In a Lisp, you can use macros to accomplish things that go way beyond defining a domain-specific library / API. A typical library is restricted to the capabilities of the language, but a DSL in Lisp can extend the syntax itself.

Want to alter the reader so you have a way to express normal code as remote computations? Go for it. Feel like adding new math operators to use matrices instead of scalars? Knock yourself out.

Common Lisp itself did exactly this when object-oriented programming came along; using nothing but macros and closures, the Common Lisp Object System (CLOS) was built.

Re:Programming Languages Are Simply Not Powerful Enough by gruseom on Saturday March 02, 2013 @04:46PM (#5311221)
The difference between DSL and API is the difference between language and library. What is that difference? Has it ever been successfully defined?
Re:Programming Languages Are Simply Not Powerful Enough by klochner on Friday March 01, 2013 @01:59AM (#5303194)
"Welcome to our team, here's the spec for our project, and here's the spec for our DSL. See you in a month."
Re:Programming Languages Are Simply Not Powerful Enough by limmeau on Friday March 01, 2013 @02:55AM (#5303337)
"and here is the spec for our in-house framework".

"and here is the 1M LOC codebase, which was carefully crafted to avoid using any of the complicated frameworks; all you gotta know is the C standard library".

Re:Programming Languages Are Simply Not Powerful Enough by anthonyb on Friday March 01, 2013 @05:06AM (#5303599)
Spec? For an in-house framework? Luxury!
Re:Programming Languages Are Simply Not Powerful Enough by limmeau on Friday March 01, 2013 @05:37AM (#5303666)
Did I say Spec? I meant the doxygen output of hundreds of classes with sparse one-line doccumments.

Plus one outdated sequence diagram.

Re:Programming Languages Are Simply Not Powerful Enough by masklinn on Friday March 01, 2013 @07:02AM (#5303838)
One-line comment? What are you, a writer-librarian?
Re:Programming Languages Are Simply Not Powerful Enough by limmeau on Friday March 01, 2013 @07:57AM (#5303989)
It can be learned. Observe:

       //! \brief Transport diagnostic wrapper
       class TransportDiagnosticWrapper {
(Actually, meaningful one-line comments are a lyric discipline of their own, related to haikus.)
Re:Programming Languages Are Simply Not Powerful Enough by npsimons on Friday March 01, 2013 @09:05AM (#5304247)
You joke, but a tool I have seen lauded for being really "smart" at automatically generating doxygen comments does exactly that. I guess it at least saves the time of a human doing it by hand . . .
Re:Programming Languages Are Simply Not Powerful Enough by adamsaleh on Friday March 01, 2013 @02:41AM (#5303292)
Actually this is how it was when I started at my current position.

We are doing web-testing in clojure, and in past year our little framework evolved into a DSL of a sorts.

On one hand it is great, we a have consturct like (with-client [name connection & body]), that behind the scenes sets up a virtual machine, registers it as a client of our web-service and destroys it after commands in body are done. I can't imagine we would be doing setup and teardown by hand.

On the other hand it took me a month to get into it (two weeks learning the language, two weeks messing around with the framework) ... and there are still lots of things only our lead-tester knows how to fix, after our devs decide to change something we were relying on for testing.

Re:Programming Languages Are Simply Not Powerful Enough by lkrubner on Friday March 01, 2013 @09:17AM (#5304281)
>two weeks learning the language

I am curious, did you already know the JVM? When I learned Clojure, I was also learning the JVM, and for me the JVM was much harder than Clojure. So I would say it took me 6 months to learn Clojure, but much of that time was the time it took to learn about the JVM and all the related Java weirdness.

Either way, 2 weeks is very impressive.

Re:Programming Languages Are Simply Not Powerful Enough by adamsaleh on Wednesday March 06, 2013 @06:28AM (#5330587)
JVM? I knew Java, but most of what I did in java was using autocomplete in Netbeans and cursing Maven, when it didn't work.

What really helped me that, we had "programing paradigm" course in college, where I learned haskell for 3 weeks, what was enough that anonymous functions, map, reduce and using lists for everything didn't feel new.

Re:Programming Languages Are Simply Not Powerful Enough by markokocic on Friday March 01, 2013 @10:08AM (#5304544)
If you start a sentence with "Welcome to our team" and end it with "See you in a month." whatever you put in between, your company is doomed, and your team is highly dysfunctional.
Re:Programming Languages Are Simply Not Powerful Enough by nnq on Friday March 01, 2013 @05:27AM (#5303639)
Abstraction layers are great... if you don't end up spending 90% of your time climbing the stairs that connect them!

Take SQL, a nice DSL for working with relational databases. Yet people ended up writing ORMs (quite ugly creatures imho - something between an elevator connecting two layers, and as in real life elevators are a mess when too many people want to use them at the same time, and an intermediate pseudo-level, but they are useful) because the pain of climbing up and down the ladder connecting the "relational level" with the "OO layer". "Language layers" or DSLs are a powerful but dangerous abstraction because when they start using them people can't stop, they just make more and more layers like crazy! (The only other abstraction so powerful and so dangerous I can think of are objects - it's amazing how many got them completely wrong so many times in languages like C++ or Java... besides Ruby and Smalltalk I can't think of anything that got them "mostly right"... and Ruby seems to be the most DSL-able language in use too, though this is why I'd take Python over it any day - smart programmers tend to make everything like a freakin DSL in Ruby and and your mind ends up running up and down the ladders until you go insane when reading code).

Re:Programming Languages Are Simply Not Powerful Enough by ef4 on Friday March 01, 2013 @10:48AM (#5304852)
Your example is actually a pet peeve of mine. SQL is not at all a nice DSL for working with relational databases programmatically. When you think of it as an API, it exposes one method that takes one gigantic string parameter. API design doesn't get much worse than that.

A sane relational database API would let you compose and extend arbitrary queries, which has profound implications for the way you can write your program and abstract away repeated patterns.

[Arel](https://github.com/nkallen/arel) has the right idea in terms of API, but a poor implementation (lots of things are not truly composable where they should be). [ScalaQuery](http://www.scalaquery.org/) purports to have the right idea, but I haven't tried it, and it's very Scala-centric.

Re:Programming Languages Are Simply Not Powerful Enough by mercurial on Friday March 01, 2013 @08:31AM (#5304109)
The other problem with SQL is the "standard problem": you have so may of them to choose for that when you need to support several databases, the additional layer of complexity and black magic of an ORM can be worth it.
Re:Programming Languages Are Simply Not Powerful Enough by nahname on Friday March 01, 2013 @10:05AM (#5304531)
I can't speak for everyone, but the reason I choose to use an ORM over writing all my SQL by hand is time and maintenance cost. I can write one SQL query to perform CRUD operations for a model almost as quickly as I could use a ORM. The problem is that it produces 10 times as much code to read and interprete. If I write the SQL code for another model, 90% of that new code is exactly the same as the last. I am bleeding duplication everywhere.
Re:Programming Languages Are Simply Not Powerful Enough by agentultra on Friday March 01, 2013 @10:17AM (#5304609)
What is completely wrong about the way C++ does "objects?"

I've recently been digging hard-core into C++ after making such disparaging comments for years and have been rather surprised to see that it's not as terrible as I once thought -- It's actually quite good.

I agree however with your point about dangerous abstractions. DSLs when implemented with careful, thoughtful restraint are rather powerful. SQL being a really good example. There's nothing stopping anyone from writing their database queries by directly sifting through and filtering datums from the domain using the primitive functions and operations of their programming language of choice... but it's clear that SQL is much more powerful and lets us express such problems in a succinct way.

But just like programming languages, once introduced, a DSL is likely to be misunderstood and abused. The problem I believe lies not with the technique but with the users. A double-edged sword is a fine tool but will likely maim an inexperienced user. Which will probably lead them to writing DoubleEdgeSwordWrapperMachineGun classes and then someone else to write a DSL on top of that...

Re:Programming Languages Are Simply Not Powerful Enough by SomeCallMeTim on Friday March 01, 2013 @01:13AM (#5303091)
I would add Lua to the latter group (a language used as a tool to build the language you need).

Not NEARLY as cool of an implementation as implementing TCP using ASCII art, but there's a command-line option parser that parses the help text to determine the command line options. [1] For example:

    -- scale.lua
      require 'lapp'
      local args = lapp [[
      Does some calculations
        -o,--offset (default 0.0)  Offset to add to scaled number
        -s,--scale  (number)  Scaling factor
         <number> (number )  Number to be scaled
      ]]

      print(args.offset + args.scale * args.number)
[1] http://lua-users.org/wiki/LappFramework
Re:Programming Languages Are Simply Not Powerful Enough by spc476 on Friday March 01, 2013 @04:39AM (#5303526)
Threre's also LPeg [1], which I find much nicer than lex and yacc (or flex and bison) for writing parsers. I just finished up a quick hack to pull out a single file from a git repository into its own repository, and the parsing of the "git fast-export" output is 70 lines of Lua/LPeg. It may sound like quite a bit, but it's a near dump of the BNF you find on the man page [2]. From there, it was simple enough to grovel through the in-memory representation of the git repository and output only what I needed.

[1] http://www.inf.puc-rio.br/~roberto/lpeg/ [3]

[2] http://kernel.org/pub/software/scm/git/docs/git-fast-import....

[3] I actually use the re module [4] as I find the results more readable, and only use the LPeg module when I need something that the re module can't provide.

[4] http://www.inf.puc-rio.br/~roberto/lpeg/re.html

Re:Programming Languages Are Simply Not Powerful Enough by chubot on Friday March 01, 2013 @04:07AM (#5303463)
That can be done in basically any dynamic language: see http://docopt.org/
Re:Programming Languages Are Simply Not Powerful Enough by SomeCallMeTim on Friday March 01, 2013 @01:47PM (#5306098)
That's a pretty cool project. Sure you CAN do it in any language (as another commenter points out, you can do it in C too). Anything that's turing-complete can do it. You could also use C to parse ASCII art and have that create a TCP implementation. It's not the natural way you'd do it in that language, though.

lapp has been around for four years; docopt is (looking at git commits) less than a year old. It strikes me as a natural way to do things in Lua, which is why (I suspect) it was done in Lua earlier.

Re:Programming Languages Are Simply Not Powerful Enough by masklinn on Friday March 01, 2013 @07:03AM (#5303841)
It can even be done in static languages with an intermediate compilation step.
Re:Programming Languages Are Simply Not Powerful Enough by ufo on Friday March 01, 2013 @08:52AM (#5304175)
My problem with Lua DSLs is the verbose function syntax (`function foo() return end`). I'm thinking about experimenting more with Metalua to see if it helps in that regard.

One thing that positively impressed me were coroutines though. You can do some very interesting DSL things with it.

Re:Programming Languages Are Simply Not Powerful Enough by gbog on Friday March 01, 2013 @12:17AM (#5302958)
Don't you think that with lisp you also need to bend your problem to the particular of lisp? I speak fluently three human languages, and I also have to bend to them when I want to express myself. The more proficient I am the less the bending is noticed, but it is still there.

I'd say it is the same with all good computer languages. You can express whatever you want in python and lisp, but following different grammar.

Re:Programming Languages Are Simply Not Powerful Enough by 6ren on Friday March 01, 2013 @02:33AM (#5303274)
Totally agree with division into modules lowering complexity (provided it narrows inter-module communication). An interesting idea, that a DSL is way to do this.

But designing a language is hard, including a DSL. Even for experts. e.g. Codd had two attempts at a language for relational algebra, but "mere mortals" couldn't use them. Mathematicians create new notations at the drop of a hat, giving their own definitions to common terms willy-nilly, but this can be an impediment to collaboration.

OTOH, there's an advantage of having many different attempts at a language, inspiring and cross-fertilising each other, til eventually settling on a near-optimal design (if everyone designs their own DSL, this doesn't happen). In practice, you get one group of people experimenting like crazy - academics, visionaries, hackers - and a huge majority that waits to see if something emerges that they can standardise on. Meanwhile, experiments continue. (This is basically the "technology adoption lifecycle".)

The ruby community develops new DSLs very quickly, in the form of frameworks. I get the impression the rapidity of change is challenging, but the improvements are worth it.

Re:Programming Languages Are Simply Not Powerful Enough by namank on Friday March 01, 2013 @12:25AM (#5302977)
I am studying engineering, which is all about OOP. HN is making me so uncontrollably curious about the functional stuff!
Re:Programming Languages Are Simply Not Powerful Enough by babarock on Friday March 01, 2013 @05:19AM (#5303626)
Keep in mind that functional isn't better or worse than OOP. What you see on HN is merely a reaction to the trend in the past decade (a trend still going on today) to teach OOP as the only de facto paradigm to use.

If Functional Programming was mainstream, everyone here would be raving about OOP and its benefits.

Ultimately what you want is to borrow the good ideas of different paradigms to create elegant and practical code.

Re:Programming Languages Are Simply Not Powerful Enough by npsimons on Friday March 01, 2013 @09:09AM (#5304254)
Keep in mind that functional isn't better or worse than OOP. What you see on HN is merely a reaction to the trend in the past decade (a trend still going on today) to teach OOP as the only de facto paradigm to use.

To put it another way, OOP is a pretty nice hammer, but so many people have been using it to bash screws in (including ridiculous cases like concrete!) that others have reacted by using screwdrivers for everything (including nails). Pick the right tool for the job.

Re:Programming Languages Are Simply Not Powerful Enough by oh_sigh on Friday March 01, 2013 @10:47AM (#5304842)
> Keep in mind that functional isn't better or worse than OOP.

Ah yes, the ol "it's all relative" argument.

Re:Programming Languages Are Simply Not Powerful Enough by polymatter on Friday March 01, 2013 @07:25AM (#5303899)
if you're at all interested, I can't recommend (http://learnyouahaskell.com/) highly enough.
Re:Programming Languages Are Simply Not Powerful Enough by namank on Friday March 01, 2013 @12:01PM (#5305402)
Would you recommend that or pg's On Lisp?
Re:Programming Languages Are Simply Not Powerful Enough by polymatter on Friday March 01, 2013 @01:03PM (#5305833)
Learn You a Haskell. I found it easier to read and often thats what you need when your mind is being warped by the content.
Re:Programming Languages Are Simply Not Powerful Enough by lclarkmichalek on Friday March 01, 2013 @04:42AM (#5303536)
Try it. Its not the silver bullet it sounds like when you listen to people rave about it, but it is worth learning.
Re:Programming Languages Are Simply Not Powerful Enough by nollidge on Friday March 01, 2013 @09:32AM (#5304357)
Put it in your toolbox. You can apply functional concepts in basically any high-level language.
Re:Programming Languages Are Simply Not Powerful Enough by tomp on Friday March 01, 2013 @05:02AM (#5303585)
I think you're wrong about Python. It has very powerful abstraction and runtime reflection mechanisms that enable DSL-like frameworks, such as Flask or Django, to be implemented in it.
Re:Programming Languages Are Simply Not Powerful Enough by bdr on Friday March 01, 2013 @05:15AM (#5303619)
Evidence to the contrary:

* Heterogeneity of object abstractions: in order of complexity, you use namedtuples, classes, and metaclasses. In Lisp you'd use the same kind of abstraction across complexity levels.

* Similarly, there are lambdas, plain functions, and bound methods, all for pretty much the same thing.

* Which do you use when? How hard is it to change? http://lukeplant.me.uk/blog/posts/djangos-cbvs-were-a-mistak...

* The way so many configuration variables in Django are strings, that just "coincidentally" point to a class, module, or function.

I've been using Python for 10 years, and Django since pre-1.0. My current startup is built on it. The parts start to show.

Re:Programming Languages Are Simply Not Powerful Enough by nnq on Friday March 01, 2013 @05:17AM (#5303623)
Actually, what I like about Python frameworks is that they don't look like DSLs, they manage to be clean, explicit, casual and understandable Python code, even if you may consider them a DSL at a conceptual level.
Re:Programming Languages Are Simply Not Powerful Enough by hawleyal on Friday March 01, 2013 @08:57AM (#5304201)
LOL.

You can bend your statement to your language, or your language to your statement. All essays look the same, regardless of the statement being made. English, Chinese, Persian.

[deleted]
Re:Programming Languages Are Simply Not Powerful Enough by cjh_ on Friday March 01, 2013 @01:45AM (#5303166)
I think you misread that.

> you can bend your problem to your language

>The former is epitomized by Java and Python--all Java and Python code looks the same, regardless of what it's actually doing.

He was saying that python and java don't bend as languages towards the domain, that is that they bend the problem towards them.

>or your language to your problem.

>The latter is the domain of Lisp and Haskell and Forth and so on.

And that Lisp, Haskell and Forth are the languages that bend.

Re:Programming Languages Are Simply Not Powerful Enough by me_again on Friday March 01, 2013 @01:48AM (#5303173)
You're misreading. OP is saying that in Java and Python you must bend your problem to the language. So you both agree.