开发者

How is Java an 'imperative' programming language and not a 'declarative' one?

Specially in comparison开发者_JS百科 to C/C++ (which are declarative), how is Java imperative?


C/C++ is imperative too.

Edit: Imperative is do this, then do that, then do the next thing and so on. Declarative is, this are the rules, now what's the answer to this question. Google, you'll find plenty of info.


You are confusing the concepts, C and C++ are not declarative languages. Refer to Declarative Programming and Imperative Programming. Basically, with declarative languages (e.g. Prolog), you specifiy what you want to accomplish, without specifying how to accomplish it, which contrasts with imperative languages.


For future readers, although both Java and C/C++ are usually written imperatively, Both languages support writing in a more declarative way for example by applying functional principles.

In the past years it has been more and more prominent and is encouraged by many influential software engineers such as Uncle Bob to go to a more functional (and thus declarative) approach.

In Java this was made much more easy with Java 8 that introduced Lambda, Streams etc.

I read this book about functional programming in Java and found it useful: https://pragprog.com/book/vsjava8/functional-programming-in-java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