Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Basics (1.x) Getting Started with Angular Angular, an Overview

Why/when would we use a Declarative language over an OO language or a Functional language?

I'm assuming both Angular and Angular 2 are both declarative languages. I didn't feel like the example sites (True Car and the Oregon Football site) gave me any idea(s) why Angular/Angular 2 is a superior choice over other types of languages...can someone elaborate? Thanks!

1 Answer

Alex Arzamendi
Alex Arzamendi
10,042 Points

The short and greatest answer of all times is: it depends.

Frameworks restrict you to a development environment for the kind of thing that you are building and often involve a mixture of things. Think Java for example, it is an object oriented programming, fighting the oop paradigm in Java is mostly a brick wall....with titanium reinforcements. So you are basically left with grouping everything into classes and interconnecting them as needed. In the event of needing to mix database support then you could use a declarative language(like MySQL for example) to add that support. Functional programming is merely a style which you can use in which high emphasis is placed on functions and the purity of data as a mean to solve issues.

Think in domains and you will find what you need. For example, do I need a website? simple, it will require html and css which are markup languages, but it would at one point require Javascript which is a programming language to control the front end, you can very well use it for server side logic, but in this example lets mix in other tech to see the bigger picture. So we already know what is going in on with the user interface or client experience. But we need user logins and to perserve certain state aspects, and for arguments sake lets say that I know PHP, Python, Ruby and Java, this means that I have options and preference would somewhat dictate the server side stack that I will use, so I will go with Python because out of my examples it is the easiest one to use in terms of switching paradigms between functional and oop. In Python you could very well use a framework like Django, in which content and information can be passed in terms of object oriented expressions as well as functional ones, models are manipulated through classes which translate latter on from an object relational mapper into SQL transactions. Thus having fulfilled the need for a declarative language as well as one that has object oriented features as well as functional ones.

Object oriented programming makes a lot of sense when building something like an Android application in which thinking in terms of Activities works best when considering object oriented programming, each activity is a class that interacts with other activities as classes and separation of concerns works well since you can separate classes between different files and reference them when needed.

I really like functional programming as well, and sometimes without really knowing Javascript forces you to think as a functional programmer since its object oriented features are not exactly pure(prototype based) and let you add functional logic in a lot of instances, since functions in Javascript are higher order you pass anonymous functions everywhere, this is functional programming logic and if you like the effects of it you are in the right track with Javascript. Not to say that other languages do not implement them, for example Android Java has a lot of functional style programming in a lot of places when passing function bodies as arguments and such(see an example of a View.onClickListener to see what I mean, it is one of the most basic examples I can think of in terms of Android Java development)

Going over Angular, it is not much of a language as it is a framework, a way of handling ui by means of Javascript, in which case you have full support of both functional and oop(oop in a way as it is different in Javascript) it is not a superior choice per se, but it is at this point more of a preference when compared with other equally good frameworks such as React (which also uses Javascript as its main lanugage, and only language actually)

Cheers! and keep learning as much as you can, all paradigms becomes more relevant as times go by, and many languages have awesome support for functional programming logic.