News for hackers. Stuff that matters.
Re:I want to fix programming by jerf on Tuesday January 24, 2012 @05:39PM (#3507281)
So, over the years I've played with many things that claim to be "declarative", and here's why I now shy away from them like the plague. There's no such thing as "declarative". No matter what you type into the computer, at some point it's going to turn into instructions that do the thing you want done. Trying to create a declarative language is a way of making it extraordinarily opaque as to what the machine is actually going to do. It looks great in four lines, it crashes and burn on any real sized problem, because you inevitably hit the following sequence:

1. I encounter a problem; a performance issue or a bug.

2. I can not practically proceed past this point because everything I might need to figure out what is going on has been "helpfully" obscured from me.

Yes, you can still thrash and flail but this hardly constitutes a "fix" to programming. You simply can not help but create an abstraction that not only leaks like a sieve, but is actually multiple leaky sieves layered on top of each other in opaque ways. (And letting us see in is in its own way a failure case too, with these goals.)

Part of what I like about Haskell is that it helps bridge the gap, but doesn't actually go too far. A map call is still ultimately an instruction to the machine. It's not quite the same type of instruction you give in C or C++, what with it being deferred until called for (lazy) etc, but it's still an instruction and it can be followed down to the machine if you really need to without only marginally more work than any other "normal" language. (It may be a bit bizarre to follow it down all the way, but hardly more so than C++ in its own way.)

Contrast this to SQL, which is declarative, and you never have to worry about what the database is doing to answer your question. Except it never works that way and you inevitably must actually sit there and learn how indexes work and how queries are parsed and how the optimizer works to a fairly deep level and then sit there on every interesting query and work out which synonymous query will tickle the optimizer into working properly except that you actually can't do that and you end up having to turn to weird annotated comments in the query specific to your database and then you still end up having to break the query into three pieces and manually gluing them together in the client code.

And I don't even care to guess how many man-millenia have been poured into that declarative language trying to make it go zoom on a subproblem much simpler than general purpose computing. (Well, except isasmuch as they've more or less grown to encompass that over the years, but it's still at least meant to be a query language.)

So, if you think you can fix that problem, have fun and I wish you the very best of luck, no sarcasm. This is the problem I've seen with the previous attempts to go down this route before, and I feed this back in the spirit of helping you refine your thoughts rather than yelling at you to stop.

Re:I want to fix programming by jng on Wednesday January 25, 2012 @08:47AM (#3509663)
Jerf, thanks so much for sharing your thoughts. I think I agree with all your views. They are taken from the real experience of trying those approaches. And I am grateful that you provide the feedback. I and anyone tackling this steep mountain need all the help we can get.

I am sure that inspectability/debuggability are two of the big issues with such an approach. When things fail, the more magic there is, the more difficult it is to fix it. It's even difficult to understand what's happening!

I do think that there is a gap there. You can specify things and have the environment apply your spec. If it's totally naive, like Prolog's "slowsort", it will take exponential time and be impractical for real-world cases. But if strategies can be found and/or devised, and applied, which get some efficiency, it can be practical for many things. When things fall apart, it's clear that powerful debuggers will be needed. A lot of work will be needed on the tools, similar to SQL Query Strategy Inspectors, etc... maybe even professionals specializing just in this. But I think that it will finally allow us to write code in a sane way. Even if armies of professionals have to come after the fact to tweak it so that it's usable, the same as for SQL.

I totally understand what you see as adavantageous in Haskell. I think that same "it's turtles all the way down", where you can inspect and debug every step, is the reason that Haskell cannot gain the power that I am after. Prolog can't either, for other reasons.

I believe a fundamentally different approach is needed. And that's what I'm trying to sketch out.

And thanks to you and many other people hopefully we can learn whether there is something there or there isn't, and if there is, hopefully reach some useful result!

Re:I want to fix programming by jseban on Wednesday January 25, 2012 @08:28AM (#3509619)
You have a point, declarative approaches almost never delivers as promised, which is "you don't have to worry about implementation".

In reality, as you say, you end up with edge cases where you still need to dive into the implementation in order to find out what's happening.

I don't think it's a good enough argument to dismiss the whole paradigm though. Im prefectly happy with my declarative regular expressions that work 90% of the time, and rather take the hit debugging those hairy 10% that end up not working well, than writing my own imperative parser every time and repeatedly deal with those off by one errors etc..

When you say "it never works" I suspect you really mean "it never works in 100% on the cases".

Re:I want to fix programming by raganwald on Wednesday January 25, 2012 @07:08AM (#3509448)
SQL is declarative, and that's it's strength. The optimization, indexing, and other tweaking of the implementation is separated from the code that declares the result needed.
Re:I want to fix programming by overgard on Wednesday January 25, 2012 @08:37AM (#3509643)
I'm not convinced you can really separate those things in a practical context. Inevitably you end up with a leaky abstraction and the opaqueness of what's actually going on makes it harder to diagnose.

I think declarative is the right default, since it shows the intent over the mechanics, but I deeply distrust any system that won't let me be very specific about the mechanics if I need to be.

Re:I want to fix programming by onemoreact on Wednesday January 25, 2012 @10:05AM (#3509933)
The problem is not that SQL is slow, the problem is people push the system until it becomes slow.

It's just as easy to write 'JOIN this billion row table with that billion row table' as it is to forget how hard that is. We may complain that creating indexes is painful, but take some huge complex and slow query and try recreating it in C++ correctly and at least as fast and you quickly enter a world of pain.

PS: It's awesome to be able to write something and then optimize it without worrying that you are going to break something. When it comes to efficiency being able to select performance trade-offs even in an arcane fashion beats testing everything from scratch by a huge margin.

Re:I want to fix programming by Groxx on Thursday January 26, 2012 @12:18AM (#3513011)
The problem is that most SQL engines have commands for fine-tuning. Things like 'ignore index', for instance. That is a leaky abstraction - knowing the details of the system lets the programmer do better than the query analyzer. Similarly, sometimes a left join + null check performs better than a "where not exists ()" subquery, despite them serving identical purposes.

If you can change how you phrase a query and get different performance, while keeping the same semantic meaning, your language isn't just leaking, it's hemorrhaging. It may still be useful, perhaps world-changingly so, but it's a perfect example of the dangers of declarative programming.

As to 'try making it in C++': with a library for doing so with as much maturity as SQL? Sure. It'd probably be reasonably simple, if more verbose. And when it inevitably runs slowly, you can infer the reason for why A runs faster than B relatively simply, because it's doing precisely what you told it to do.

Re:I want to fix programming by jamesrcole on Wednesday January 25, 2012 @02:07AM (#3508692)
I don't think there's any inherent problem with stuff being declarative. We just need the software to be smart enough to handle it well. We might have a long way to go till we can do this effectively.

I'd suggest looking at 'declarative' from the point of view of delegation (not in the technical sense, but the usual sense of getting someone else to do a task for you). Ideally you want to specify what you want to be done and you shouldn't care about how it's done. Software is meant to be a labor saving device.

I assume you're ok with the idea of delegating tasks to people. If the software was smart enough I think it'd reasonable to delegate to it as well.

Re:I want to fix programming by cr4zy on Wednesday January 25, 2012 @02:19AM (#3508728)
Search is declarative and works well.
Re:I want to fix programming by zimbatm on Wednesday January 25, 2012 @08:05AM (#3509565)
"We just need the software to be smart enough to handle it well."

You just shifted the complexity with one sentence, it doesn't make it any easier.

Re:I want to fix programming by jamesrcole on Wednesday January 25, 2012 @11:51AM (#3510463)
I never said anything about making it easier.

I was pointing out that it's a worthwhile longterm goal, but one that requires sophisticated software to achieve.

Re:I want to fix programming by pfraze on Tuesday January 24, 2012 @06:51PM (#3507593)
What if you created a declarative language which allows you to override the algorithms in a functional/imperative? You could create a public algorithm repo that auto-pulls into your local machine on setup. Could search for algorithms by declarations. That would be a lot of reuse.
Re:I want to fix programming by munificent on Tuesday January 24, 2012 @08:15PM (#3507872)
> What if you created a declarative language which allows you to override the algorithms in a functional/imperative?

We have that. They're called libraries. If I need to sort a collection, I don't write an imperative chunk of code, I just do:

    sort(myCollection)
Looks pretty declarative to me.
Re:I want to fix programming by dmitriy_ko on Tuesday January 24, 2012 @10:25PM (#3508247)
The issue here is that function definition doesn't tell what the function does. So you may have hundred implementations of sorting algorithms in different libraries, and neither compiler nor the IDE know that they all do the same thing. So when you write

sort(myCollection)

you are still referring to one particular set of instructions. The system parent poster envisions (the way I understand it) would be along those lines:

* User gives SPECIFICATION of sort, along the lines OP writes about in his blog.

* Other contributors provide various implementations which satisfy the specification. Such system would either have to auto-prove that implementation meets specification or just trust contributors that it does.

* Then in your code you can write sort(myCollection) and the system would pick the best implementation.

Re:I want to fix programming by parbo on Wednesday January 25, 2012 @03:07AM (#3508829)
Interfaces, polymorphism and templates?
Re:I want to fix programming by fossuser on Tuesday January 24, 2012 @06:51PM (#3507594)
I think to have a truly declarative language that doesn't just dissolve into obscure commands at some point requires the language to have a true understanding of human language. Which to currently do well even just for answering questions requires Watson levels of computing power.
Re:I want to fix programming by nickik on Wednesday January 25, 2012 @06:45AM (#3509391)
I think human language sucks at giving commands. Yes human language is very expressive but its very easy to misunderstand each other. With code its always your fault if it dosn't do what you want, you exprest it wrongly. With human language you the error can be on both ends.
Re:I want to fix programming by nandemo on Wednesday January 25, 2012 @01:59AM (#3508674)
> Trying to create a declarative language is a way of making it extraordinarily opaque as to what the machine is actually going to do. It looks great in four lines, it crashes and burn on any real sized problem,

Erlang, Haskell and Ocaml are examples of declarative languages, and they all have been used to solve very real-sized problems: telecommunication switches, compilers, trading systems, a window manager, etc.

It amazes me how the argument above is still repeated (often followed by "but those systems don't count, give me an example of X".)

Re:I want to fix programming by jacktoole1 on Wednesday January 25, 2012 @04:58AM (#3509136)
I love OCaml, but I would hardly call it a declarative language. You still describe the steps to perform an algorithm, rather than the result of the algorithm. The article poster references Haskell and explicitly says "The functional approach brings indeed several improvements over regular imperative or object-oriented programming. But still it’s not the solution."
Re:I want to fix programming by rue on Wednesday January 25, 2012 @07:04AM (#3509437)
The argument forwarded for considering them declarative is that their compilers perform transforms on the source code, and that there are no side-effects.

I certainly agree with your interpretation more. Typical functional programming isn't really declarative (though, yes, moreso than imperative programs are) and those waters shouldn't be muddied.

Re:I want to fix programming by silon3 on Wednesday January 25, 2012 @06:13AM (#3509305)
Agreed IMO: Annotating "turing complete" code is not in any way declarative programming.
Re:I want to fix programming by javadyan on Tuesday January 24, 2012 @09:25PM (#3508096)
Best answer so far :)
Re:I want to fix programming by phzbOx on Tuesday January 24, 2012 @08:38PM (#3507962)
Quantum computer might open unexplored doors.. :)