The problem with assignment statements - Uncle Bob

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 พ.ย. 2024

ความคิดเห็น • 96

  • @CodingHaribo
    @CodingHaribo 2 วันที่ผ่านมา +2

    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

  • @MrTutiplengo
    @MrTutiplengo 4 วันที่ผ่านมา +12

    Interesting point, but the short video offers no viable solutions to how to accomplish side effects correctly.

    •  3 วันที่ผ่านมา +2

      exactly, I was waiting for the solution myself

    • @bundlesofun9568
      @bundlesofun9568 3 วันที่ผ่านมา +2

      Pretty sure the solutions were a) use a functional language, b) git gud 😂

    • @MrTutiplengo
      @MrTutiplengo 3 วันที่ผ่านมา

      @@bundlesofun9568 but he didn't describe a way to do a side effect in a functional language either.

    • @pdgiddie
      @pdgiddie 3 วันที่ผ่านมา

      It sure as hell won't involve an assignment, that's for sure 😅

    • @eio4528
      @eio4528 3 วันที่ผ่านมา +5

      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.

  • @adambickford8720
    @adambickford8720 4 วันที่ผ่านมา +2

    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.

  • @MrYerak5
    @MrYerak5 4 วันที่ผ่านมา +10

    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?

    • @rallisf1
      @rallisf1 4 วันที่ผ่านมา

      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.

    • @Coburah
      @Coburah 4 วันที่ผ่านมา

      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));
      }

    • @james.lambert
      @james.lambert 3 วันที่ผ่านมา +3

      You need to copy the entire database with each mutation

    • @Coburah
      @Coburah 3 วันที่ผ่านมา +2

      @@james.lambert truly immutable 😂

    • @pdgiddie
      @pdgiddie 3 วันที่ผ่านมา +2

      Simple: use a monad 😉

  • @CristiNeagu
    @CristiNeagu วันที่ผ่านมา

    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.

  • @Kidkromechan
    @Kidkromechan 4 วันที่ผ่านมา +2

    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.

    • @rallisf1
      @rallisf1 4 วันที่ผ่านมา +4

      Not really, FP just moves side effects out of the functions. You cannot have no side effects at all.

    • @adambickford8720
      @adambickford8720 4 วันที่ผ่านมา

      @@rallisf1 Dunno if i'd characterize that as 'just', it's a pretty profound impact.

    • @Kidkromechan
      @Kidkromechan 4 วันที่ผ่านมา

      @@rallisf1 I see. That's good to know :D

  • @James-l5s7k
    @James-l5s7k 4 วันที่ผ่านมา +2

    This reinforces good behaviour.

  • @4ngelf
    @4ngelf วันที่ผ่านมา

    Well, I agree that we should avoid mutation as much as possible. But a side-effect free program doesn't exists.

  • @turolretar
    @turolretar 4 วันที่ผ่านมา +7

    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
      @anve2441 4 วันที่ผ่านมา +7

      I think his point is: stop writing bugs by not writing code

    • @marc-andrebrun8942
      @marc-andrebrun8942 4 วันที่ผ่านมา +3

      @@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.

    • @Coburah
      @Coburah 4 วันที่ผ่านมา +1

      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.

    • @Coburah
      @Coburah 4 วันที่ผ่านมา +3

      People introduce state entirely unnecessarily all the time in code. Often, it's not needed and it introduces bugs. That's all.

    • @adambickford8720
      @adambickford8720 4 วันที่ผ่านมา +7

      Don't mutate stuff. That's all he's saying.

  • @fish42
    @fish42 4 วันที่ผ่านมา +3

    But is it really possible to not use assignments statements at all?? That seems crazy. Or does he mean only for certain situations?

    • @mike.t.angelo
      @mike.t.angelo 4 วันที่ผ่านมา +4

      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.

    • @nickst0ne
      @nickst0ne 4 วันที่ผ่านมา +4

      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.

    • @marc-andrebrun8942
      @marc-andrebrun8942 4 วันที่ผ่านมา +3

      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.

    • @pedroamaralcouto
      @pedroamaralcouto 4 วันที่ผ่านมา +3

      Try to work with functional programming to understand what he said.

    • @vbombos
      @vbombos 3 วันที่ผ่านมา

      @@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.

  • @mariusraducan1348
    @mariusraducan1348 3 วันที่ผ่านมา

    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.

  • @chudchadanstud
    @chudchadanstud 4 วันที่ผ่านมา +22

    now he's just nitpicking

    • @kerojey4442
      @kerojey4442 3 วันที่ผ่านมา +1

      always has been

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      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

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      ​@@kerojey4442define referential transparency

    • @maleldil1
      @maleldil1 นาทีที่ผ่านมา

      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.

  • @svenstarson1908
    @svenstarson1908 3 วันที่ผ่านมา +1

    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.

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      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

  • @ohwow2074
    @ohwow2074 4 วันที่ผ่านมา +1

    2:53 LMAO the reference 😂

  • @hassaanmaqsood
    @hassaanmaqsood 3 วันที่ผ่านมา

    Event Architecture from "time depenent functions"

  • @flaguser4196
    @flaguser4196 4 วันที่ผ่านมา +1

    but why did lisp introduce garbage collection?

    • @marc-andrebrun8942
      @marc-andrebrun8942 4 วันที่ผ่านมา +1

      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.

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา +1

      Because moving memory around is not the job of a software engineer but rather the compiler

    • @brentlidstone1982
      @brentlidstone1982 2 วันที่ผ่านมา

      @@AndreiGeorgescu-j9p Uncle Bob seems to disagree.

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      @@brentlidstone1982 he's all about fp nowadays so not really. Considering he's ancient it's actually amazing

  • @bundlesofun9568
    @bundlesofun9568 3 วันที่ผ่านมา +1

    I like how he just roasted everyone who depends on managed languages 🤣🤣

  • @kerojey4442
    @kerojey4442 3 วันที่ผ่านมา +5

    This guy is pro at talking nonsense bs

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      Just say you don't understand computer science

    • @kerojey4442
      @kerojey4442 2 วันที่ผ่านมา

      @AndreiGeorgescu-j9p continue to buy his books!

  • @yapdog
    @yapdog 3 วันที่ผ่านมา

    So, the lesson is........ don't write code

  • @brentlidstone1982
    @brentlidstone1982 2 วันที่ผ่านมา

    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.

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      @@brentlidstone1982 define pure functions

  • @utk787
    @utk787 3 วันที่ผ่านมา

    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

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      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

  • @timothydahlin5321
    @timothydahlin5321 4 วันที่ผ่านมา

    Physics causes the function to fail. 😂

  • @JENSATAAU
    @JENSATAAU 2 วันที่ผ่านมา +1

    hmmm - not one real eaxmple - only mumble jumble

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 2 วันที่ผ่านมา

      Almost like it's a snippet from a talk.
      Also this is very basic programming language theory

    • @brentlidstone1982
      @brentlidstone1982 2 วันที่ผ่านมา

      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.

  • @bmehder
    @bmehder 3 วันที่ผ่านมา

    Preach brother