35

Similar yet different. So confusing

 4 years ago
source link: https://www.tuicool.com/articles/hit/7jMfmiI
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

There are concepts which are very similar, yet different and confuses many people.

Referential transparency vs immutability

Referential transparency is a concept in a programming language which guarantees that once the value is assigned to the variable

it will not change there is no way to assign a different value to it. For example, in ES6 you can use const

for it:

const a = { x: 1 };
a = { z: 1 }; // TypeError: Assignment to constant variable
a.x = 2; // This is ok

(Not sure why this is a type error, but you get the idea)

Immutability is a concept in a programming language (and in different areas) which guarantees that the value once it was created will remain unchanged. For example, in ES6 you can use Object.freeze for it:

let b = Object.freeze({ x: 1 });
b.x = 2; // Silently ignores error e.g. does nothing
b = { z: 1 }; // This is ok

Confusion: I guess not a lot of people know or use every day the terminology "referential transparency". Programming language calls it constant ( const ). And constant is something that stays unchanged, you can even say immutable...

Authentication vs authorization

Authentication in the context of a user accessing an application tells an application who the current user is and whether or not they're present ( source ).

Authentication answers the question - who you are.

Authorization in the context of a user accessing an application tells an application if the current user (including unauthenticated users) is allowed to make given action or not.

Authorization answers the question - what you allowed to do.

Confusion: for starters - names are very similar which wasn't the best idea in the first place (naming is hard). The second part of the confusion is that you typically need authentication to do authorization.

What are your favorite sources of confusion?

Photo by Lisa Algra on Unsplash

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK