Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I would like to point out that if you write code like this (that is, creating a temporary object only to have it instantly deleted), your code smells.

Not necessarily. What if all you want are the side effects of the object?

In particular I/O. Either disk or network.

Creating the object opens the connection, destroying it closes the connection. And you use the object in between to write data.

Or, don't assign the new object to anything, and simply write the data you pass in to it, and close the stream.

It's a perfectly reasonable use case.



> And you use the object in between to write data

That's not what I was talking about. See the original comment and follow-ups.


> That's not what I was talking about.

You didn't read my next sentence.

I was explaining that you could use the object in two ways. (If you only ever used it the second way then you would just make it static, so I was giving the first way as a reason why it would not be static.)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: