I have to say it, but Bob is talking about mutating state (assignment) being the root of side-effects, but you can read side-effects as well, something that will stop your function from being "pure", such as date/time or random stuff like generating UUIDs
In this context 'assignment' means mutation, references *and* values. You initialize a reference to its one and only state, with a reference to immutable objects. Then it doesn't matter when you refer to it, it's correct.
You got the first one right. Connecting to a database is very different than opening a file. Connecting to a database is a network/socket connection, if you don't use it it will just expire after a minute or so. Closing the database connection just frees up resources on the database, nothing changes on your application. From a security perspective idle database connections could be hijacked by some other (malicious) app.
You can do this with monads that "hide" and centralize assignments. Pseudo code: void UseDb() { // GetConnection() closes the connection // after performing DoStuff(( Db.GetConnection(connection - > DoStuff(connection)); }
There is no other concept I find more contemptible in programming than functional programming. Functional programming is like putting on a cycling helmet and knee and elbow pads every time you leave the house, even though you don't ride a cycle because it's too dangerous.
I believe the point is to not assign values or have a side effect outside of the scope of the function. It is not possible to do normal oop programming without side effects. Maybe functional programming languages make this possible.
Most computer systems are stateful because not having any memory at all is not very useful, so I’ve heard. I don’t understand his point. Does he mean assigning to variables scoped outside of the function? Or just globals? Because what is there to do without any assignments in a programming language?
@@anve2441 in FP assigment, side effect must be OUT of functions. at the beginning, there was no compilation, but only a shell called REPL, for Read, Eval Print loop. Read is the tokenization of your text code Eval is the main double recursion with Apply : on deal with the synthax, the other deal with semantic; it's here that assigments are forbiden; when the double recursion eval / appy is exhausted print is called; Print, is where the side effect occurs, of course.
Try to minimize assignment inside function scopes as well. ESPECIALLY in large functions... I have seen this too many times at work... var someState = Get(); // 100 lines of code... someState = NewState(); When scrolling through this code, it's not apparent what's happening to this variable. You can argue that functions shouldn't be long (I agree) and that an IDE can help figure out what's going on (I agree), but when the code looks like this all over the place, it just becomes a tangled mess.
I think the context here is assigning values to variables that are outside the scope of the function, like he says, doing assignment statements that allocate memory or open a file handle, things that change the state of the system outside the scope of the function. Or, for example, changing the value of a global variable. Then you need another function that deallocates the memory, or closes the file handle, and things like that.
I think the incriminated assignments are those beyond the initial value. Immutable objects do not suffer from the problem mentioned. They cannot be changed someplace where it was not intended. Also, what Uncle Bob says should be taken with a grain of salt. He is spectacular but what he promotes are ideals, which are not always pragmatic. Using discernment is advised.
in FP assigment, side effect must be OUT of functions. at the beginning, there was no compilation, but only a shell called REPL, for Read, Eval Print loop. Read is the tokenization of your text code Eval is the main double recursion with Apply : on deal with the synthax, the other deal with semantic; it's here that assigments are forbiden; when the double recursion eval / apply is exhausted print is called; Print, is where the side effect occurs, of course.
@@mike.t.angelo You don't have to use assignments to allocate memory. "malloc(1);" is valid code. You can even cast it to void to get rid of any warnings :D.
In linear logic, one can do all these things in a rigorous way, with errors caught by the type system at compilation time. Granule project could be the backbone of a such programming language, but, of course, it might remain at the academic level forever because „practical” minded people would not need such intellectual „elucubrations” for the „real” world of production.
No he's talking about referential transparency and why imperative programs can't be refactored without potential issue. This is a core reason for functional programming. You guys don't understand programming language theory
I think the "assignment statement" framing is flawed here, but the core is sound: functions/methods that affect the global state of the system are dangerous, and you should try to minimise them and push them outwards as possible.
And that is why you need a thoughtful programer that can decide whether an effect is of the unwanted kind or the its the effect your program is trying to achieve.
No that's why you need to not use imperative languages that allow for unmanaged effects. This is like the "just remember to free memory dude" argument all over again
to stick to the math. integers are infinite; with garbage collection, recursion on a stream (list with lazy evaluation) LISP & scheme can deal with very huge integers, so that give a simulation of infinite.
Since I understand what pure functions are, I'm willing to bet that there's more that he says afterwards that is completely essential to understanding this point fully. This video just cuts his speech off half way for no discernable reason. If that is the fault of the channel owner, may I ask, what the hell are you doing? Do you honestly believe that this video is somehow sufficient without the second half where he explains what to do instead? Just screaming "write pure functions!!!" at new people is not useful to anyone.
A variable is called a variable because the value can vary in time. If value cant change thats a constant, i just dont get it why do they call it a variable then if the value cant change
No that's not at all why it's called a variable. The word comes from math and variables never change within a problem, they can take on different values in different problems. A constant is a predefined symbol like '3'. Just because C was made without any denotational sense to it doesn't mean you can change what things mean now
I'm pretty sure there was examples afterwards. But this channel owner decided those examples are not relevant for some reason and that we don't need to see them.
I have to say it, but Bob is talking about mutating state (assignment) being the root of side-effects, but you can read side-effects as well, something that will stop your function from being "pure", such as date/time or random stuff like generating UUIDs
Interesting point, but the short video offers no viable solutions to how to accomplish side effects correctly.
exactly, I was waiting for the solution myself
Pretty sure the solutions were a) use a functional language, b) git gud 😂
@@bundlesofun9568 but he didn't describe a way to do a side effect in a functional language either.
It sure as hell won't involve an assignment, that's for sure 😅
Seek the full lecture. This channel is just view farming by rehashing someone elses content, in this case Uncle Bob, for their own personal gain.
In this context 'assignment' means mutation, references *and* values. You initialize a reference to its one and only state, with a reference to immutable objects. Then it doesn't matter when you refer to it, it's correct.
So the the problem is programers not the statments, how can i connect to a db without realesing it when im done? And what salution does he recommend?
You got the first one right. Connecting to a database is very different than opening a file. Connecting to a database is a network/socket connection, if you don't use it it will just expire after a minute or so. Closing the database connection just frees up resources on the database, nothing changes on your application. From a security perspective idle database connections could be hijacked by some other (malicious) app.
You can do this with monads that "hide" and centralize assignments. Pseudo code:
void UseDb() {
// GetConnection() closes the connection
// after performing DoStuff((
Db.GetConnection(connection - > DoStuff(connection));
}
You need to copy the entire database with each mutation
@@james.lambert truly immutable 😂
Simple: use a monad 😉
There is no other concept I find more contemptible in programming than functional programming. Functional programming is like putting on a cycling helmet and knee and elbow pads every time you leave the house, even though you don't ride a cycle because it's too dangerous.
I believe the point is to not assign values or have a side effect outside of the scope of the function.
It is not possible to do normal oop programming without side effects. Maybe functional programming languages make this possible.
Not really, FP just moves side effects out of the functions. You cannot have no side effects at all.
@@rallisf1 Dunno if i'd characterize that as 'just', it's a pretty profound impact.
@@rallisf1 I see. That's good to know :D
This reinforces good behaviour.
Well, I agree that we should avoid mutation as much as possible. But a side-effect free program doesn't exists.
Most computer systems are stateful because not having any memory at all is not very useful, so I’ve heard. I don’t understand his point. Does he mean assigning to variables scoped outside of the function? Or just globals? Because what is there to do without any assignments in a programming language?
I think his point is: stop writing bugs by not writing code
@@anve2441 in FP assigment, side effect must be OUT of functions.
at the beginning, there was no compilation, but only a shell called REPL, for Read, Eval Print loop.
Read is the tokenization of your text code
Eval is the main double recursion with Apply : on deal with the synthax, the other deal with semantic;
it's here that assigments are forbiden; when the double recursion eval / appy is exhausted print is called;
Print, is where the side effect occurs, of course.
Try to minimize assignment inside function scopes as well. ESPECIALLY in large functions... I have seen this too many times at work...
var someState = Get();
// 100 lines of code...
someState = NewState();
When scrolling through this code, it's not apparent what's happening to this variable. You can argue that functions shouldn't be long (I agree) and that an IDE can help figure out what's going on (I agree), but when the code looks like this all over the place, it just becomes a tangled mess.
People introduce state entirely unnecessarily all the time in code. Often, it's not needed and it introduces bugs. That's all.
Don't mutate stuff. That's all he's saying.
But is it really possible to not use assignments statements at all?? That seems crazy. Or does he mean only for certain situations?
I think the context here is assigning values to variables that are outside the scope of the function, like he says, doing assignment statements that allocate memory or open a file handle, things that change the state of the system outside the scope of the function. Or, for example, changing the value of a global variable. Then you need another function that deallocates the memory, or closes the file handle, and things like that.
I think the incriminated assignments are those beyond the initial value. Immutable objects do not suffer from the problem mentioned. They cannot be changed someplace where it was not intended.
Also, what Uncle Bob says should be taken with a grain of salt. He is spectacular but what he promotes are ideals, which are not always pragmatic. Using discernment is advised.
in FP assigment, side effect must be OUT of functions.
at the beginning, there was no compilation, but only a shell called REPL, for Read, Eval Print loop.
Read is the tokenization of your text code
Eval is the main double recursion with Apply : on deal with the synthax, the other deal with semantic;
it's here that assigments are forbiden; when the double recursion eval / apply is exhausted print is called;
Print, is where the side effect occurs, of course.
Try to work with functional programming to understand what he said.
@@mike.t.angelo You don't have to use assignments to allocate memory. "malloc(1);" is valid code. You can even cast it to void to get rid of any warnings :D.
In linear logic, one can do all these things in a rigorous way, with errors caught by the type system at compilation time. Granule project could be the backbone of a such programming language, but, of course, it might remain at the academic level forever because „practical” minded people would not need such intellectual „elucubrations” for the „real” world of production.
now he's just nitpicking
always has been
No he's talking about referential transparency and why imperative programs can't be refactored without potential issue.
This is a core reason for functional programming. You guys don't understand programming language theory
@@kerojey4442define referential transparency
I think the "assignment statement" framing is flawed here, but the core is sound: functions/methods that affect the global state of the system are dangerous, and you should try to minimise them and push them outwards as possible.
And that is why you need a thoughtful programer that can decide whether an effect is of the unwanted kind or the its the effect your program is trying to achieve.
No that's why you need to not use imperative languages that allow for unmanaged effects. This is like the "just remember to free memory dude" argument all over again
2:53 LMAO the reference 😂
Event Architecture from "time depenent functions"
but why did lisp introduce garbage collection?
to stick to the math.
integers are infinite;
with garbage collection, recursion on a stream (list with lazy evaluation) LISP & scheme can deal with very huge integers, so that give a simulation of infinite.
Because moving memory around is not the job of a software engineer but rather the compiler
@@AndreiGeorgescu-j9p Uncle Bob seems to disagree.
@@brentlidstone1982 he's all about fp nowadays so not really. Considering he's ancient it's actually amazing
I like how he just roasted everyone who depends on managed languages 🤣🤣
This guy is pro at talking nonsense bs
Just say you don't understand computer science
@AndreiGeorgescu-j9p continue to buy his books!
So, the lesson is........ don't write code
Since I understand what pure functions are, I'm willing to bet that there's more that he says afterwards that is completely essential to understanding this point fully. This video just cuts his speech off half way for no discernable reason. If that is the fault of the channel owner, may I ask, what the hell are you doing? Do you honestly believe that this video is somehow sufficient without the second half where he explains what to do instead? Just screaming "write pure functions!!!" at new people is not useful to anyone.
@@brentlidstone1982 define pure functions
A variable is called a variable because the value can vary in time. If value cant change thats a constant, i just dont get it why do they call it a variable then if the value cant change
No that's not at all why it's called a variable. The word comes from math and variables never change within a problem, they can take on different values in different problems. A constant is a predefined symbol like '3'.
Just because C was made without any denotational sense to it doesn't mean you can change what things mean now
Physics causes the function to fail. 😂
hmmm - not one real eaxmple - only mumble jumble
Almost like it's a snippet from a talk.
Also this is very basic programming language theory
I'm pretty sure there was examples afterwards. But this channel owner decided those examples are not relevant for some reason and that we don't need to see them.
Preach brother