News for hackers. Stuff that matters.
Re:Programming with Natural Language Is Going to Work (2010) by Marazan on Wednesday May 24, 2023 @03:49PM (#36063072)
Which is useless because _it has changed the semantics of the function_
Re:Programming with Natural Language Is Going to Work (2010) by byby on Wednesday May 24, 2023 @04:35PM (#36063540)
You have to change the semantics of the function to make it unit testable. Literally tell me how else can you test that function with a unit test?
Re:Programming with Natural Language Is Going to Work (2010) by Marazan on Wednesday May 24, 2023 @05:49PM (#36064295)
Let me tell you your mind is going to be blown once you learn about Monads.

A mutable object is functionally identical to a return value if you control the initial state and lifetime of the object. Like you can do in a unit test.

And as I demonstrated in my other comment I 100% retained the semantic structure of the function whilst making it 100% unit testable.

Re:Programming with Natural Language Is Going to Work (2010) by byby on Wednesday May 24, 2023 @06:23PM (#36064605)
>And as I demonstrated in my other comment I 100% retained the semantic structure of the function whilst making it 100% unit testable.

This is not true. You changed the signature of the function to include a new parameter.

> Let me tell you your mind is going to be blown once you learn about Monads.

You know about monads and you do this type of injection hack in your example? You realize Haskells type system exactly segregates things the way ChatGPT did it right? The IO monad prevents you from injecting prints into your pure logic, you have to use bind to segregate things from being polluted with the IO monad. Literally haskells type system forces you to code for unit test ability AS A type check; meaning if your code isn't unit testable, it's a Type Error.

>A mutable object is functionally identical to a return value if you control the initial state and lifetime of the object. Like you can do in a unit test.

Yeah it is, but you had to change the function signature to get it. Either a mutable input value or a return value. Pick one. You chose the former. Your dependency injection example IS a valid unit test but it is completely untrue that you did not change the semantics of the function, you HAD to change it, you had no choice.

Also lifetimes don't matter in python too much as it is garbage collected. You nor does any other scoped owner control the lifetime of an object in python. The garbage collector controls the lifetime via reference counting... but this is off topic.

Re:Programming with Natural Language Is Going to Work (2010) by moomoo3000 on Wednesday May 24, 2023 @04:23PM (#36063413)
It was a bad function
Re:Programming with Natural Language Is Going to Work (2010) by Marazan on Wednesday May 24, 2023 @05:50PM (#36064306)
And yet I was able to make it unit testable without changing it's semantics.