HackerTrans
TopNewTrendsCommentsPastAskShowJobs

byby

no profile record

comments

byby
·3 yıl önce·discuss
[dead]
byby
·3 yıl önce·discuss
[dead]
byby
·3 yıl önce·discuss
[dead]
byby
·3 yıl önce·discuss
[dead]
byby
·3 yıl önce·discuss
No. This is false. Even senior engineers can have this problem. It's not a differentiator for success.

This is counterintuitive but actually there is raw science to back the opposite fact up. I'm not joking.

The more delusional you are as in the less ability you have to take and accept criticism the more likely you are to be successful. There is a positive correlation for this verified by science.

It gels with my anecdotal experience too. At the top end of success those guys are the most delusional and least accepting of criticism, for example Elon musk or Steve jobs, etc. Etc.

But even on the lower end of the spectrum, senior engineers it's there too. For example people who claim they are able to unbiasedly accept criticism are often the people who are worst at it.

The reason for this is not any sort of deliberate emotional reaction or anything like that. But rather because the brain actively deludes you from seeing the complete truth. It pushes people to construct artificial scaffolds of logic to uphold their existing beliefs.

Senior engineers are not immune to it nor are they better. What determines the senior role has a lot of factors and definitely not all the factors are related to the actual formal senior rank. A lot of it is luck, time, politics and other bullshit that gets people that rank.

Everyone builds these ideals about their identity, their rank, and their engineering ability. The reality is that a lot of it is delusional. By deluding yourself it becomes easy to include other people in your delusion as well and that's how a lot of hierarchies work.

Not saying their aren't competent people out there, but don't fall for the false belief that a rank like "senior engineer" conveys a certain level of emotional maturity to accept criticism.
byby
·3 yıl önce·discuss
Yeah but to keep on topic you suggested that this sort of thing was happening in the thread.

I disagree, it's not.
byby
·3 yıl önce·discuss
>You've written 3 functions instead off one.

3 functions is better. Think about it. Do people write all their stuff in one big function? No. Better to compose higher level functions with smaller ones rather then write one big monolith like you did. The more modular something is the better.

Also IO_function is there for illustration purposes. Technically it's just wrapping print with a name so you can understand the intent. In reality you just use the regular print here without a wrapper, so in actuality only two functions are defined.

>The job of ChatGPT was to make cool_function unit testable. You haven't done it.

It did. By giving it a return value. Just like you did by giving it a new input value.

>You still have cool_function using side effect generating code hitting the actual IO system.

Yeah but one component of cool_function is pure and you can unit test that. Cool function itself can never be tested because it generates no output, you test the unit components of cool function. That's the point of unit tests.

>Genuinely the worst unit test I have ever seen written, on a poor form per line basis, absolute bananas. If you don't understand why [i for i in range(4)] is bad in a unit test and [0,1,2,3] is correct then I need you to walk away from the computer.

Let's just talk about it like adults. Just tell me what exactly about it makes you think it's bad?

Most likely it's some pedantic stylistic philosophy you have? I'm thinking you only want to test literals? Perhaps you prefer [0,1,2,3]? Am I right on the money?

Logic potentially has errors so you don't put logic in your test code. Makes sense, but who cares. For trivial shit it's fine. While in this case the logic in the test is identical to the function, typically 'logic_function' represents something significantly more complex and the list comprehension so I could care less if I'm not following the strictest form of testing. The comprehension is just something akin to an alias shortcut I prefer to use over writing out a massive literal. For the toy example the test is pointless because the logic is identical but typically it's fine to use range as an alias to represent a sequence of numbers.

Someone who strictly follows these stylistic rules without seeing intent or having the ability to bend the rules is just an inflexible pedantic programmer. It's not good to boast about it either by telling other people to walk away from a computer. That's just rude.
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
This is the function I gave chatGPT:

   ME:
   def (x: int):
      for i in range(x):
         print(i)
It takes an int. Are you trolling now or did you get mixed up with something else?
byby
·3 yıl önce·discuss
Alright fine, I can concede to this. ChatGPT should not have given me the best alternative but it should have given me the exact technically correct answer. You're right.
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
I've been writing them for over 20. Doesn't matter. What matters is factual correctness.

