TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Imperative vs. Declarative (2013)

72 pointsby actraubover 10 years ago

6 comments

sytelusover 10 years ago
I&#x27;d been enough in to these battles so my 2 cents. I&#x27;m not saying that declarative mode is bad, in fact I love it, but the problem is that people tend to over do it in undesirable way. I&#x27;ve seen &quot;architects&quot; designing declarative language on top XML and asking programmers to code in it. There are also examples in likes of WPF which is perhaps the ugliest fattiest hairiest thing out there that lot of people have to fight with to get their job done.<p>1. Declarative languages or constructs are much harder to debug when things are not working as expected. There are no breakpoints to put or no debug statements to write or no watch to put. It was supposed to do <i>that</i> and you just can&#x27;t tell why it&#x27;s doing <i>this</i>.<p>2. Performance issues are much harder to resolve with declarative constructs. When you get in hotspot, there is no way to run. You would be fortunate if your language&#x2F;platform allows you to fall back to imperative mode but there are platforms&#x2F;languages out there which insist in 100% declarative styles.<p>3. There is lot of bad declarative syntax that is not designed to be composable. Lot of time, it&#x27;s just is not extensible or allows to take advantage of modern programming language constructs such as inheritance, functional patterns, etc.
评论 #8691320 未加载
评论 #8694759 未加载
评论 #8691414 未加载
评论 #8691311 未加载
评论 #8692287 未加载
评论 #8691288 未加载
评论 #8691859 未加载
Animatsover 10 years ago
Yes, way too imperative. &quot;map&quot; and &quot;reduce&quot; are imperative; they order something done.<p>With true declarative forms, you can treat them as data and do something other than execute them. It&#x27;s hard to do much with an imperative form other than execute it. A scene graph or a game level file is a declarative form; you can view it from different angles and positions. The programs that plan actions for NPCs look at a game level and decide what to do. CAD files are declarative. Spreadsheets are mostly declarative.<p>The usual problem with declarative forms is lack of expressive power. If you need to express something the declarative form can&#x27;t handle, it&#x27;s tempting to bolt on some kind of imperative gimmick. This is how we ended up with Javascript.
评论 #8691853 未加载
评论 #8695554 未加载
评论 #8691180 未加载
评论 #8690959 未加载
taericover 10 years ago
Hasn&#x27;t it been fairly well established that imperative and declarative are not necessarily duals? That is, !imperative is not the same as declarative. And vice versa.<p>That is, the base generalization here is invalid.<p>Further, there are plenty of things where imperative just makes sense. It is why we have plenty of imperatives in every day usage. I mean, sure, you could tell your kids &quot;I want a clean room.&quot; Likely, they will look at you and wonder, if that is what you want, why don&#x27;t you clean it. :)<p>So, sure, if there is a nice clean concise declarative way to specify something, do so. However, I think it is a fool&#x27;s errand to think that can be the universal case. Even in an ideal sense. It is why you don&#x27;t hear people trying to drop imperatives from daily life. (Or... do you?)
_random_over 10 years ago
Still waaay too imperative, how about this:<p>func [1,2,3,4,5] =&gt; [2,4,6,8,10] <i>&#x2F;&#x2F;Calculation inferred by compiler.</i><p>console.log (func [6,7,8,9,10]) <i>&#x2F;&#x2F;=&gt; [12,14,16,18,20]</i>
评论 #8691139 未加载
评论 #8690738 未加载
评论 #8691694 未加载
segmondyover 10 years ago
Awwww, all that an no mention of Prolog or Mecury? Prolog is a declarative language that is being used in the real world and being used often to solve interesting problems too. There is always a joke about how folks tend to reinvent lisp while trying to extend their language. Same can be said for any program that has rules, there is always a half ass prolog engine poorly implemented.
sanketbajoriaover 10 years ago
Good Explanation
评论 #8692905 未加载