6 ms·
This is a well-expressed defense of declarative concepts but the title itself highlights the Achille's heel of these ideas: how, after all, do you simply make t
by putzdown 11y ago
This is a well-expressed defense of declarative concepts but the title itself highlights the Achille's heel of these ideas: how, after all, do you simply make the computer do something, like print "Hello, World" at a particular place and time? Declarative techniques are great for the things that they're great for, but programmers who hate side effects have the problem that every program that does anything observable does it through side effects. So I continue to sit on the declarative fence.
- gizmo686 11y agoYou declare that you want it to print "Hello, World" at said place and time.
- notNow 11y agoHow so? What you're saying amounts to basically an instruction not a relation or declaration in the programming sense of the word.
- crdoconnor 11y agoUsing HTML? It's a declarative language.
- notNow 11y agoHow would you specify the starting time of execution in HTML documents?
- gizmo686 11y agoGiven the current specs, I am not aware of any way to do it, but in theory, you could do something like: <div visible="after:5pm"> hello world </div>
- dragonwriter 11y agoUsing a poshformat (which, if the use case was general enough, might be formalized into a microformat.) [0] Probably leveraging the HTML time element. Of course, that lets you specify the execution time, but unless you have a system consuming the format that is aware of the additional semantics beyond the base HTML semantics, specifying that won't do anything. [0] http://microformats.org/wiki/poshformats http://microformats.org/wiki/poshformats
- gizmo686 11y agoSuppose the langauge has a built-in printf() and sleep() function. You could say main=printf("Hello World"), which declares that your program is equivalent to the action of printing "Hello World". You could also say that main=sleep(1), which declares that your program is equivent to the program sleep(1). You can also say that main=sleep(1) >> printf("Hello World"), which says that your program is equivent to the program that sleeps for a second, then prints "Hello World". You can even create syntactic sugar around the concatenation operator, so it looks like you are programming in an imperative language. If the concatenation operator happens to be over-loadable, you can do a lot of neat stuff with it. Even if it isn't, you can define common control flow operations (such as for loops) at the language level, which means that you can just as easily define new control flow operations that the language designers didn't think of.
- pekk 11y agoPrefixing "main=" to a subroutine definition is no different from any language's syntax for declaring subroutines. If that means every programming language is declarative, then declarative doesn't even mean anything.
- anon4 11y agoOkay, but why the weird syntax and not the standard C style int main() { sleep(1); printf("Hello World"); return 0; } And then you can say "pure functions can be evaluated in any order". Maybe impure functions can be suffixed by a !.
- jerf 11y agoIn the small, all paradigms are the same. print "Hello World" with suitable syntax tweaks, is imperative, functional (that code works in Haskell), declarative, and logical (Prolog has a print). Or, more accurately, is simply too small to be usefully discussed in this context. You have to pick something larger to talk about.
- tel 11y agoIt's nice to have the data/declarative notion of an instruction. It's even nicer to have this notion be exactly the same notion by which you cause effects via your language. This means that all effectual code you encounter can, at least in principle, be analyzed as a declarative data structure.
- hvs 11y agoI think us programmers have a tendency to see things as all or nothing, even while we work daily with a number of technologies and languages that do things differently. There is no reason that everything has to be declarative while benefiting from the advantages of declarative/functional languages. Most programmers use SQL on a daily basis and we don't hear arguments that it should be procedural to be inline with our other languages.
- deleted 11y ago[deleted]
- 0xdeadbeefbabe 11y agoYou do hear about ORMs though, which I think supports your point that SQL is better at what it does (than an ORM).
- lfowles 11y agoAre there notable ORMs that don't map to SQL? (Not familiar with databases at all)
- 0xdeadbeefbabe 11y agoAnything is possible. My point is often you'd rather have SQL over an ORM that maps to SQL.
- jerf 11y agoI ranted a while ago on HN about how I don't believe in the existence of declarative: https://news.ycombinator.com/item?id=3507281 https://news.ycombinator.com/item?id=3507281 As I re-read it, read this article, and pondered some more, I'm revising my view a bit, and beginning to think of "declarative" as something like probability. This is debatable, but I tend to agree with the idea of probability as a measure of knowledge of a given agent, and all probabilities must be understood in the context of some agent for whom those are the correct probabilities, as opposed to being free-standing numbers. Similarly, declarative can be seen as relative to the programmer. Haskell code that looks like map (+1) . filter isEven . map (*2) may be declarative to one programmer while writing it, who doesn't care about the details, yet be essentially imperative to someone who, say, is tasked with optimizing that, and cares about exactly what the compiler does with that code and how. It's not a characteristic of the code, but the programmer's relationship to the code, which may even change over time. From this perspective, most things that proudly wear the label "declarative" can be seen as over-forcing you to be ignorant about their implementation details by making this unnecessarily opaque, for the purpose of wearing that label. Still not a tradeoff I like, vs. the same tech except transparent.
- crdoconnor 11y agoIMO it's better to write applications than minimize the amount of imperative code written - favoring declarative code - rather than to eliminate it altogether. A good example of this would be to favor a templating language to render your HTML where possible, rather than building your HTML directly from your code using string concatenation.
- romaniv 11y agoFor the most part, it is possible to remodel applications to handle stateful things outside of the main program. Consider a website. An entire website can be modeled as a function that takes headers, URL and request body as parameters and returns headers and body as the response. You can use the same principle to model almost anything. You take real inputs as inputs and output instructions for imperative side-effect to a minimalist agent of some sort.
- djur 11y agoOnly static and very basic dynamic websites can be modeled that way. Most dynamic websites handle requests which are intended to have an effect (POST, PUT), which requires your function to be impure or to model state changes (DB updates, file I/O, etc.) in some way like Haskell's monads. And what that looks like is going to be much, much different from anything developers are used to in impure languages.
- romaniv 11y agoDatabase and file updates can be treated as a part of page's output.
- wslh 11y agoIn a way, the issue is that nobody is doing the herculean work of automating many of the repetitive and context sensitive things in our field (and don't care if we have an ugly meta-algorithm as a result). I will mention two things that give some clarity about the potential of declarative and intelligent techniques: 1/ Z3[1] (satisfiability modulo theories solver) where you declare what you want and it contains many strategies and previous knowledge to achieve the goals. 2/ Gregory Chaitin[2] saying (can't find the source, probably was a lecture I attended) something like that artificial intelligence is an engineering problem, may be we need a lot of ugly pieces to make it work instead of elegant algorithms. So I think nobody is working really hard at a higher level to look at the problems we have and find a declarative way to solve them. This solution probably will require a lot of field research and ugly disparate modules. [1] http://research.microsoft.com/en-us/projects/z3m/ http://research.microsoft.com/en-us/projects/z3m/ [2] https://en.wikipedia.org/wiki/Gregory_Chaitin https://en.wikipedia.org/wiki/Gregory_Chaitin
- 7h3kk1d 11y agoI think the point is to consciously acknowledge what you're doing needs a side effect. It's similar with mutable state. Both state and side effects are completely necessary but should be isolated and controlled through known constructs.
- fizixer 11y agoI think 'pure-declarative' people are seriously misguided. They like to reduce the dynamic idea of 'computation' to a static idea of 'declaration'. One of the biggest motivation for them is mathematics. All mathematics is written declaration on paper, and mathematics accomplishes so much, so we should follow that model. They fail to realize that math on paper is only half the story. The other half is the 'computation' going on in the mind of the mathematician. And even mathematicians haven't reduced it into declaration. Bottomline: Hybrid approach is superior to 'pure-computational' or 'pure-declarative'.