Ask Your Question
0

why are variables immutable in puppet ?

asked 2016-11-09 10:41:17 -0500

jondoe gravatar image

it's all in the title

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-11-09 15:50:42 -0500

Red Cricket gravatar image

Because puppet is a declarative programming language.

edit flag offensive delete link more

Comments

2

Simple language design choice. Not being able to reassign a variable means that it will always have the same value, which fits well with the declaritive nature of the language.

DarylW gravatar imageDarylW ( 2016-11-09 21:38:36 -0500 )edit

i mean does it serve some technical purpose, i can see how it constrains me(not being to reassign variables, updates hashes and so on) but i don't see why, whay will break if variables were mutable.

jondoe gravatar imagejondoe ( 2016-11-10 02:59:41 -0500 )edit

Nothing would 'break', it would just be different programming languate schemantics..

DarylW gravatar imageDarylW ( 2016-11-10 08:57:01 -0500 )edit

ok thanks.

jondoe gravatar imagejondoe ( 2016-11-10 10:01:33 -0500 )edit
2

answered 2016-11-13 04:19:05 -0500

Stefan gravatar image

One problem would also be that if you are able to redeclare a variable than parsing order actually matters, which you want to avoid in the puppet language. Think of the following example

class 'foo' {
  $a = 10
  include bar
  $a = 20
}

class 'bar' {
  notify { 'Test': message => $foo::a }
}

now what should the bar class print? The "final" value of $a (20) or the value at the specific parsing time (10). But the class bar could have also be included at a second point out of class foo (lets say a third class baz also includes bar).

So in theory immutable variables would even allow something like

notify { "Test": message => $a }
$a = "I am a"

but (unfortunately) parsing order from top to bottom still matters in the puppet language.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-11-09 10:41:17 -0500

Seen: 79 times

Last updated: Nov 13 '16