See here what a unit test is versus integration test: https://www.testim.io/blog/unit-test-vs-integration-test/

And also see my reply to the other guy where I definitively show that not only is what chatgpt produced correct, but better:

https://news.ycombinator.com/item?id=36064097
byby
·3 yıl önce·discuss
> I'm sorry, I clearly haven't explained myself well as otherwise you would not have wasted a huge amount of text tying yourself in knots based clearly on a mistaken apprehension of what I was saying.

No need to apologize. This is a discussion. No one did anything wrong.

>For clarity I reproduce the original function you gave and then I present what the change I am suggesting is

This is called dependency injection and it's a valid way of segregating IO away from pure logic. Although this pattern is popular among old school OOP programmers it's getting out of vogue due to the complexity of it all. You used a python trick here of default values, but typically dependency injection changes the function signature and ups the complexity of the code by a lot. Let me show you the full output of the code that chatgpt was implying:

   #unit testable code (without using dependency injection tricks)

   def cool_function(x: int) -> None:
       IO_function(logic_function(x))

   def logic_function(x: int) -> List[int]:  
       return [i for i in range(x)]

   def IO_function(x: Any) -> None:
       print(x)
       
   def test_output():
       assert logic_function(4) == [i for i in range(4)]
Chatgpt only gave you logic_function, because IO_function is sort of obvious.. it's just "print" (I only wrapped print in "IO_function" to keep things clear, typically you won't define that function). But basically the full complete code would be to recompose IO with logic. You now have two components one of which is testable.

As a side note you will see it's actually an improvement to the code. It's simpler, no dependency injection, no confusing function type signature and a much simpler test case. The other thing that must be noted is the modularity.

Making tests unit testable in this way allows for your logic to be portable. What if I want to repurpose cool_function to output it's logic to another function? In your example you don't have the components to do that, it's harder for your case as you'd have to create another component for injection.

In short not only did chatGPT produce A correct answer. But it produced the better answer compared with your dependency injection. That being said your dependency injection is valid BUT you were not correct in saying that chatGPT's answer was worse or incorrect.
byby
·3 yıl önce·discuss
>Output formatting is still a type of transformation!

I'll quote part of my reply (which you missed):

   (Btw making print formatting unit testable means segregating the formatting from the print. Produce the string first, test that, then print, because print can never be unit tested by definition)
Right? Think about it. You want to unit test your formatting, remove the logic from the atomic IO function. Otherwise you can't test it via a unit test because that's the definition of unit testing. I realize that there is formatting that's part of the internal functionality of printf, but really all that means is that funcitonality can never really be unit tested. If you want to test printf, that happens at the integration level... By Defintion.

>BTW I gave ChatGPT the prompt I would give, and I have to say the answer looks pretty good, even if I'm not a Python programmer and it's not the way I'd do it (which would be to change the function to allow passing in an output stream):

It's wrong in this case. Unless you specifically asked it to write unit testable code, what it did here is write a hack that monkey patches the program. It's a huge hack. It didn't write unit testable code, but rather it wrote a integration test that monkey patches stdout, negating any need to make your code "unit testable" no refactoring needed using this method. The entire concept of refactoring code to be unit testable flies out the door in this case as you're just using integration tests to get around everything.

I mean yeah you use the unit test library but is not technically a unit test. It's fine I'm not a stichler for what style of testing is used in practice but what I am saying is that what chatgpt did previously was literally follow my instructions to the letter. It did it exactly 100% correctly. Think about it. I asked chatgpt to make the Code more unit testable. You didn't have chatgpt do anything to the code. You simply changed the test from a unit test to integration test. Huge difference. I mean if your case was the "proper" way then what does it even mean to make code "unit testable" if you're not even touching the code? Like why does the concept of "making code more unit testable" even exist if we're just changing tests to make everything unit testable? Ask yourself this and you'll realize that the only answer is basically what I just told you previously.
byby
·3 yıl önce·discuss
[flagged]
byby
·3 yıl önce·discuss
It is. There is literally zero other way to make that function unit testable. What are you gonna compare that data with in a test if it's thrown into IO?

By definition all unit testable functions have to return data that can be asserted. You throw that data to IO it's not unit testable.

IO is testable via an integration tests. But not unit tests. Which is what my query exactly specified. I specified unit tests.